-- 金条使用函数
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_
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-06-01 15:39:18 |
👁️ 阅读: 11
我是lua后端老师!
小仙,你这个问题问得很有水平!让我看看你的代码,你想要根据金条的绑定状态来分别显示数量,而不是显示总数量。我来帮你修改一下。
首先,我们需要在界面显示时判断当前选择的金条是绑定还是非绑定的。你的代码中已经有了`getplaydef(actor, "N12")`来记录选择的数量,但还需要一个变量来记录当前选择的是绑定还是非绑定状态。
让我帮你修改代码:
```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
-- 设置默认选择绑定状态(0=非绑定,1=绑定)
if getplaydef(actor, "N13") == nil or getplaydef(actor, "N13") == "" then
setplaydef(actor, "N13", 0) -- 默认显示非绑定数量
end
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
release_print("绑定金条数量:", bind_item_num, "非绑定金条数量:", nonbind_item_num)
if total_item_num >= 1 then
if getplaydef(actor, "N12") < 1 then
setplaydef(actor, "N12", 1)
end
-- 根据绑定状态决定显示的数量
local show_item_num = 0
local bind_state = getplaydef(actor, "N13") or 0 -- 获取绑定状态(0=非绑定,1=绑定)
if bind_state == 0 then
-- 显示非绑定数量
show_item_num = nonbind_item_num
else
-- 显示绑定数量
show_item_num = bind_item_num
end
-- 如果选择的数量大于当前状态的数量,调整选择数量
local selected_num = getplaydef(actor, "N12")
if selected_num > show_item_num and show_item_num > 0 then
setplaydef(actor, "N12", show_item_num)
selected_num = show_item_num
end
local text = selected_num * 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=]] .. show_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=]] .. selected_num .. [[|maxvalue=]] .. show_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 .. [[,使用物品>
<Button|x=50.0|y=200.0|size=12|color=255|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") or 1
local N13_state = getplaydef(actor, "N13") or 0 -- 绑定状态(0=非绑定,1=绑定)
if p2 == "滑动" then
if N12_num < 1 then
setplaydef(actor, "N12", 1)
else
local num = getconst(actor, "<$NPCPARAMS(3,N12)>")
setplaydef(actor, "N12", num)
end
end
if p2 == "+" then
-- 根据当前状态获取最大数量
local max_num = 0
if N13_state == 0 then
max_num = nonbind_item_num
else
max_num = bind_item_num
end
if N12_num < max_num then
setplaydef(actor, "N12", N12_num + 1)
end
end
if p2 == "-" then
if N12_num > 1 then
setplaydef(actor, "N12", N12_num - 1)
end
end
if p2 == "切换绑定" then
-- 切换绑定状态
if N13_state == 0 then
setplaydef(actor, "N13", 1) -- 切换到绑定
else
setplaydef(actor, "N13", 0) -- 切换到非绑定
end
-- 重置选择数量为1
setplaydef(actor, "N12", 1)
end
if p2 == "使用物品" then
-- 检查背包中是否有足够的金条
if N13_state == 0 then
-- 使用非绑定金条
if nonbind_item_num < N12_num then
sendmsg(actor, 1, '{"Msg":"非绑定金条数量不足","FColor":255,"BColor":219,"Type":1}')
item_103main(actor, item)
return
end
takeitem(actor, item_name, N12_num, 1, "使用非绑定金条")
changemoney(actor, 1, "+", N12_num * 1000000, "非绑定金条兑换", true)
else
-- 使用绑定金条
if bind_item_num < N12_num then
sendmsg(actor, 1, '{"Msg":"绑定金条数量不足","FColor":255,"BColor":219,"Type":1}')
item_103main(actor, item)
return
end
takeitem(actor, item_name, N12_num, 2, "使用绑定金条")
changemoney(actor, 3, "+", N12_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. **新增绑定状态变量**:使用`N13`来记录当前选择的是绑定还是非绑定金条(0=非绑定,1=绑定)
2. **修改ItemShow显示**:根据绑定状态显示对应的数量,而不是总数量
3. **修改Slider最大值**:同样根据绑定状态设置最大可滑动值
4. **新增切换绑定按钮**:让玩家可以切换使用绑定或非绑定金条
5. **修改使用逻辑**:根据绑定状态扣除对应的金条并给予对应的金币
这样修改后,界面会根据玩家选择的绑定状态显示对应的金条数量,使用起来更加直观!小仙,你看这样修改是否符合你的需求?如果还有其他问题,随时问我哦!
← 返回问答库