|
发表于 2013-8-16 09:06:13
|
显示全部楼层
本帖最后由 lfglvstory 于 2013-8-16 09:24 编辑
给楼主提供可移植版J版触发,手写的经测试OK。移植请看代码中的注释,很简单的。
- function Trig_Summon_Conditions takes nothing returns boolean
- // 'u001' 修改为你所召唤的单位的编号(在编辑器按ctr+d可以看到)
- return GetUnitTypeId(GetSummonedUnit()) == 'u001'
- endfunction
- function Trg_Damage_Conditions takes nothing returns boolean
- return GetEventDamage() > 0
- endfunction
- function Damage_TimerActions takes nothing returns nothing
- local timer t = GetExpiredTimer()
- local integer parentKey = GetHandleId(t)
- local unit hero = LoadUnitHandle(udg_HT,parentKey,StringHash("hero"))
- local real tempLife = LoadReal(udg_HT,parentKey,StringHash("damage"))
- call SetUnitState(hero,UNIT_STATE_LIFE,GetUnitState(hero,UNIT_STATE_LIFE) + tempLife)
- call FlushChildHashtable(udg_HT,parentKey)
- call PauseTimer(t)
- call DestroyTimer(t)
- set t = null
- set hero = null
- endfunction
- function Trg_Damage_Actions takes nothing returns nothing
- local timer t = CreateTimer()
- local integer key = GetHandleId(t)
- local unit hero = GetTriggerUnit()
- local unit enemy = GetEventDamageSource()
- local unit summon = LoadUnitHandle(udg_HT,GetHandleId(hero),StringHash("summon"))
- local real dmg = GetEventDamage()
- call DisableTrigger(GetTriggeringTrigger())
- if IsUnitAliveBJ(summon) then
- // 将伤害转移给召唤单位(如果不需要转移伤害请删除下面这句)
- call UnitDamageTarget(enemy,summon,dmg,true,false,ATTACK_TYPE_HERO,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
- // 优先判断伤害是否致命
- if dmg > GetUnitState(hero,UNIT_STATE_LIFE) then
- // 若伤害致命,则直回血
- call SetUnitState(hero,UNIT_STATE_LIFE,GetUnitState(hero,UNIT_STATE_LIFE)+dmg)
- else
- // 否则用短时计时器来完美补足生命(不会出现生命值先减少后增加的尴尬现象)
- // 保存回血单位和回血值
- call SaveUnitHandle(udg_HT,key,StringHash("hero"),hero)
- call SaveReal(udg_HT,key,StringHash("damage"),dmg)
- // 启动计时器
- call TimerStart(t,0.0035,FALSE,function Damage_TimerActions)
- endif
- else
- call FlushChildHashtable(udg_HT,GetHandleId(hero))
- call DestroyTrigger(GetTriggeringTrigger())
- endif
- set t = null
- set hero = null
- set enemy = null
- set summon = null
- call EnableTrigger(GetTriggeringTrigger())
- endfunction
- function Trig_Summon_Actions takes nothing returns nothing
- local unit hero = GetSummoningUnit()
- local unit summon = GetSummonedUnit()
- local trigger trg_Damage = CreateTrigger()
- local integer key = GetHandleId(hero)
- // 保存召唤物
- call SaveUnitHandle(udg_HT,key,StringHash("summon"),summon)
- // 注册触发器
- call TriggerRegisterUnitEvent(trg_Damage,hero,EVENT_UNIT_DAMAGED)
- call TriggerAddCondition(trg_Damage, Condition(function Trg_Damage_Conditions))
- call TriggerAddAction(trg_Damage,function Trg_Damage_Actions)
- set hero = null
- set summon = null
- endfunction
- //===========================================================================
- //移植说明:魔兽1.24以上适用
- //> 建一个全局变量哈希表,命名为 HT
- //> 新建一个触发器,命名为 Summon,将其转换为自定义文本格式,在将此代码复制进去即可
- //===========================================================================
- function InitTrig_Summon takes nothing returns nothing
- set gg_trg_Summon = CreateTrigger()
- // 初始化哈希表
- call FlushParentHashtable(udg_HT)
- set udg_HT = InitHashtable()
- call TriggerRegisterAnyUnitEventBJ(gg_trg_Summon, EVENT_PLAYER_UNIT_SUMMON )
- call TriggerAddCondition(gg_trg_Summon, Condition(function Trig_Summon_Conditions))
- call TriggerAddAction(gg_trg_Summon, function Trig_Summon_Actions)
- endfunction
复制代码 |
|