dp-s_doc/Start/Example/8.md

58 lines
1.4 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/29.png)
> 然后我们在分解券.nut中写入以下代码
```
//本例子由凌众提供
//分解券
Cb_Use_Item_Sp_Func[7577] <- function(SUser, ItemId) {
SUser.GiveItem(ItemId, 1);
local is = SUser.GetCurCharacExpertJob();
if (!is) {
SUser.SendNotiPacketMessage("未开启分解机", 8);
return;
}
local inven = SUser.GetInven();
for (local i = 9; i <= 48; i++) //<=16为一行 以此类推+8多一行
{
local itemObj = inven.GetSlot(1, i);
local itemid = itemObj.GetIndex();
//如果这个位置有道具
if (itemid != 0) {
local pvfitem = PvfItem.GetPvfItemById(itemid);
local rarity = pvfitem.GetRarity();
if (rarity <= 3) {
SUser.DisPatcher_DisJointItem_disjoint(i);
}
}
SUser.SendItemSpace(0);
}
};
```
> 最后我们回到dp_s文件夹中打开Main.nut 加载我们刚才编写的逻辑
```
sq_RunScript("MyProject/分解券.nut");
```
> 至此一个简单的分解券的逻辑就写完了,这样其他公会的人也能互相看到了