• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Trigger] Spell Trigger Problem

Status
Not open for further replies.
Level 9
Joined
Feb 15, 2013
Messages
372
Guys can anyone explain why do this doesn't knockback? o.0 I'm trying to use hashtable but I'm not so talented at hash..... Thanks :)

[trigger="Heavy Strike"]Heavy Strike
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Heavy Strike
Actions
Set HeavyStrikeUnit = (Triggering unit)
Set HeavyStrikeTarget = (Target unit of ability being cast)
Set HeavyStrikeDamage = 7.30
Set HeavyStrikeTimer = 2.00
Hashtable - Save HeavyStrikeDamage as 0 of 0 in HeavyStrikeHash
Hashtable - Save HeavyStrikeTimer as 1 of 0 in HeavyStrikeHash
Unit Group - Add HeavyStrikeTarget to HeavyStrikeGroup
Trigger - Turn on Heavy Strike Knockback <gen>[/trigger]


[trigger="Heavy Strike Knockback"]Heavy Strike Knockback
Events
Time - Every 0.04 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in HeavyStrikeGroup and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
HeavyStrikeTimer Equal to 0.00
Then - Actions
Set HeavyStrikeTarget = (Target unit of ability being cast)
Set HeavyStrikeDamage = (Load 0 of 0 from HeavyStrikeHash)
Set HeavyStrikeTimer = (Load 1 of 0 from HeavyStrikeHash)
Set HeavyStrikeLoc = ((Position of HeavyStrikeTarget) offset by (Facing of HeavyStrikeTarget) towards (Facing of HeavyStrikeTarget) degrees)
Unit - Move HeavyStrikeTarget instantly to HeavyStrikeLoc
Hashtable - Save HeavyStrikeLoop as ((Integer(HeavyStrikeLoop)) - (Integer(0.04))) of 1 in HeavyStrikeHash
Special Effect - Create a special effect attached to the foot of HeavyStrikeTarget using Abilities\Spells\Human\FlakCannons\FlakTarget.mdl
Unit - Cause HeavyStrikeUnit to damage HeavyStrikeTarget, dealing HeavyStrikeDamage damage of attack type Spells and damage type Normal
Special Effect - Destroy (Last created special effect)
Else - Actions
Custom script: call DestroyGroup(udg_HeavyStrikeGroup)
Custom script: call RemoveLocation(udg_HeavyStrikeLoc)
Hashtable - Clear all child hashtables of child 0 in HeavyStrikeHash[/trigger]
 
Level 28
Joined
Sep 26, 2009
Messages
2,520
First of all, there is no "Target unit of ability being cast" in the loop trigger, since no unit fires the loop trigger, then there can be no unit targeted.
You should use picked unit if anything.

If "HeavyStrikeDamage" has constant value, it is unnecessary to save the values inside variable if all you do is reference the variable without any further need to calculate anything => get rid of that variables and use the value directly when you damage unit.
There is also no need to save that value into hashtable. Same for "HeavyStrikeTimer".
Same can be applied to "HeavyStrikeTarget". If all you do with the target is add it into unit group, then there is no need for the variable. You should save units into variable if you do at least 2 or more actions with that unit, but you only do one in the first trigger.
In the loop trigger it should be alright to save the picked unit into variable, as you refer to that unit in multiple actions (for location, for moving it, for damaging it, etc.), however you should learn to use temporal variable (in short: temp variables).

HeavyStrikeLoc leaks. It creates a location_B as an offset of location_A. You save location_B into variable, but you don't do that with location_A, thus causing leak.
Also, you create about 50 location_A and location_B, but you remove only the last created location_B, thus after the spell ends, you created 99 location leaks.

The spell will loop endlessly, as you don't do anything with "HeavyStrikeTimer".
Look at what you do in Heavy Strike trigger:
Set timer to 2.00
Save timer into hashtable.
...
and in Heavy Strike Knockback trigger you do this:
Every 0.04 second - Load value from hashtable... this returns the value you saved - value 2.00. But that's all you do.
You check if timer is equal to 0.00 but that is simply not possible because you don't decrease the "time" from the Timer.

Last thing, this spell is not MUI which basically means that the spell will now work as intended if two or more units cast it at around the same time (meaning if unit A casts the spell and the spell is currently knocking back the target and during that 2 second interval Unit B casts the spell as well, the spell will bug out).
The reason for that is because only 1 thing can be saved under same keys. This is limited only to the type of thing you save into it, meaning if you save unit "Unit A" as 1 of 1 in MyHashtable and save integer "5" as 1 of 1 in MyHashtable, then it will work alright without any problems, because unit is different "type of data" than integer is.
However if you save unit "Unit A" as 1 of 1 in MyHashtable and then you save unit "Unit B" as 1 of 1 in MyHashtable, then both units won't be saved under those keys, only "Unit B". That is because you first save "Unit A" there, then try to save "Unit B" there, but since there is no additional place for both of them, "Unit A" gets removed from the Hashtable and "Unit B" gets in its place.
 
Status
Not open for further replies.
Top