|
发表于 2016-2-22 23:22:38
|
显示全部楼层
假设LZ要的效果是发动技能产生的:
比如,对目标发动技能后,30秒内5次伤害会造成40%额外伤害
- globals
- hashtable HT = InitHashtable()
- endglobals
- function Trig_testDmged takes nothing returns boolean
- local trigger trg = GetTriggeringTrigger()
- local boolean do_destroy = false
- local integer pkey = GetHandleId(trg)
- local unit source // 伤害来源
- local integer count // 计数器
- local real dmg // 受到的伤害
- local real rate = 0.4 // 系数
- if GetTriggerEventId() == EVENT_UNIT_DAMAGED then
- // 单位受到伤害
- set source = LoadUnitHandle(HT, pkey, 0)
- set dmg = GetEventDamage()
- if dmg > 1 and GetEventDamageSource() == source then
- // 伤害大于1且伤害来源是施法者
- call DisableTrigger(trg) // 防止下面的造成伤害动作反复触发受伤事件造成死循环
- call UnitDamageTarget(source, GetTriggerUnit(), dmg*rate, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_DIVINE, WEAPON_TYPE_WHOKNOWS)
- call EnableTrigger(trg)
-
- set count = LoadInteger(HT, pkey, 1) + 1
- if count >= 5 then
- set do_destroy = true
- else
- call SaveInteger(HT, pkey, 1, count)
- endif
- endif
- set source = null
- else
- // 30秒到期
- set do_destroy = true
- endif
-
- if do_destroy then
- // 销毁触发器
- call FlushChildHashtable(HT, pkey)
- call DestroyTrigger(trg)
- endif
-
- set trg = null
-
- return false
- endfunction
- function Trig_testAct takes nothing returns boolean
- local trigger trg
- local integer pkey
- if GetSpellAbilityId() == '1234' then // 1234换成自定义技能ID
- set trg = CreateTrigger()
- set pkey = GetHandleId(trg)
- call SaveUnitHandle(HT, pkey, 0, GetTriggerUnit()) // 绑定施法者
- call SaveInteger(HT, pkey, 1, 0) // 计数器,记录技能效果触发的次数
- call TriggerRegisterUnitEvent(trg, GetSpellTargetUnit(), EVENT_UNIT_DAMAGED) // 注册施法目标受伤事件
- call TriggerRegisterTimerEvent(trg, 30, false) // 注册30秒到期事件,即技能效果结束
- call TriggerAddCondition(trg, Condition(function Trig_testDmged))
- set trg = null
- endif
- return false
- endfunction
- //===========================================================================
- function InitTrig_test takes nothing returns nothing
- local trigger trg = CreateTrigger()
- call TriggerRegisterAnyUnitEventBJ(trg, EVENT_PLAYER_UNIT_SPELL_EFFECT)
- call TriggerAddCondition(trg, Condition(function Trig_testAct))
- set trg = null
- endfunction
复制代码
|
|