---捡取触发
function shoubao_start(player, itemname, itemidx)
local isKuafu = checkkuafu(player)
-- 个人首爆
if not isKuafu and grsbCfg[tostring(itemidx)] then
local zt = lualib:GetPlayerInt(player, "个人首爆_" .. itemidx)
if zt == 0
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-07-23 21:56:41 |
👁️ 阅读: 11
我是lua后端老师!
小仙,我来帮你优化这段代码。根据你的需求,需要根据 `newItemidx` 是否有值来决定调用 `callscriptex` 时使用的参数。让我们看看这段代码:
```lua
-- 捡取触发
function shoubao_start(player, itemname, itemidx)
local isKuafu = checkkuafu(player)
-- 个人首爆
if not isKuafu and grsbCfg[tostring(itemidx)] then
local zt = lualib:GetPlayerInt(player, "个人首爆_" .. itemidx)
if zt == 0 then
local jilu = lualib:GetVar(player, VarCfg["个人首爆待领"])
if not string.find(jilu, itemidx .. ";") then
jilu = jilu .. itemidx .. ";"
lualib:SetVar(player, VarCfg["个人首爆待领"], jilu)
lualib:Tips(player, string.format("恭喜你,获得首爆物品[%s]!", itemname) , 1)
local newItemidx = unifyequipmentgender(player, itemidx) -- 这里接收返回值
callscriptex(player, "ADDVARCACHE", "T121", itemidx, 1)
release_print(newItemidx)
end
end
end
end
```
现在根据你的要求修改代码,判断 `newItemidx` 是否有值:
```lua
-- 捡取触发
function shoubao_start(player, itemname, itemidx)
local isKuafu = checkkuafu(player)
-- 个人首爆
if not isKuafu and grsbCfg[tostring(itemidx)] then
local zt = lualib:GetPlayerInt(player, "个人首爆_" .. itemidx)
if zt == 0 then
local jilu = lualib:GetVar(player, VarCfg["个人首爆待领"])
if not string.find(jilu, itemidx .. ";") then
jilu = jilu .. itemidx .. ";"
lualib:SetVar(player, VarCfg["个人首爆待领"], jilu)
lualib:Tips(player, string.format("恭喜你,获得首爆物品[%s]!", itemname) , 1)
local newItemidx = unifyequipmentgender(player, itemidx) -- 这里接收返回值
-- 根据newItemidx是否有值决定使用哪个参数
if newItemidx and newItemidx ~= "" and newItemidx ~= 0 then
-- 当newItemidx有值时使用newItemidx
callscriptex(player, "ADDVARCACHE", "T121", newItemidx, 1)
else
-- 当newItemidx没有值时使用原始的itemidx
callscriptex(player, "ADDVARCACHE", "T121", itemidx, 1)
end
release_print(newItemidx)
end
end
end
end
```
修改说明:
1. 移除了原来的 `callscriptex` 调用
2. 添加了一个条件判断,检查 `newItemidx` 是否有值
3. 使用 `if newItemidx and newItemidx ~= "" and newItemidx ~= 0 then` 来检查 `newItemidx` 是否有效
4. 如果 `newItemidx` 有效,就使用它作为参数
5. 如果 `newItemidx` 无效,就使用原始的 `itemidx` 作为参数
这样修改后,代码就会根据 `unifyequipmentgender` 函数的返回值来决定使用哪个物品ID了。小仙,如果还有其他问题,随时问我哦!
我是lua后端老师!
小仙,我来帮你优化这段代码。根据你的需求,需要根据 `newItemidx` 是否有值来决定调用 `callscriptex` 时使用的参数。让我们看看这段代码:
```lua
-- 捡取触发
function shoubao_start(player, itemname, itemidx)
local isKuafu = checkkuafu(player)
-- 个人首爆
if not isKuafu and grsbCfg[tostring(itemidx)] then
local zt = lualib:GetPlayerInt(player, "个人首爆_" .. itemidx)
if zt == 0 then
local jilu = lualib:GetVar(player, VarCfg["个人首爆待领"])
if not string.find(jilu, itemidx .. ";") then
jilu = jilu .. itemidx .. ";"
lualib:SetVar(player, VarCfg["个人首爆待领"], jilu)
lualib:Tips(player, string.format("恭喜你,获得首爆物品[%s]!", itemname) , 1)
local newItemidx = unifyequipmentgender(player, itemidx) -- 这里接收返回值
callscriptex(player, "ADDVARCACHE", "T121", itemidx, 1)
release_print(newItemidx)
end
end
end
end
```
现在根据你的要求修改代码,判断 `newItemidx` 是否有值:
```lua
-- 捡取触发
function shoubao_start(player, itemname, itemidx)
local isKuafu = checkkuafu(player)
-- 个人首爆
if not isKuafu and grsbCfg[tostring(itemidx)] then
local zt = lualib:GetPlayerInt(player, "个人首爆_" .. itemidx)
if zt == 0 then
local jilu = lualib:GetVar(player, VarCfg["个人首爆待领"])
if not string.find(jilu, itemidx .. ";") then
jilu = jilu .. itemidx .. ";"
lualib:SetVar(player, VarCfg["个人首爆待领"], jilu)
lualib:Tips(player, string.format("恭喜你,获得首爆物品[%s]!", itemname) , 1)
local newItemidx = unifyequipmentgender(player, itemidx) -- 这里接收返回值
-- 根据newItemidx是否有值决定使用哪个参数
if newItemidx and newItemidx ~= "" and newItemidx ~= 0 then
-- 当newItemidx有值时使用newItemidx
callscriptex(player, "ADDVARCACHE", "T121", newItemidx, 1)
else
-- 当newItemidx没有值时使用原始的itemidx
callscriptex(player, "ADDVARCACHE", "T121", itemidx, 1)
end
release_print(newItemidx)
end
end
end
end
```
修改说明:
1. 移除了原来的 `callscriptex` 调用
2. 添加了一个条件判断,检查 `newItemidx` 是否有值
3. 使用 `if newItemidx and newItemidx ~= "" and newItemidx ~= 0 then` 来检查 `newItemidx` 是否有效
4. 如果 `newItemidx` 有效,就使用它作为参数
5. 如果 `newItemidx` 无效,就使用原始的 `itemidx` 作为参数
这样修改后,代码就会根据 `unifyequipmentgender` 函数的返回值来决定使用哪个物品ID了。小仙,如果还有其他问题,随时问我哦!
← 返回问答库