function feijianhit(actor, sMsg)
-- 获取玩家N$切割加成变量的值作为基础伤害
local baseDamage = getplaydef(actor, "N$切割加成")
baseDamage = tonumber(baseDamage) or 0
-- 获取玩家U220变量的值作为百分比(例如10表示10%)
local percent = getplaydef(actor, "U220")
perc
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-03-09 22:11:24 |
👁️ 阅读: 16
道友你好!我是lua后端老师!
让我看看你的代码,小仙。你获取攻击下限的方法有问题哦。`gethumability`函数获取的是人物属性,但参数ID对应关系你搞混了。
根据资料,`gethumability`的参数ID:
- 5=攻击下限
- 6=攻击上限
你代码里用`gethumability(actor, 1)`获取的是防御下限,不是攻击下限。应该改成:
```lua
function feijianhit(actor, sMsg)
-- 获取玩家N$切割加成变量的值作为基础伤害
local baseDamage = getplaydef(actor, "N$切割加成")
baseDamage = tonumber(baseDamage) or 0
-- 获取玩家U220变量的值作为百分比(例如10表示10%)
local percent = getplaydef(actor, "U220")
percent = tonumber(percent) or 0
-- 获取人物攻击下限(参数ID应为5)
local minAttack = gethumability(actor, 5) -- 5表示攻击下限
-- 计算实际伤害:(切割加成 × 百分比) + 人物攻击下限
local damage = math.floor((baseDamage * percent / 100) + minAttack)
local msgdata = json2tbl(sMsg)
local mapid = getbaseinfo(actor, 3)
local monobj = getmonbyuserid(mapid, msgdata.paramList[1])
if monobj then
-- 使用计算后的damage值
humanhp(monobj, "-", damage)
sendattackeff(monobj, 2, damage, "*")
healthspellchanged(monobj)
else
release_print("怪物对象不存在")
end
end
```
这样就能正确获取到你的攻击下限1000了。下次写代码要仔细检查参数哦,不懂的可以问浮生梦尊师!
道友你好!我是lua后端老师!
让我看看你的代码,小仙。你获取攻击下限的方法有问题哦。`gethumability`函数获取的是人物属性,但参数ID对应关系你搞混了。
根据资料,`gethumability`的参数ID:
- 5=攻击下限
- 6=攻击上限
你代码里用`gethumability(actor, 1)`获取的是防御下限,不是攻击下限。应该改成:
```lua
function feijianhit(actor, sMsg)
-- 获取玩家N$切割加成变量的值作为基础伤害
local baseDamage = getplaydef(actor, "N$切割加成")
baseDamage = tonumber(baseDamage) or 0
-- 获取玩家U220变量的值作为百分比(例如10表示10%)
local percent = getplaydef(actor, "U220")
percent = tonumber(percent) or 0
-- 获取人物攻击下限(参数ID应为5)
local minAttack = gethumability(actor, 5) -- 5表示攻击下限
-- 计算实际伤害:(切割加成 × 百分比) + 人物攻击下限
local damage = math.floor((baseDamage * percent / 100) + minAttack)
local msgdata = json2tbl(sMsg)
local mapid = getbaseinfo(actor, 3)
local monobj = getmonbyuserid(mapid, msgdata.paramList[1])
if monobj then
-- 使用计算后的damage值
humanhp(monobj, "-", damage)
sendattackeff(monobj, 2, damage, "*")
healthspellchanged(monobj)
else
release_print("怪物对象不存在")
end
end
```
这样就能正确获取到你的攻击下限1000了。下次写代码要仔细检查参数哦,不懂的可以问浮生梦尊师!
← 返回问答库