| 07-27-2011, 09:27 PM | #1 |
Hello. I'm having problems with a spell of mine: JASS:scope Heal initializer Init //================================================== // Config constants: // - // globals private constant integer SPELL_ID = 'A012' private constant integer BUFF_ID = 'B00A' private constant integer NUM_INTERVALS = 20 private constant real INTERVAL = 1.0 private constant real HEAL_PER_INTERVAL = 10.0 private constant string HEAL_EFFECT = "Abilities\\Spells\\NightElf\\Rejuvenation\\RejuvenationTarget.mdl" private constant string ATTACH_POINT_TARGET = "chest" endglobals4 //================================================== // THE CODE: //================================================== globals private hashtable htHeal endglobals private function HealEffect takes nothing returns nothing local timer t = GetExpiredTimer() local unit target = LoadUnitHandle(htHeal,GetHandleId(t),0) local effect sfx = LoadEffectHandle(htHeal,GetHandleId(t),1) call SetUnitState(target,UNIT_STATE_LIFE, GetUnitState(target, UNIT_STATE_LIFE)+HEAL_PER_INTERVAL) endfunction private function OnSpellEffect takes nothing returns nothing local unit target = GetSpellTargetUnit() local timer t = NewTimer() local effect sfx = AddSpecialEffectTarget(HEAL_EFFECT,target,ATTACH_POINT_TARGET) set htHeal = InitHashtable() call UnitAddAbility(target,BUFF_ID) call SaveUnitHandle(htHeal,GetHandleId(t),0,target) call SaveEffectHandle(htHeal,GetHandleId(t),1,sfx) call TimerStart(t,INTERVAL,true,function HealEffect) endfunction private function SpellIdMatch takes nothing returns boolean return SPELL_ID == GetSpellAbilityId() endfunction private function Init takes nothing returns nothing local trigger t = CreateTrigger() call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT) call TriggerAddCondition(t,Condition(function SpellIdMatch)) call TriggerAddAction(t,function OnSpellEffect) set t = null endfunction endscope So my problems are:
|
| 07-27-2011, 11:50 PM | #2 |
The only way to apply a buff on a unit is to use some sort of a buff applying ability, attempting to add it directly using UnitAddAbility doesn't work. As far as abilities go, you can either use a buff spell or an aura. Buff spells based on the same base spell don't stack, so if you go this route you might run out of different buff spells for your buffs. For this reason, we prefer to use auras which do stack as long as they use different buffs, even if they are based on the same base aura. This has some minor drawbacks (buff won't start fading when it's about to expire, units with autocast dispel abilities won't use them on the buffed unit) but in most maps those aren't critical problems. As far as auras go, the tornado slow aura is preferred because it doesn't show an icon in the unit's command card. It's a negative aura so the tooltip of the buff it places will display the buff's name in red, but you can always fix this using colour codes in the buff's name. You can also use the aura ability to place the special effect on the unit instead of having to create it using triggers. Make sure to use the aura to apply the effect, not the buff. For some reasons, aura buffs do not display their model when applied on the same unit that is the source of the aura. For coding a spell like this, I would recommend the ABuff system. It provides you with a framework that already covers things like the spell expiring and a periodic event. You just need to define an aBuff and write the function that does the periodic healing and use it as the aBuff's periodic event response. Check the documentation and examples in the aBuff map for more details on the implementation. |
| 07-28-2011, 07:04 AM | #3 |
You're initializing the hastable each time the spell is cast, I'm not sure if that will bug but it's not good! If you want to use a hashtable (although this is very bad as there is a 255 limit of hashtables so 1 hashtable per spell is yuck), initialize it in the Init function. I too would recommend using a buff system. I haven't ever used ABuff but I assume it's good. Dusk's buff system is also pretty nice :) |
