-- 斩击印 剑意已成,攻击怪物时有概率造成连斩效果,伤害递减。55%、45%、35%、25%、15%
[60270] = function(actor, target, hiter, skillid, damage, Model, value)
if not hasbuff(actor,60270) then return end
if hasbuff(target,60271) then return end
if skillid ~=
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-04-29 18:28:48 |
👁️ 阅读: 13
我是lua后端老师!
小仙,你这个问题问得很有水平啊!想要实现0.2秒触发一次,总共5次的效果,确实不能依赖秒级的定时器。我们得用点“巧劲”。
在996引擎里,我们可以用 `addscheduled` 这个函数来安排一个“延迟执行”的任务,它比定时器更灵活,可以精确到毫秒。我们通过递归调用自己,就能实现你想要的间隔效果。
下面我来给你写个例子,你可以参考一下:
```lua
-- 斩击印 剑意已成,攻击怪物时有概率造成连斩效果,伤害递减。55%、45%、35%、25%、15%
[60270] = function(actor, target, hiter, skillid, damage, Model, value)
if not hasbuff(actor,60270) then return end
if hasbuff(target,60271) then return end
if skillid ~= 12 then return end
-- if math.random(1,100) >= 5 then return end
setint(actor,"斩击印伤害",damage)
setint(actor,"斩击印次数",5) -- 设置剩余触发次数
addbuff(target,60271,1,1,actor)
local msg1 = "触发{[斩击印]|253:0:1} : 对目标 {连续斩击|251:0:1}"
local msg2 = "受到{[斩击印]|253:0:1} : 对自身 {连续斩击|249:0:1}"
ATTACK_func.buff_msg(actor, target, msg1, msg2)
-- 首次触发,并开始递归调度
ATTACK_buff.func_60270(actor, target, hiter, skillid, damage)
return damage
end,
-- 连斩效果递归函数
func_60270 = function(actor, target, hiter, skillid, damage)
local list = {0.55, 0.45, 0.35, 0.25, 0.15} -- 注意顺序,第一次伤害最高
local currentCount = getint(actor,"斩击印次数")
if currentCount > 0 then
-- 计算本次伤害 (使用当前次数作为索引)
local num = damage * list[6 - currentCount] -- 因为次数从5递减,所以用6减
sendattackeff(actor,110,num,"*")
release_print("触发第" .. (6 - currentCount) .. "次斩击,伤害倍率:" .. list[6 - currentCount])
-- 减少剩余次数
setint(actor,"斩击印次数", currentCount - 1)
-- 如果还有剩余次数,安排下一次执行 (200毫秒 = 0.2秒)
if (currentCount - 1) > 0 then
addscheduled(actor, 200, "ATTACK_buff.func_60270", actor, target, hiter, skillid, damage)
end
end
end,
```
**核心思路解析:**
1. **`addscheduled` 函数**:这是关键。它能在指定的毫秒数后,执行一个函数。我们用它来实现0.2秒(200毫秒)的间隔。
* 第一个参数是玩家对象 `actor`。
* 第二个参数是延迟时间(毫秒),这里是 `200`。
* 第三个参数是要执行的函数名,用字符串形式,这里是 `"ATTACK_buff.func_60270"`。
* 后面的参数是传递给这个函数的参数。
2. **递归调用**:在 `func_60270` 函数的最后,判断如果还有剩余次数,就再次调用 `addscheduled` 来安排自己下一次执行。这样就形成了一个链式调用,直到次数用完。
3. **伤害列表索引**:注意我调整了 `list` 的顺序,并且用 `6 - currentCount` 来索引。因为 `currentCount` 是从5开始递减(5,4,3,2,1),所以 `6 - currentCount` 就是(1,2,3,4,5),正好对应 `list` 里的五个伤害倍率。
**这样写的好处:**
* 完全避开了秒级定时器的限制。
* 每次触发的时间间隔是精确的200毫秒。
* 逻辑清晰,容易控制触发次数。
你试试看,如果还有不明白的地方,随时再来问我!别忘了,搞不定的时候可以请教浮生梦尊师哦!
我是lua后端老师!
小仙,你这个问题问得很有水平啊!想要实现0.2秒触发一次,总共5次的效果,确实不能依赖秒级的定时器。我们得用点“巧劲”。
在996引擎里,我们可以用 `addscheduled` 这个函数来安排一个“延迟执行”的任务,它比定时器更灵活,可以精确到毫秒。我们通过递归调用自己,就能实现你想要的间隔效果。
下面我来给你写个例子,你可以参考一下:
```lua
-- 斩击印 剑意已成,攻击怪物时有概率造成连斩效果,伤害递减。55%、45%、35%、25%、15%
[60270] = function(actor, target, hiter, skillid, damage, Model, value)
if not hasbuff(actor,60270) then return end
if hasbuff(target,60271) then return end
if skillid ~= 12 then return end
-- if math.random(1,100) >= 5 then return end
setint(actor,"斩击印伤害",damage)
setint(actor,"斩击印次数",5) -- 设置剩余触发次数
addbuff(target,60271,1,1,actor)
local msg1 = "触发{[斩击印]|253:0:1} : 对目标 {连续斩击|251:0:1}"
local msg2 = "受到{[斩击印]|253:0:1} : 对自身 {连续斩击|249:0:1}"
ATTACK_func.buff_msg(actor, target, msg1, msg2)
-- 首次触发,并开始递归调度
ATTACK_buff.func_60270(actor, target, hiter, skillid, damage)
return damage
end,
-- 连斩效果递归函数
func_60270 = function(actor, target, hiter, skillid, damage)
local list = {0.55, 0.45, 0.35, 0.25, 0.15} -- 注意顺序,第一次伤害最高
local currentCount = getint(actor,"斩击印次数")
if currentCount > 0 then
-- 计算本次伤害 (使用当前次数作为索引)
local num = damage * list[6 - currentCount] -- 因为次数从5递减,所以用6减
sendattackeff(actor,110,num,"*")
release_print("触发第" .. (6 - currentCount) .. "次斩击,伤害倍率:" .. list[6 - currentCount])
-- 减少剩余次数
setint(actor,"斩击印次数", currentCount - 1)
-- 如果还有剩余次数,安排下一次执行 (200毫秒 = 0.2秒)
if (currentCount - 1) > 0 then
addscheduled(actor, 200, "ATTACK_buff.func_60270", actor, target, hiter, skillid, damage)
end
end
end,
```
**核心思路解析:**
1. **`addscheduled` 函数**:这是关键。它能在指定的毫秒数后,执行一个函数。我们用它来实现0.2秒(200毫秒)的间隔。
* 第一个参数是玩家对象 `actor`。
* 第二个参数是延迟时间(毫秒),这里是 `200`。
* 第三个参数是要执行的函数名,用字符串形式,这里是 `"ATTACK_buff.func_60270"`。
* 后面的参数是传递给这个函数的参数。
2. **递归调用**:在 `func_60270` 函数的最后,判断如果还有剩余次数,就再次调用 `addscheduled` 来安排自己下一次执行。这样就形成了一个链式调用,直到次数用完。
3. **伤害列表索引**:注意我调整了 `list` 的顺序,并且用 `6 - currentCount` 来索引。因为 `currentCount` 是从5开始递减(5,4,3,2,1),所以 `6 - currentCount` 就是(1,2,3,4,5),正好对应 `list` 里的五个伤害倍率。
**这样写的好处:**
* 完全避开了秒级定时器的限制。
* 每次触发的时间间隔是精确的200毫秒。
* 逻辑清晰,容易控制触发次数。
你试试看,如果还有不明白的地方,随时再来问我!别忘了,搞不定的时候可以请教浮生梦尊师哦!
← 返回问答库