1. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  2. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  3. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  4. Check out the Staff job openings thread.
    Dismiss Notice

Problem with a triggered spell

Discussion in 'Triggers & Scripts' started by Windu, Feb 26, 2010.

  1. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    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:

    Cast

    • 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])




    Trigger 2 - Loop

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

    Dynasti

    Joined:
    Oct 18, 2007
    Messages:
    877
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    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!
     
  3. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    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.
     
  4. Dynasti

    Dynasti

    Joined:
    Oct 18, 2007
    Messages:
    877
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    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
     
  5. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    Ok thanks a lot. I will be waiting, and yeah, I will fix these things that you mentioned.
    Hope you can find the error :)
     
  6. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,127
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    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.
     
  7. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    @ 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 ?
     
  8. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    You save the handle of the location, but then you remove the location. That's why it bugs.

    Don't remove the location in the first trigger, and during every loop. Remove it just before you clear the hashtable.
     
  9. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    But is it okay if I only remove EW_Loc[1] in the cast ?

    Won't the EW_Loc[0] leak ? Or it will just be removed when it is loaded and the time is 0 ?
     
  10. JeffreyQ

    JeffreyQ

    Joined:
    Sep 28, 2004
    Messages:
    363
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    It shouldn't leak for hashtables since the raw data is always stored until you clear it and you can always get it back again within the same storage area. I might be wrong though.
     
  11. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,127
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    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.
     
  12. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    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.
     
  13. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    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 ?
     
  14. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,127
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Add an If/Then/Else to check if the EW_Times is lower than or Equal to 600. If it is, then proceed with the movement of the lightning, else make the damage.
     
  15. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,193
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    EW distance=600*0.03 = 18

    However during 3 seconds, 0.03 second intervals it runs 3/0.03=100 times.

    18*100 = 1800 and not 600.
     
  16. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    Yeap, that's right.
    Thanks for pointing that out.

    Do you have any suggestions how to make something like a generic formula for every distance and time? I would be very grateful. :)
     
  17. Dynasti

    Dynasti

    Joined:
    Oct 18, 2007
    Messages:
    877
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    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.
     
  18. Windu

    Windu

    Joined:
    Nov 26, 2005
    Messages:
    706
    Resources:
    0
    Resources:
    0
    10x a lot dude!!!
    That was really really helpful.

    +Rep and many thanks :)
     
  19. Dynasti

    Dynasti

    Joined:
    Oct 18, 2007
    Messages:
    877
    Resources:
    4
    Maps:
    2
    Spells:
    1
    Tutorials:
    1
    Resources:
    4
    np dude :)