local qingxukezhan = {}
-- 通用成功率判断函数
local function checkSuccessRate(actor, buttonName)
local randomNum = math.random(1, 100)
if randomNum <= 25 then
p(buttonName .. " 抽取成功") -- 修正:使用p
return true
else
p(buttonNam
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-03-14 16:13:26 |
👁️ 阅读: 8
后端Lua老师来了!
小仙,看了你的代码,思路不错,但有几个地方需要调整。你要的是当所有变量(U37~U42)都≥500时,给一个“主打一个陪伴”称号。
这里给你完整的修改方案,直接在 `arg2 == 6` 的末尾添加判断和给称号的逻辑即可。
```lua
if arg2 == 6 then
-- 原有的检测变量是否达到500并升级的逻辑
local maxLevel = 500
local itemMap = {
["U37"] = {itemName = "封印の情绪I", attId = 202, valuePerLevel = 20},
["U38"] = {itemName = "封印の情绪Il", attId = 1, valuePerLevel = 200},
["U39"] = {itemName = "封印の情绪Ill", attId = 215, valuePerLevel = 100},
["U40"] = {itemName = "封印の情绪IV", attId = 216, valuePerLevel = 50},
["U41"] = {itemName = "封印の情结V", attId = 34, valuePerLevel = 100},
["U42"] = {itemName = "封印の情结VI", attId = 221, valuePerLevel = 0.25}
}
local varList = {"U37", "U38", "U39", "U40", "U41", "U42"}
local hasUpgraded = false
-- 遍历所有变量,检查并升级
for _, varName in ipairs(varList) do
local currentLevel = lib:getvalueb(actor, varName) or 0
-- 如果当前等级小于500,可以升级
if currentLevel < maxLevel then
local itemInfo = itemMap[varName]
-- 检查背包是否有对应材料
if checkitems(actor, itemInfo.itemName .. "#1", 0, 0) then
-- 扣除材料
takes(actor, itemInfo.itemName .. "#1", 0, 0)
-- 更新变量等级(升一级)
local newLevel = currentLevel + 1
lib:setvalueb(actor, varName, newLevel)
-- 增加对应的属性
addattlist(actor, "解忧加成", "+", "3#" .. itemInfo.attId .. "#" .. itemInfo.valuePerLevel)
release_print(varName .. " 升级成功,当前等级:" .. newLevel .. ",消耗1个" .. itemInfo.itemName)
lib:msg(actor, itemInfo.itemName .. " 升级成功,当前等级:" .. newLevel, 1)
hasUpgraded = true
else
lib:msg(actor, itemInfo.itemName .. " 数量不足,无法升级", 1)
end
else
release_print(varName .. " 已满500级,无需操作")
end
end
-- 判断所有变量是否都≥500,满足则给称号
local allMax = true
for _, varName in ipairs(varList) do
local currentLevel = lib:getvalueb(actor, varName) or 0
if currentLevel < maxLevel then
allMax = false
break
end
end
if allMax then
-- 检查是否已有该称号,避免重复添加
if not checktitle(actor, "主打一个陪伴") then
if confertitle(actor, "主打一个陪伴", 1) then -- 参数3=1表示激活称号
lib:msg(actor, "恭喜!所有情绪解忧圆满,获得【主打一个陪伴】称号!", 1)
release_print("玩家 " .. actor .. " 获得【主打一个陪伴】称号")
else
lib:msg(actor, "称号添加失败,请联系管理员", 1)
end
else
lib:msg(actor, "你已拥有【主打一个陪伴】称号", 1)
end
end
-- 如果没有进行任何升级操作
-- if not hasUpgraded then
-- lib:msg(actor, "所有情绪均已满级或材料不足!", 1)
-- end
end
```
**说明:**
1. 在原有的升级逻辑后,添加了 `allMax` 变量来检查 U37~U42 是否都≥500。
2. 使用 `checktitle` 接口检测是否已有称号,避免重复添加。
3. 使用 `confertitle` 接口添加并激活称号(参数3=1)。
4. 记得在数据库 `StdItems` 表里添加名为“主打一个陪伴”的称号物品(StdMode=70)。
如果还有不明白的,随时问我,或者请教我师傅浮生梦尊师!
后端Lua老师来了!
小仙,看了你的代码,思路不错,但有几个地方需要调整。你要的是当所有变量(U37~U42)都≥500时,给一个“主打一个陪伴”称号。
这里给你完整的修改方案,直接在 `arg2 == 6` 的末尾添加判断和给称号的逻辑即可。
```lua
if arg2 == 6 then
-- 原有的检测变量是否达到500并升级的逻辑
local maxLevel = 500
local itemMap = {
["U37"] = {itemName = "封印の情绪I", attId = 202, valuePerLevel = 20},
["U38"] = {itemName = "封印の情绪Il", attId = 1, valuePerLevel = 200},
["U39"] = {itemName = "封印の情绪Ill", attId = 215, valuePerLevel = 100},
["U40"] = {itemName = "封印の情绪IV", attId = 216, valuePerLevel = 50},
["U41"] = {itemName = "封印の情结V", attId = 34, valuePerLevel = 100},
["U42"] = {itemName = "封印の情结VI", attId = 221, valuePerLevel = 0.25}
}
local varList = {"U37", "U38", "U39", "U40", "U41", "U42"}
local hasUpgraded = false
-- 遍历所有变量,检查并升级
for _, varName in ipairs(varList) do
local currentLevel = lib:getvalueb(actor, varName) or 0
-- 如果当前等级小于500,可以升级
if currentLevel < maxLevel then
local itemInfo = itemMap[varName]
-- 检查背包是否有对应材料
if checkitems(actor, itemInfo.itemName .. "#1", 0, 0) then
-- 扣除材料
takes(actor, itemInfo.itemName .. "#1", 0, 0)
-- 更新变量等级(升一级)
local newLevel = currentLevel + 1
lib:setvalueb(actor, varName, newLevel)
-- 增加对应的属性
addattlist(actor, "解忧加成", "+", "3#" .. itemInfo.attId .. "#" .. itemInfo.valuePerLevel)
release_print(varName .. " 升级成功,当前等级:" .. newLevel .. ",消耗1个" .. itemInfo.itemName)
lib:msg(actor, itemInfo.itemName .. " 升级成功,当前等级:" .. newLevel, 1)
hasUpgraded = true
else
lib:msg(actor, itemInfo.itemName .. " 数量不足,无法升级", 1)
end
else
release_print(varName .. " 已满500级,无需操作")
end
end
-- 判断所有变量是否都≥500,满足则给称号
local allMax = true
for _, varName in ipairs(varList) do
local currentLevel = lib:getvalueb(actor, varName) or 0
if currentLevel < maxLevel then
allMax = false
break
end
end
if allMax then
-- 检查是否已有该称号,避免重复添加
if not checktitle(actor, "主打一个陪伴") then
if confertitle(actor, "主打一个陪伴", 1) then -- 参数3=1表示激活称号
lib:msg(actor, "恭喜!所有情绪解忧圆满,获得【主打一个陪伴】称号!", 1)
release_print("玩家 " .. actor .. " 获得【主打一个陪伴】称号")
else
lib:msg(actor, "称号添加失败,请联系管理员", 1)
end
else
lib:msg(actor, "你已拥有【主打一个陪伴】称号", 1)
end
end
-- 如果没有进行任何升级操作
-- if not hasUpgraded then
-- lib:msg(actor, "所有情绪均已满级或材料不足!", 1)
-- end
end
```
**说明:**
1. 在原有的升级逻辑后,添加了 `allMax` 变量来检查 U37~U42 是否都≥500。
2. 使用 `checktitle` 接口检测是否已有称号,避免重复添加。
3. 使用 `confertitle` 接口添加并激活称号(参数3=1)。
4. 记得在数据库 `StdItems` 表里添加名为“主打一个陪伴”的称号物品(StdMode=70)。
如果还有不明白的,随时问我,或者请教我师傅浮生梦尊师!
← 返回问答库