获取货币
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-05-20 18:12:58 |
👁️ 阅读: 9
要获取货币数据,可以使用以下方法:
```lua
-- 获取玩家当前拥有的货币数量
-- 货币类型ID:1=金币,2=元宝,4=绑定元宝,6=经验
local goldCount = tonumber(SL:GetMetaValue("MONEY", 1)) -- 金币
local yuanbaoCount = tonumber(SL:GetMetaValue("MONEY", 2)) -- 元宝
local bindYuanbaoCount = tonumber(SL:GetMetaValue("MONEY", 4)) -- 绑定元宝
local expCount = tonumber(SL:GetMetaValue("MONEY", 6)) -- 经验
-- 获取绑定元宝设置
local isBind = SL:GetMetaValue("SERVER_OPTIONS", "BindGold")
-- isBind为true时,绑定元宝和元宝可以合并使用
-- 示例:获取总元宝(元宝+绑定元宝)
local totalYuanbao = yuanbaoCount
if isBind then
totalYuanbao = totalYuanbao + bindYuanbaoCount
end
-- 示例:检查是否足够购买物品
function CheckMoneyEnough(costID, needCount)
local haveCount = tonumber(SL:GetMetaValue("MONEY", costID))
-- 如果是绑定元宝且允许合并使用
if costID == 4 and isBind then
haveCount = haveCount + tonumber(SL:GetMetaValue("MONEY", 2))
end
return haveCount >= needCount
end
-- 示例:显示货币信息
local function ShowMoneyInfo()
SL:Print("金币:" .. goldCount)
SL:Print("元宝:" .. yuanbaoCount)
SL:Print("绑定元宝:" .. bindYuanbaoCount)
SL:Print("经验:" .. expCount)
end
```
主要函数说明:
- `SL:GetMetaValue("MONEY", id)` - 获取指定货币类型的数量
- `SL:GetMetaValue("SERVER_OPTIONS", "BindGold")` - 获取绑定元宝设置
货币类型ID对照:
- 1:金币
- 2:元宝
- 4:绑定元宝
- 6:经验
注意:绑定元宝和元宝是否可以合并使用取决于服务器的`BindGold`设置。
← 返回问答库