dp-s_doc/Start/Example/3.md

82 lines
2.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> 首先我们先在dp_s文件夹中建立一个项目文件夹 MyProject 方便管理
![Alt text](../../image/6.png)
> 然后我们建立一个新文件 融合石.nut 用于编写我们的代码
![Alt text](../../image/17.png)
> 然后我们在融合石.nut中写入以下代码
```
//本例子由凌众提供
//装备代码1 装备代码2 融合后产出代码
Ronghe_Config <- {
"27601,27601",27601
}
Cb_Use_Item_Sp_Func[7577] <- function(SUser, ItemId) {
//获取玩家背包
local InvenObj = SUser.GetInven();
//如果背包存在
if (InvenObj) {
//获取玩家背包类型1的第9个格子
local ItemObj = InvenObj.GetSlot(1, 9);
local ItemObj2 = InvenObj.GetSlot(1, 10);
//空装备
if (ItemObj.IsEmpty || ItemObj2.IsEmpty) {
//发送通知
SUser.SendNotiPacketMessage("装备融合失败,请检查装备位置是否正确", 8);
//返还消耗的道具
local test = SUser.GiveItem(ItemId, 1);
return;
}
local ItemId1 = ItemObj.GetIndex();
local ItemId2 = ItemObj2.GetIndex();
local Skey = ItemId1 + "," + ItemId2;
if (!(Skey in Ronghe_Config)) {
//发送通知
SUser.SendNotiPacketMessage("装备融合失败,装备不可融合", 8);
//返还消耗的道具
SUser.GiveItem(ItemId, 1);
return;
}
local itemid3 = Ronghe_Config[Skey];
local item = SUser.GiveItem(itemid3, 1);
//最后获得的道具
local reitem = InvenObj.GetSlot(1, item[1]);
local dz = ItemObj.GetForging();
local qh = ItemObj.GetUpgrade();
local zf = ItemObj.GetAmplification();
local fm = ItemObj.GetEnchanting();
local pj = ItemObj.GetAdd_Info();
ItemObj.Delete();
ItemObj2.Delete();
reitem.SetForging(dz);
reitem.SetUpgrade(qh);
reitem.SetAmplification(zf);
reitem.SetEnchanting(fm);
reitem.SetAdd_Info(pj);
reitem.Flush();
SUser.SendItemSpace(0);
SUser.SendNotiPacketMessage("装备融合成功", 8);
}
}
```
![Alt text](../../image/18.png)
> 最后我们回到dp_s文件夹中打开Main.nut 加载我们刚才编写的逻辑
```
sq_RunScript("MyProject/融合石.nut");
```
![Alt text](../../image/19.png)
> 至此一个简单的融合石的逻辑就写完了,然后我们就可以在游戏中使用道具7577来融合了