-- 金条
function stdmodefunc103(actor, item)
local item_name = getiteminfo(actor, item, 7)
local item_num = getbagitemcount(actor, item_name)
if item_num >= 1 then
setplaydef(actor, "N12", 1)
item_103main(actor, item)
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-06-01 15:32:37 |
👁️ 阅读: 12
我是lua后端老师!小仙,我来帮你修改这个金条使用脚本,让它能区分绑定和非绑定金条。根据你的需求,我们需要做以下调整:
1. 获取绑定金条数量时使用绑定状态参数2
2. 根据金条的绑定状态给予对应的绑定或非绑定金币
下面是修改后的完整代码:
```lua
-- 金条使用函数
function stdmodefunc103(actor, item)
local item_name = getiteminfo(actor, item, 7)
-- 获取绑定金条数量
local bind_item_num = getbagitemcount(actor, item_name, 2)
-- 获取非绑定金条数量
local nonbind_item_num = getbagitemcount(actor, item_name, 1)
local total_item_num = bind_item_num + nonbind_item_num
if total_item_num >= 1 then
setplaydef(actor, "N12", 1)
item_103main(actor, item)
stop(actor)
end
end
function item_103main(actor, item)
local item_name = getiteminfo(actor, item, 7)
-- 获取绑定金条数量
local bind_item_num = getbagitemcount(actor, item_name, 2)
-- 获取非绑定金条数量
local nonbind_item_num = getbagitemcount(actor, item_name, 1)
local total_item_num = bind_item_num + nonbind_item_num
if total_item_num >= 1 then
if getplaydef(actor, "N12") < 1 then
setplaydef(actor, "N12", 1)
end
local text = getplaydef(actor, "N12") * 100
local sc = [[
<Img|x=-562.0|y=-1049.0|width=2000|height=2000|esc=0|img=public/1900000651_1.png|link=@exit>
<Img|x=-2.0|y=2.0|show=4|bg=1|reload=0|img=public/button/exp/bg1.png|bagPos=1|move=0|loadDelay=0|esc=1|reset=1>
<Layout|x=545|y=0|width=80|height=80|link=@exit>
<Button|x=389.0|y=2.0|pimg=public/1900000511.png|nimg=public/1900000510.png|link=@exit>
<ItemShow|x=36.0|y=63.0|width=70|height=70|itemcount=]] .. total_item_num .. [[|showtips=1|itemname=]] .. item_name .. [[>
<RText|x=111.0|y=140.0|outlinecolor=0|size=16|outline=1|color=255|text=<使用获得: /FCOLOR=7><]] .. text .. [[万金币/FCOLOR=251>>
<Button|x=281.0|y=65.0|size=18|color=255|nimg=public/button/exp/+.png|pimg=public/button/exp/++.png|link=@item_103,]] .. item .. [[,+>
<Button|x=116.0|y=65.0|size=18|color=255|nimg=public/button/exp/-.png|pimg=public/button/exp/--.png|link=@item_103,]] .. item .. [[,->
<Text|a=4|x=213.0|y=80.0|size=15|color=7|text=已选择: $STM(SLIDERV_N12)个>
<Slider|x=124.0|y=111.0|width=180|defvalue=]] .. getplaydef(actor, "N12") .. [[|maxvalue=]] .. total_item_num .. [[|sliderid=N12|link=@item_103,]] .. item .. [[,滑动>
<Button|x=147.0|y=181.0|size=15|pimg=public/button/exp/an2.png|nimg=public/button/exp/an1.png|color=161|text=使用金条|link=@item_103,]] .. item .. [[,使用物品>
]]
say(actor, sc)
stop(actor)
end
end
function item_103(actor, item, p2)
local item_name = getiteminfo(actor, item, 7)
-- 获取绑定金条数量
local bind_item_num = getbagitemcount(actor, item_name, 2)
-- 获取非绑定金条数量
local nonbind_item_num = getbagitemcount(actor, item_name, 1)
local total_item_num = bind_item_num + nonbind_item_num
local N12_num = getplaydef(actor, "N12")
if p2 == "滑动" then
if N12_num < 1 then
setplaydef(actor, "N12", 1)
stdmodefunc103(actor, item)
end
local num = getconst(actor, "<$NPCPARAMS(3,N12)>")
setplaydef(actor, "N12", num)
end
if p2 == "+" and N12_num < total_item_num then
setplaydef(actor, "N12", N12_num + 1)
end
if p2 == "-" and total_item_num > 1 then
setplaydef(actor, "N12", N12_num - 1)
end
if p2 == "使用物品" then
-- 检查背包中是否有足够的金条
if total_item_num < N12_num then
return
end
local money_num = N12_num * 1000000
-- 优先扣除绑定金条
local remaining_num = N12_num
if bind_item_num > 0 then
local deduct_bind = math.min(bind_item_num, remaining_num)
if deduct_bind > 0 then
takeitem(actor, item_name, deduct_bind, 2, "使用绑定金条")
-- 给予绑定金币(货币ID3)
changemoney(actor, 3, "+", deduct_bind * 1000000, "绑定金条兑换", true)
remaining_num = remaining_num - deduct_bind
end
end
-- 如果还有剩余数量,扣除非绑定金条
if remaining_num > 0 and nonbind_item_num > 0 then
takeitem(actor, item_name, remaining_num, 1, "使用非绑定金条")
-- 给予非绑定金币(货币ID1)
changemoney(actor, 1, "+", remaining_num * 1000000, "非绑定金条兑换", true)
end
sendmsg(actor, 1, '{"Msg":"[获得金币] ' .. N12_num * 100 .. '万","FColor":255,"BColor":219,"Type":1}')
if getbagitemcount(actor, item_name, 0) < 1 then
close(actor)
return
end
end
item_103main(actor, item)
end
```
**主要修改点:**
1. **获取金条数量**:使用`getbagitemcount`的第三个参数来区分绑定状态
- `2`:只统计绑定物品
- `1`:只统计非绑定物品
- `0`:统计所有物品
2. **扣除逻辑**:优先扣除绑定金条,再扣除非绑定金条
3. **给予金币**:
- 扣除绑定金条时,给予绑定金币(货币ID3)
- 扣除非绑定金条时,给予非绑定金币(货币ID1)
这样修改后,你的金条使用脚本就能正确区分绑定和非绑定状态了!如果还有其他问题,随时问我哦~
← 返回问答库