MemeMayhem / ModExamples

11 stars 3 forks source link

为什么创建自定义属性,计算层数时会出现错误,第一次是1,第二次是3,第三次是6,第四次是10? #52

Closed GSMUZILI closed 2 months ago

GSMUZILI commented 2 months ago

function(combat_unit) local name = "yds_passive_custom" combat_unit.Attack:RegisterOnMissileImpactCallback( name, function(level, attack_data, caster, target) if attack_data.missile_id ~= "yds_attack" then return end -- 初始化或获取已绑定的属性计数器 caster.yds_passive_custom = caster.yds_passive_custom or caster:GetBoundedAttribute(name) -- 攻击计数器加1 caster.yds_passive_custom = caster.yds_passive_custom + 1 -- 显示到面板 caster:ModifyAttribute("yds_passive_xs", caster.yds_passive_custom) -- 当攻击计数器达到4时,重置计数器并触发 if caster.yds_passive_custom >= 4 then caster.yds_passive_custom = 0 -- 面板属性归0 caster:SetAttribute("yds_passive_xs", 0) for i = 1, 2 do combat_unit.Attack:NewMissileAttack(target, "attack_brain") end end end ) end

fx013 commented 2 months ago

ModifyAttribute是做加法,你应该用caster:ModifyAttribute("yds_passive_xs",1)