• 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.

Problem with a triggered spell

Status
Not open for further replies.
Level 15
Joined
Nov 26, 2005
Messages
1,151
Hey guyz!
Here is the spell I want to make:

Explosive Wire: The hero places a wire in front of him in 3 seconds. After that the wire explodes and dmages units close to it.

Here are the triggers:


  • Explosive Wire Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Explosive Wire (W)
    • Actions
      • Set EW_Caster = (Casting unit)
      • Set EW_Loc[0] = (Position of EW_Caster)
      • Set EW_Distance = (600.00 x 0.03)
      • Set EW_Time = 3.00
      • Set EW_Angle = (Facing of EW_Caster)
      • Set EW_Times = 1
      • -------- Lightning Create --------
      • Set EW_Loc[1] = (EW_Loc[0] offset by EW_Distance towards EW_Angle degrees)
      • Lightning - Create a Finger of Death lightning effect from source EW_Loc[0] to target EW_Loc[1]
      • Set EW_Lightning = (Last created lightning effect)
      • -------- Saving --------
      • Hashtable - Save EW_Angle as 0 of (Key (Casting unit)) in Explosive_Wire_Table
      • Hashtable - Save EW_Distance as 1 of (Key (Casting unit)) in Explosive_Wire_Table
      • Hashtable - Save EW_Time as 2 of (Key (Casting unit)) in Explosive_Wire_Table
      • Hashtable - Save Handle OfEW_Loc[0] as 3 of (Key (Casting unit)) in Explosive_Wire_Table
      • Hashtable - Save Handle OfEW_Lightning as 4 of (Key (Casting unit)) in Explosive_Wire_Table
      • Hashtable - Save EW_Times as 5 of (Key (Casting unit)) in Explosive_Wire_Table
      • -------- Adding Caster to Group --------
      • Unit Group - Add (Casting unit) to EW_Group
      • -------- Cleaning --------
      • Custom script: call RemoveLocation(udg_EW_Loc[0])
      • Custom script: call RemoveLocation(udg_EW_Loc[1])




  • Explosive Wire Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in EW_Group and do (Actions)
        • Loop - Actions
          • Set EW_Angle = (Load 0 of (Key (Picked unit)) from Explosive_Wire_Table)
          • Set EW_Distance = (Load 1 of (Key (Picked unit)) from Explosive_Wire_Table)
          • Set EW_Time = (Load 2 of (Key (Picked unit)) from Explosive_Wire_Table)
          • Set EW_Loc[0] = (Load 3 of (Key (Picked unit)) in Explosive_Wire_Table)
          • Set EW_Lightning = (Load 4 of (Key (Picked unit)) in Explosive_Wire_Table)
          • Set EW_Times = (Load 5 of (Key (Picked unit)) from Explosive_Wire_Table)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • EW_Time Greater than 0.00
            • Then - Actions
              • Set EW_Times = (EW_Times + 1)
              • Set EW_Loc[2] = (EW_Loc[0] offset by (EW_Distance x (Real(EW_Times))) towards EW_Angle degrees)
              • Lightning - Move EW_Lightning to source EW_Loc[0] and target EW_Loc[2]
              • Hashtable - Save (EW_Time - 0.03) as 2 of (Key (Picked unit)) in Explosive_Wire_Table
              • Hashtable - Save EW_Times as 5 of (Key (Picked unit)) in Explosive_Wire_Table
              • Custom script: call RemoveLocation(udg_EW_Loc[2])
            • Else - Actions
              • For each (Integer A) from 1 to 6, do (Actions)
                • Loop - Actions
                  • Set EW_Loc[3] = (EW_Loc[0] offset by (100.00 x (Real((Integer A)))) towards EW_Angle degrees)
                  • Special Effect - Create a special effect at EW_Loc[3] using Abilities\Spells\Demon\DemonBoltImpact\DemonBoltImpact.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Unit - Cause (Picked unit) to damage circular area after 0.00 seconds of radius 99.50 at EW_Loc[3], dealing 280.00 damage of attack type Spells and damage type Force
                  • Custom script: call RemoveLocation(udg_EW_Loc[3])
              • Lightning - Destroy EW_Lightning
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in Explosive_Wire_Table
              • Unit Group - Remove (Picked unit) from EW_Group
          • Custom script: call RemoveLocation(udg_EW_Loc[0])


Can somebody help me find the error(s) ?

+Rep for helpful answers
 
Level 18
Joined
Oct 18, 2007
Messages
930
Hello :)

Ok before trying to find any errors I'd like to know if there are any visible major errors, like: Game Crash, lag, etc. etc.

I'll look into the triggers while awaiting your reply.

Edit: The first minior thing I see is that you could use another number on "Loc" variable in the loop as it's the same as in the first trigger. It won't affect the game, just a minior touch.

Edit: For CPU and more lag friendly issue you could have the trigger being turned on and off when it's used/not used

Edit: Other than that, it seems short but not with any issues. Good job there buddy!
 
Level 15
Joined
Nov 26, 2005
Messages
1,151
No, there is no crashing, no lag, no bugs.
Just the lightning does not move forward but stays in the position it is created in the Cast trigger.

I think that something with the use of EW_Times variable is wrong or the use of locations, but I can't find any problems on my own.

I hope, you understand what the problem is.
 
Level 18
Joined
Oct 18, 2007
Messages
930
Oh my! I must have missed that, I'll be looking into it right away!

Edit: I could have helped you more, but sadly I can't atm. Don't got Wc3 on this comp.

What you could do is to mainly check if anything that you want to be firedd aint fired. Add some debug messages and see if everything that you want to pop up does.

Edit: The distance is going to be screwed if run maybe 10 times, since you're using the formula "Distance * Times". And if you're distance is 500 and the trigger has run 10 times under a minute the lightning lenght would be 1000 and so on. But since the distance starts out so small it should not be that big of a deal.

Edit: As I said, you should add lots of debug messages and slow down the timer to see what's going on. I'm suggestion you to debug message for:
  • If the lightning is not equal to 'null'
  • if the caster not equal to 'null'
  • if the loc's arent 'null'
  • the variable of 'times'
  • the variable of 'time'
  • etc. etc. you get the idea
 
First off, why do you create it on such a small offset? Instead of (600 * 0.03), just use "200.00". Secondly, you don't turn on the second loop, unless it's initially on. Thirdly, you use the global reals for both the settings and the loading proceedure in the loop.

I don't know if this is the effect you wanted, because I don't really get it, but I made a test map for you: View attachment TestSpell.w3x
Well, I didn't understand where exactly you want the damage to take place: in he initial facing of the caster or where he faces after those 3 seconds? I made the second one, because it makes more sense, since he has a lighting to follow him.
 
Level 15
Joined
Nov 26, 2005
Messages
1,151
@ Dynasti:

Well, I got it with the messages. I will try to do that.
I already fixed the EW_Loc arraw.
The distance uses the formula (Distane * Times) => [200*0.03 (18) ]*1; [200*0.03 (18) ]*2 = 36 and so on ... that's how I want to make the lightning. Move from the casting position towards 600 distance ahead.

@ Pharaoh_

So, u misunderstood about one thing. The lightning is cast and that's all. The caster doesn't have anything to do with it any more. The lightning won't follow him, just expand from the starting cast position to a position 600 units away towards the cast facing.
That's what I want to make.


And the problem is that the lightning is created but I will neither expand nor show the effects/damage at the end.

So there must be some error in the beginning (?) of the loop ? I dunno ...

- "Secondly, you don't turn on the second loop, unless it's initially on"
- I didn't understand that, what did u mean?

- "Thirdly, you use the global reals for both the settings and the loading proceedure in the loop."
- Is that wrong? I've seen many people do it. If it is wrong - why and how can I fix it ?
 
Oh, I see, yes, I kinda lost you after some point.
So you want something like this: View attachment TestSpell.w3x

Edit: I never store locations, because I have doubts. Instead, I save the X of Location, as a real, in the hash, and the Y value and then I create a point with Convert Points to Coordinates, where I place the loaded-from-Hash reals. It's safer.
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
Removing the [1] is enough in the first trigger.

Move Custom script: call RemoveLocation(udg_EW_Loc[0]) just above "clear child hashtable" in the second trigger and it won't leak.

The handle is kind of an address that points to the memory slot the location is stored at. As long as you have the handle, you can retrieve the location and no leak is created.

And use Triggering unit instead of casting unit, it's faster.
 
Level 15
Joined
Nov 26, 2005
Messages
1,151
Ok, thanks a lot to lal of you (+Rep ofc)

Now that problem is fixed. The lightning moves and damages just fine.

@ Pharaoh_
I will try your method in my next spells, to see which is easier for me, thanks for suggestiong.

@ Maker
Yeah, I almost reached the same conclusion, but when u say the same - I am sure :) that it's ok.

But there is another issue I would like to clear:
Now the lightning goes far beyond 600 distance... How can I fix that ? I want it to go for exactly 600 distance in 3 seconds (Just like I've set the variables). And yet that "EW_Times" is not right, is it? What can I do ?
 
Level 18
Joined
Oct 18, 2007
Messages
930
Depends.

You could just go out from a formula that uses how far it would go in a sec. Lets say after 1 sec you want it to go 800 in distance, but you don't know how it will fit with your tick. Well just use this:

At start you define your time:
Tick = 0.03
set Time = 3.74
set DistanceWanted = 2870
set DistancePerTick = DistanceWanted/Time*Tick (2870/3.74*0.03)
set SomeOtherTimeCounter = Time

Then every loop you add:
set SomeOtherTimeCounter = SomeOtherTimeCounter - Tick
set DistanceTraveled = DistanceTraveled + DistancePerTick
if SomeOtherTimeCounter (Less than or Equal to 0.00) then
endloop or something
etc. etc.

This should leave your moving object aprox 2870 distance from where it started aprox 3.74 seconds later.

Edit: The formula may be crooked, let me give it a sec to test it out

Edit: It works.
 
Level 15
Joined
Nov 26, 2005
Messages
1,151
Depends.

You could just go out from a formula that uses how far it would go in a sec. Lets say after 1 sec you want it to go 800 in distance, but you don't know how it will fit with your tick. Well just use this:

At start you define your time:
Tick = 0.03
set Time = 3.74
set DistanceWanted = 2870
set DistancePerTick = DistanceWanted/Time*Tick (2870/3.74*0.03)
set SomeOtherTimeCounter = Time

Then every loop you add:
set SomeOtherTimeCounter = SomeOtherTimeCounter - Tick
set DistanceTraveled = DistanceTraveled + DistancePerTick
if SomeOtherTimeCounter (Less than or Equal to 0.00) then
endloop or something
etc. etc.

This should leave your moving object aprox 2870 distance from where it started aprox 3.74 seconds later.

Edit: The formula may be crooked, let me give it a sec to test it out

Edit: It works.

10x a lot dude!!!
That was really really helpful.

+Rep and many thanks :)
 
Status
Not open for further replies.
Top