local leishen = {}
function leishen.main(param1, param2, param3, param4)
lib:Require(param1, function(state)
if state then
if param1 then
leishen.parent = lib:openwin(param1, nil, true, param4) or {}
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-03-23 21:17:16 |
👁️ 阅读: 3
我是lua后端老师!
小仙,我看了一下你的代码,问题出在 **客户端脚本的点击事件** 和 **服务端处理逻辑** 的对应关系上。
在你的客户端脚本(第一个文件)中,点击 `Button_1` 时发送的消息是:
```lua
SL:SendLuaNetMsg(58003, leishen.param2, 0, 3, jsonstr)
```
这里的 `arg2`(对应 `SendLuaNetMsg` 的第四个参数)是 `3`。
而在服务端脚本(第二个文件)的 `leishen.link` 函数中,你对 `arg2` 的判断只有:
```lua
if arg2 == 0 then
map(actor,"天尊殿·雷火部")
end
if arg2 == 1 then
map(actor,"天尊大殿")
end
if arg2 == 2 then
mapmove(actor,"化魔大陆",168,270)
end
if arg2 == 3 then
-- 这里只是检测物品并扣除,没有传送
local needItemCount = 1
local itemName1 = "雷尊怒首"
local itemName2 = "避雷の顶"
local currentItemCount1 = getbagitemcount(actor, itemName1)
local currentItemCount2 = getbagitemcount(actor, itemName2)
if currentItemCount1 < needItemCount then
lib:msg(actor, "你还没有" .. itemName1, 1)
return
end
if currentItemCount2 < needItemCount then
lib:msg(actor, "你还没有" .. itemName2, 1)
return
end
takeitem(actor, itemName1, needItemCount)
takeitem(actor, itemName2, needItemCount)
end
```
所以点击 `Button_1` 时,`arg2` 是 `3`,执行的是物品检测和扣除,**并没有传送**。
如果你发现点击 `Button_1` 后还是传送了,那可能是因为:
1. 服务端脚本中 `arg2 == 3` 的判断之后,还有其他代码(比如 `map` 或 `mapmove`)没有写在条件内,导致继续执行。
2. 或者客户端发送的 `arg2` 不是 `3`,需要检查 `SendLuaNetMsg` 的参数是否正确。
建议你在服务端 `leishen.link` 开头加一句:
```lua
release_print("收到消息,arg2=" .. tostring(arg2))
```
这样就能确认实际收到的 `arg2` 值。
如果还有疑问,可以再问我,或者请教浮生梦尊师哦!
我是lua后端老师!
小仙,我看了一下你的代码,问题出在 **客户端脚本的点击事件** 和 **服务端处理逻辑** 的对应关系上。
在你的客户端脚本(第一个文件)中,点击 `Button_1` 时发送的消息是:
```lua
SL:SendLuaNetMsg(58003, leishen.param2, 0, 3, jsonstr)
```
这里的 `arg2`(对应 `SendLuaNetMsg` 的第四个参数)是 `3`。
而在服务端脚本(第二个文件)的 `leishen.link` 函数中,你对 `arg2` 的判断只有:
```lua
if arg2 == 0 then
map(actor,"天尊殿·雷火部")
end
if arg2 == 1 then
map(actor,"天尊大殿")
end
if arg2 == 2 then
mapmove(actor,"化魔大陆",168,270)
end
if arg2 == 3 then
-- 这里只是检测物品并扣除,没有传送
local needItemCount = 1
local itemName1 = "雷尊怒首"
local itemName2 = "避雷の顶"
local currentItemCount1 = getbagitemcount(actor, itemName1)
local currentItemCount2 = getbagitemcount(actor, itemName2)
if currentItemCount1 < needItemCount then
lib:msg(actor, "你还没有" .. itemName1, 1)
return
end
if currentItemCount2 < needItemCount then
lib:msg(actor, "你还没有" .. itemName2, 1)
return
end
takeitem(actor, itemName1, needItemCount)
takeitem(actor, itemName2, needItemCount)
end
```
所以点击 `Button_1` 时,`arg2` 是 `3`,执行的是物品检测和扣除,**并没有传送**。
如果你发现点击 `Button_1` 后还是传送了,那可能是因为:
1. 服务端脚本中 `arg2 == 3` 的判断之后,还有其他代码(比如 `map` 或 `mapmove`)没有写在条件内,导致继续执行。
2. 或者客户端发送的 `arg2` 不是 `3`,需要检查 `SendLuaNetMsg` 的参数是否正确。
建议你在服务端 `leishen.link` 开头加一句:
```lua
release_print("收到消息,arg2=" .. tostring(arg2))
```
这样就能确认实际收到的 `arg2` 值。
如果还有疑问,可以再问我,或者请教浮生梦尊师哦!
← 返回问答库