呢喃的歌声
- CN币
- 0 颗
- 威望
- 34
- 贡献
- 23
- UID
- 585
- QQ

- 微信Wechat
- 良风有幸
- 居住地
- 中国
|
楼主 |
发表于 2025-3-31 20:01:01
|
显示全部楼层
远程商店最后一次求助,大佬们再看一眼吧
本帖最后由 zhangwei2199 于 2025-3-31 20:44 编辑
以我的能力只能做到这一步了,npc创建,打开商店,物品显示,价格计算一切正常,点击购买后不扣魔币不给道具,大佬们最后一次求助,还不行就放弃了
l- local Module = ModuleBase:createModule('ol_shop')
- local itemList = {
- { name = '母爱之卵', image = 27075, price = 100000, desc = '大地鼠媽媽石像所贈與的奇異之蛋', count = 1, maxCount = 999, itemid = '26' },
- { name = '再生剧药', image = 26206, price = 50000, desc = '能重新分配人物點數,使能力改變', count = 1, maxCount = 999, itemid = '26' },
- { name = '新手标志', image = 252025, price = 500, desc = '代表剛來這個世界沒多久的頭飾,新手的證明', count = 1, maxCount = 999, itemid = '55' },
- { name = '金刚不坏安全帽', image = 27933, price = 5000, desc = '可以用來抵擋受傷一百次,史上最強的安全帽', count = 1, maxCount = 999, itemid = '8' },
- { name = '王者守护神', image = 99194, price = 50000, desc = '裝備上就會擁有王者的保護,可以輕鬆的襲擊魔族', count = 1, maxCount = 999, itemid = '21' },
- { name = '水龙料理', image = 26364, price = 500, desc = '宠物親近度+10', count = 1, maxCount = 999, itemid = '23' },
- }
- --- 加载模块钩子
- function Module:onLoad()
- self:logInfo('load')
- local npc = self:NPC_createNormal('在线商店', 101024, { map = 1000, x = 220, y = 88, direction = 4, mapType = 0 })
- self:NPC_regTalkedEvent(npc, Func.bind(self.onSellerTalked, self))
- self:NPC_regWindowTalkedEvent(npc, Func.bind(self.onSellerSelected, self));
- end
- function Module:onSellerTalked(npc, player)
- if NLG.CanTalk(npc, player) then
- NLG.ShowWindowTalked(player, npc, CONST.窗口_商店买, CONST.BUTTON_是, 0,
- self:NPC_buildBuyWindowData(101024, '在线商店', '选择你要的商品', '金钱不足', '背包已满', itemList))
- end
- end
- function Module:onSellerSelected(npc, player, seqNo, select, data)
- local data = tostring(_data)
- if (select == CONST.按钮_关闭) then
- return;
- end
- local items = string.split(data, '|');
- local itemList = itemList;
- for key = 1, #items / 2 do
- local c = itemList[items[(key - 1) * 2 + 1] + 1]
- if c then
- count = (tonumber(items[(key - 1) * 2 + 2]) or 0);
- if c.maxCount > 0 then
- maxCount = c.maxCount - count;
- totalGold = c.price * count;
- keyNum = items[(key - 1) * 2 + 1] + 1;
- else
- maxCount = c.maxCount;
- NLG.SystemMessage(player,"[系統]此物品倉庫已無存貨!");
- return;
- end
- if c.itemid > 1 then
- itemid = c.itemid;
- else
- itemid = -1;
- end
- end
- if itemid == -1 then ----排除透过按钮取得道具
- return;
- end
- if maxCount < 0 then
- NLG.SystemMessage(player,"[系統]數量超過庫存!");
- return;
- end
- if Char.ItemNum(player, 68000) < totalGold then
- NLG.SystemMessage(player,"[系統]魔力金幣卡數量不足無法購買!");
- return;
- end
- if (Char.ItemSlot(player)<20) then
- itemList[keyNum][3] = itemList[keyNum][3] - count;
- Char.GiveItem(player,itemList[keyNum][2],count);
- Char.DelItem(player, 68000, totalGold);
- for NewItemSlot = 8,27 do
- local NewItemIndex = Char.GetItemIndex(player, NewItemSlot);
- if (NewItemIndex > 0) then
- if (Item.GetData(NewItemIndex, CONST.道具_已鉴定)==0) then
- Item.SetData(NewItemIndex, CONST.道具_已鉴定, 1);
- Item.UpItem(player, NewItemSlot);
- NLG.UpChar(player);
- end
- end
- end
- else
- NLG.Say(player, -1, "注意提取數量超過物品欄!", CONST.颜色_黄色, CONST.字体_中);
- return;
- end
- if (itemList[keyNum][3]==0) then
- table.remove(itemList,keyNum);
- itemList = itemList;
- end
- end
- end
- --- 卸载模块钩子
- function Module:onUnload()
- self:logInfo('unload')
- end
- return Module;
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|