找回密码
 立即注册
查看: 224|回复: 12

[提问/求助] 远程商店类型的lua,继续求教各位大佬

[复制链接]
呢喃的歌声

1

主题

21

回帖

113

积分
CN币
0 颗


威望
34

贡献
23

UID
585

QQ
QQ

微信Wechat
良风有幸

居住地
中国

发表于 2025-3-22 18:41:06 | 显示全部楼层 |阅读模式
本帖最后由 zhangwei2199 于 2025-3-23 19:16 编辑

玩家说话远程打开商店那种,用这个窗口测试lua尝试了一下可以正常显示购买窗口,但是后面的购买结算部分不知道怎么处理 @ahsin

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×

点评

已解决:http://bbs.cnmlb.com:233/thread-309-1-1.html  发表于 2025-4-5 20:15
万物创造者

188

主题

207

回帖

2341

积分
CN币
1 颗


威望
574

贡献
792

UID
1

QQ
QQ

微信Wechat
ahsinsoft

居住地
中国 上海市 杨浦区 定海路街道

发表于 2025-3-22 23:25:07 | 显示全部楼层
这个是k佬的测试lua,远程商店挺麻烦的,各种处理,如果好做,各大佬都做出来了。
圣洁的灵魂 [SVIP]

14

主题

26

回帖

2106

积分
CN币
76 颗


威望
693

贡献
599

UID
284

QQ
QQ



发表于 2025-3-23 11:50:52 | 显示全部楼层
  1.        local data = tostring(_data)
  2.        if (select == CONST.按钮_关闭) then
  3.                  return;
  4.        end
  5.        local items = string.split(data, '|');
  6.        local itemMenu = itemMenu;
  7.        for key = 1, #items / 2 do
  8.          local c = itemMenu[items[(key - 1) * 2 + 1] + 1]
  9.          if c then
  10.            count = (tonumber(items[(key - 1) * 2 + 2]) or 0);
  11.            if c.maxCount > 0 then
  12.              maxCount = c.maxCount - count;
  13.              totalGold = c.price * count;
  14.              keyNum = items[(key - 1) * 2 + 1] + 1;
  15.            else
  16.              maxCount = c.maxCount;
  17.              NLG.SystemMessage(player,"[系統]此物品倉庫已無存貨!");
  18.              return;
  19.            end
  20.            if c.itemid > 1 then
  21.              itemid = c.itemid;
  22.            else
  23.              itemid = -1;
  24.            end
  25.          end
  26.          if itemid == -1 then  ----排除透过按钮取得道具
  27.             return;
  28.          end
  29.          if maxCount < 0 then
  30.            NLG.SystemMessage(player,"[系統]數量超過庫存!");
  31.            return;
  32.          end
  33.          if Char.ItemNum(player, 68000) < totalGold then
  34.            NLG.SystemMessage(player,"[系統]魔力金幣卡數量不足無法購買!");
  35.            return;
  36.          end
  37.          if (Char.ItemSlot(player)<20) then
  38.                 itemList[keyNum][3] = itemList[keyNum][3] - count;
  39.                 Char.GiveItem(player,itemList[keyNum][2],count);
  40.                 Char.DelItem(player, 68000, totalGold);
  41.                 for NewItemSlot = 8,27 do
  42.                     local NewItemIndex = Char.GetItemIndex(player, NewItemSlot);
  43.                     if (NewItemIndex > 0) then
  44.                       if (Item.GetData(NewItemIndex, CONST.道具_已鉴定)==0) then
  45.                         Item.SetData(NewItemIndex, CONST.道具_已鉴定, 1);
  46.                         Item.UpItem(player, NewItemSlot);
  47.                         NLG.UpChar(player);
  48.                       end
  49.                     end
  50.                 end
  51.          else
  52.                 NLG.Say(player, -1, "注意提取數量超過物品欄!", CONST.颜色_黄色, CONST.字体_中);
  53.                 return;
  54.          end
  55.          if (itemList[keyNum][3]==0) then
  56.                 table.remove(itemList,keyNum);
  57.                 itemList = itemList;
  58.          end
复制代码


呢喃的歌声

1

主题

21

回帖

113

积分
CN币
0 颗


威望
34

贡献
23

UID
585

QQ
QQ

微信Wechat
良风有幸

居住地
中国

 楼主| 发表于 2025-3-23 18:46:01 | 显示全部楼层
用了ahxin大佬的ol_shop脚本,结合了xmen大佬的结算脚本,目前效果是玩家说话///aaa可以呼出购买窗口,商店物品列表正常,点击购买和结算画面正常,点击确定后无反应


报错
[ERROR][ol_shop]        ol_shop_npc_12800_WindowTalkedEvent event callback error:       lua/Modules/ol_shop.lua:39: attempt to index local 'itemMenu' (a nil value)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
圣洁的灵魂 [SVIP]

14

主题

26

回帖

2106

积分
CN币
76 颗


威望
693

贡献
599

UID
284

QQ
QQ



发表于 2025-3-23 20:49:35 | 显示全部楼层
本帖最后由 xman 于 2025-3-24 17:46 编辑
zhangwei2199 发表于 2025-3-23 18:46
用了ahxin大佬的ol_shop脚本,结合了xmen大佬的结算脚本,目前效果是玩家说话///aaa可以呼出购买窗口,商店 ...

itemMenu跟itemList是一样的,就是你卖的商品,要整活起来

for i=1,#itemList
    itemMenu = {name='..ItemName..', image='..ItemImage..', price=price, desc='..ItemMsg..', count=1, maxCount=maxCount, itemid=itemid};
end



你把你的商品转换成这个表格的格式,M大要你参考的manaPool就是在说这部分
如果你要自弄商品表,捣穀出怎么才对应就测试当经验。

商店NPC的data输出的格式先去了解,会是一长串含|的字串
local items = string.split(data, '|');

万物创造者

188

主题

207

回帖

2341

积分
CN币
1 颗


威望
574

贡献
792

UID
1

QQ
QQ

微信Wechat
ahsinsoft

居住地
中国 上海市 杨浦区 定海路街道

发表于 2025-3-23 21:47:59 | 显示全部楼层
数量和价格,挺难做的,不想做哈
呢喃的歌声

1

主题

21

回帖

113

积分
CN币
0 颗


威望
34

贡献
23

UID
585

QQ
QQ

微信Wechat
良风有幸

居住地
中国

 楼主| 发表于 2025-3-24 16:40:56 | 显示全部楼层
本帖最后由 zhangwei2199 于 2025-3-24 17:29 编辑

数量和价格如果商品不多的话也就是手动输入列表,不需要调用函数去获取,现在的问题就是最后无法发放物品并扣除金币
搞不定,真搞不定,几位大佬轮番指教,我还是死在代码拼接
呢喃的歌声

1

主题

21

回帖

113

积分
CN币
0 颗


威望
34

贡献
23

UID
585

QQ
QQ

微信Wechat
良风有幸

居住地
中国

 楼主| 发表于 2025-3-31 20:01:01 | 显示全部楼层

远程商店最后一次求助,大佬们再看一眼吧

本帖最后由 zhangwei2199 于 2025-3-31 20:44 编辑

以我的能力只能做到这一步了,npc创建,打开商店,物品显示,价格计算一切正常,点击购买后不扣魔币不给道具,大佬们最后一次求助,还不行就放弃了



l
  1. local Module = ModuleBase:createModule('ol_shop')
  2. local itemList = {
  3.   { name = '母爱之卵', image = 27075, price = 100000, desc = '大地鼠媽媽石像所贈與的奇異之蛋', count = 1, maxCount = 999,  itemid = '26' },
  4.   { name = '再生剧药', image = 26206, price = 50000, desc = '能重新分配人物點數,使能力改變', count = 1, maxCount = 999,  itemid = '26' },
  5.   { name = '新手标志', image = 252025, price = 500, desc = '代表剛來這個世界沒多久的頭飾,新手的證明', count = 1, maxCount = 999,  itemid = '55' },
  6.   { name = '金刚不坏安全帽', image = 27933, price = 5000, desc = '可以用來抵擋受傷一百次,史上最強的安全帽', count = 1, maxCount = 999,  itemid = '8' },
  7.   { name = '王者守护神', image = 99194, price = 50000, desc = '裝備上就會擁有王者的保護,可以輕鬆的襲擊魔族', count = 1, maxCount = 999,  itemid = '21' },
  8.   { name = '水龙料理', image = 26364, price = 500, desc = '宠物親近度+10', count = 1, maxCount = 999,  itemid = '23' },
  9. }

  10. --- 加载模块钩子
  11. function Module:onLoad()
  12.   self:logInfo('load')
  13.   local npc = self:NPC_createNormal('在线商店', 101024, { map = 1000, x = 220, y = 88, direction = 4, mapType = 0 })
  14.   self:NPC_regTalkedEvent(npc, Func.bind(self.onSellerTalked, self))
  15.   self:NPC_regWindowTalkedEvent(npc, Func.bind(self.onSellerSelected, self));
  16. end

  17. function Module:onSellerTalked(npc, player)
  18.   if NLG.CanTalk(npc, player) then
  19.     NLG.ShowWindowTalked(player, npc, CONST.窗口_商店买, CONST.BUTTON_是, 0,
  20.       self:NPC_buildBuyWindowData(101024, '在线商店', '选择你要的商品', '金钱不足', '背包已满', itemList))
  21.   end
  22. end

  23. function Module:onSellerSelected(npc, player, seqNo, select, data)
  24.        local data = tostring(_data)
  25.        if (select == CONST.按钮_关闭) then
  26.                  return;
  27.        end
  28.        local items = string.split(data, '|');
  29.        local itemList = itemList;
  30.        for key = 1, #items / 2 do
  31.          local c = itemList[items[(key - 1) * 2 + 1] + 1]
  32.          if c then
  33.            count = (tonumber(items[(key - 1) * 2 + 2]) or 0);
  34.            if c.maxCount > 0 then
  35.              maxCount = c.maxCount - count;
  36.              totalGold = c.price * count;
  37.              keyNum = items[(key - 1) * 2 + 1] + 1;
  38.            else
  39.              maxCount = c.maxCount;
  40.              NLG.SystemMessage(player,"[系統]此物品倉庫已無存貨!");
  41.              return;
  42.            end
  43.            if c.itemid > 1 then
  44.              itemid = c.itemid;
  45.            else
  46.              itemid = -1;
  47.            end
  48.          end
  49.          if itemid == -1 then  ----排除透过按钮取得道具
  50.             return;
  51.          end
  52.          if maxCount < 0 then
  53.            NLG.SystemMessage(player,"[系統]數量超過庫存!");
  54.            return;
  55.          end
  56.          if Char.ItemNum(player, 68000) < totalGold then
  57.            NLG.SystemMessage(player,"[系統]魔力金幣卡數量不足無法購買!");
  58.            return;
  59.          end
  60.          if (Char.ItemSlot(player)<20) then
  61.                 itemList[keyNum][3] = itemList[keyNum][3] - count;
  62.                 Char.GiveItem(player,itemList[keyNum][2],count);
  63.                 Char.DelItem(player, 68000, totalGold);
  64.                 for NewItemSlot = 8,27 do
  65.                     local NewItemIndex = Char.GetItemIndex(player, NewItemSlot);
  66.                     if (NewItemIndex > 0) then
  67.                       if (Item.GetData(NewItemIndex, CONST.道具_已鉴定)==0) then
  68.                         Item.SetData(NewItemIndex, CONST.道具_已鉴定, 1);
  69.                         Item.UpItem(player, NewItemSlot);
  70.                         NLG.UpChar(player);
  71.                       end
  72.                     end
  73.                 end
  74.          else
  75.                 NLG.Say(player, -1, "注意提取數量超過物品欄!", CONST.颜色_黄色, CONST.字体_中);
  76.                 return;
  77.          end
  78.          if (itemList[keyNum][3]==0) then
  79.                 table.remove(itemList,keyNum);
  80.                 itemList = itemList;
  81.          end
  82.    end
  83. end

  84. --- 卸载模块钩子
  85. function Module:onUnload()
  86.   self:logInfo('unload')
  87. end

  88. return Module;
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
万物创造者

188

主题

207

回帖

2341

积分
CN币
1 颗


威望
574

贡献
792

UID
1

QQ
QQ

微信Wechat
ahsinsoft

居住地
中国 上海市 杨浦区 定海路街道

发表于 2025-3-31 20:09:52 | 显示全部楼层
论坛插入代码时,请使用



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
万物创造者

188

主题

207

回帖

2341

积分
CN币
1 颗


威望
574

贡献
792

UID
1

QQ
QQ

微信Wechat
ahsinsoft

居住地
中国 上海市 杨浦区 定海路街道

发表于 2025-3-31 20:13:50 | 显示全部楼层
ol_shop.lua 只是测试版,我没发布过,代码只供参考。强撸当心服务器爆炸
圣洁的灵魂 [SVIP]

14

主题

26

回帖

2106

积分
CN币
76 颗


威望
693

贡献
599

UID
284

QQ
QQ



发表于 2025-3-31 20:49:51 | 显示全部楼层
本帖最后由 xman 于 2025-4-2 23:51 编辑
zhangwei2199 发表于 2025-3-31 20:01
以我的能力只能做到这一步了,npc创建,打开商店,物品显示,价格计算一切正常,点击购买后不扣魔币不给道 ...

你确认一下你的itemList中itemid有正确吗?看上去错误
我的代码之前是扣除另一种货币,我帮你改成魔币了

恩  21列那边确实改出错,全名是之后要远端的fn才用



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
呢喃的歌声

1

主题

21

回帖

113

积分
CN币
0 颗


威望
34

贡献
23

UID
585

QQ
QQ

微信Wechat
良风有幸

居住地
中国

 楼主| 发表于 2025-3-31 21:45:38 | 显示全部楼层
xman大佬慧眼如炬,itemid确实不对,去引号,然后21行这里  (player, shopNPc, CONST.窗口_商店买, CONST.BUTTON_是, 0,   应该是npc,deepseek帮忙查的错
现在可以结算了,不过买到的物品全是铜剑,买一次后商店窗口也有些问题,离胜利不远了,大佬们威武

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|CN魔力实验室

GMT+8, 2025-4-27 23:25 , Processed in 0.065599 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表