• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Toss

Status
Not open for further replies.
Level 4
Joined
May 23, 2010
Messages
83
hey got an issue with toss. i got a already created script and tried to make it MUI using hashtables, so i can't find where the problem is. first of all, yes i've created a hashtable and set that as toss_hashtable. i verified so many times if i got an error on string keys but i didn't. so can anybody help me?

here comes the triggers:
  • Toss Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Toss
    • Actions
      • Set toss_height = 100
      • Set toss_castcount = (toss_castcount + 1)
      • Set toss_casterpoint = (Position of (Triggering unit))
      • Set toss_targetpoint = (Target point of ability being cast)
      • Unit Group - Pick every unit in (Units within 400.00 of toss_casterpoint) and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is A structure) Equal to False
              • ((Picked unit) is alive) Equal to True
            • Then - Actions
              • Unit Group - Add (Picked unit) to toss_pickunit
              • Hashtable - Save (Angle from (Position of (Picked Unit)) to toss_targetpoint) as (Key angle) of (Key (Picked unit)) in toss_hashtable
              • Hashtable - Save 0 as (Key height) of (Key (Picked unit)) in toss_hashtable
              • Hashtable - Save (Distance between toss_pickedunitpoint and toss_targetpoint) as (Key distance) of (Key (Picked unit)) in toss_hashtable
            • Else - Actions
      • Set toss_tossedunit = (Random unit from toss_pickunit)
      • Set toss_pickedunitpoint = (Position of toss_tossedunit)
      • Unit - Add Storm Crow Form to toss_tossedunit
      • Unit - Remove Storm Crow Form from toss_tossedunit
      • Unit Group - Add toss_tossedunit to toss_tossedunits
      • Trigger - Turn on Toss Periodic <gen>
      • Custom script: call RemoveLocation (udg_toss_casterpoint)
      • Custom script: call RemoveLocation (udg_toss_targetpoint)
      • Custom script: call RemoveLocation (udg_toss_pickedunitpoint)
      • Custom script: call DestroyGroup (udg_toss_pickunit)
  • Toss Periodic
    • Events
      • Time - Every 0.02 Seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in toss_tossedunits and do (Actions)
        • Loop - Actions
          • Set toss_tempheight = (Load (Key height) of (Key (Picked unit)) from toss_hashtable)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • toss_tempheight Less than toss_height
            • Then - Actions
              • Set toss_tempheight = (toss_tempheight + 1)
              • Hashtable - Save toss_tempheight as (Key height) of (Key (Picked unit)) in toss_hashtable
              • Set toss_angle = (Load (Key angle) of (Key (Picked unit)) from toss_hashtable)
              • Set toss_distance = (Load (Key distance) of (Key (Picked unit)) from toss_hashtable)
              • Set toss_pickedunitpoint = (Position of (Picked unit))
              • Set toss_targetpoint = (toss_pickedunitpoint offset by (toss_distance / (Real(toss_height))) towards toss_angle degrees)
              • Unit - Move (Picked unit) instantly to toss_targetpoint
              • Set toss_flyheight = ((Power(((Real(toss_height)) / 2.00), 2.00)) - ((((Real(toss_height)) / 2.00) - (Real(toss_tempheight))) x (((Real(toss_height)) / 2.00) - (Real(toss_tempheight)))))
              • Animation - Change (Picked unit) flying height to toss_flyheight at 0.00
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • toss_tempheight Equal to toss_height
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from toss_tossedunits
                  • Animation - Change (Picked unit) flying height to 0.00 at 0.00
                  • Special Effect - Create a special effect at Pt_PickedPos using Abilities\Spells\Orc\WarStomp\WarStompCaster.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in toss_hashtable
                • Else - Actions
              • Custom script: call RemoveLocation (udg_toss_targetpoint)
              • Custom script: call RemoveLocation (udg_toss_pickedunitpoint)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in toss_tossedunits) Equal to 0
        • Then - Actions
          • Hashtable - Clear toss_hashtable
          • Trigger - Turn off (This trigger)
        • Else - Actions
i'm still trying to make this work i really want this working!! :)
 
Level 4
Joined
May 23, 2010
Messages
83
FFFFFFUUUUUUUUU ahahahahhahahahahaha i didn't realize that i'll test it now, if it still won't work ill post again

edit: i got another issue: i pick the unit, i throw it, but the unit is tossed so far away why that?
 
Try
  • offset by (toss_distance x 0.02)
P.S. The spell is not MUI.
Example:
  • Set toss_tempheight = (toss_tempheight + 1)
    • Hashtable - Save toss_tempheight as (Key height) of (Key (Picked unit)) in toss_hashtable
Should be:
  • Set toss_tempheight = (Load Key(height) of (Key(Picked unit)) in toss_hashtable)
    • Hashtable - Save (toss_tempheight + 1) as (Key height) of (Key (Picked unit)) in toss_hashtable
 
Level 4
Joined
May 23, 2010
Messages
83
ok i did this, it is pretty mui, as i got various units being thrown, but again an issue: the game gets laggy after i cast a few times the spell. am i missing to clear some issue?

edit: new trigger, if anyone find a leak please tell me

  • Toss Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Toss
    • Actions
      • Set toss_height = 50
      • Set toss_casterpoint = (Position of (Triggering unit))
      • Set toss_targetpoint = (Target point of ability being cast)
      • Set toss_pickunit = (Units within 250.00 of toss_casterpoint)
      • Unit Group - Pick every unit in toss_pickunit and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • ((Picked unit) is A structure) Equal to True
                  • ((Picked unit) is A flying unit) Equal to True
                  • ((Picked unit) is alive) Equal to False
                  • (Triggering unit) Equal to (Picked unit)
            • Then - Actions
              • Unit Group - Remove (Picked unit) from toss_pickunit
            • Else - Actions
      • Set toss_tossedunit = (Random unit from toss_pickunit)
      • Set toss_pickedunitpoint = (Position of toss_tossedunit)
      • Unit - Add Storm Crow Form to toss_tossedunit
      • Unit - Remove Storm Crow Form from toss_tossedunit
      • Unit Group - Add toss_tossedunit to toss_tossedunits
      • Unit Group - Pick every unit in toss_pickunit and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • toss_tossedunit Equal to (Picked unit)
            • Then - Actions
              • Hashtable - Save (Angle from (Position of (Picked unit)) to toss_targetpoint) as (Key angle) of (Key (Picked unit)) in toss_hashtable
              • Hashtable - Save 0 as (Key height) of (Key (Picked unit)) in toss_hashtable
              • Hashtable - Save (Distance between (Position of (Picked unit)) and toss_targetpoint) as (Key distance) of (Key (Picked unit)) in toss_hashtable
            • Else - Actions
              • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in toss_hashtable
      • Trigger - Turn on Toss Periodic <gen>
      • Custom script: call RemoveLocation (udg_toss_casterpoint)
      • Custom script: call RemoveLocation (udg_toss_targetpoint)
      • Custom script: call RemoveLocation (udg_toss_pickedunitpoint)
      • Custom script: call DestroyGroup (udg_toss_pickunit)
and

  • Toss Periodic
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in toss_tossedunits and do (Actions)
        • Loop - Actions
          • Set toss_tempheight = (Load (Key height) of (Key (Picked unit)) from toss_hashtable)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • toss_tempheight Less than toss_height
            • Then - Actions
              • Hashtable - Save (toss_tempheight + 1) as (Key height) of (Key (Picked unit)) in toss_hashtable
              • Set toss_angle = (Load (Key angle) of (Key (Picked unit)) from toss_hashtable)
              • Set toss_distance = (Load (Key distance) of (Key (Picked unit)) from toss_hashtable)
              • Set toss_pickedunitpoint = (Position of (Picked unit))
              • Set toss_targetpoint = (toss_pickedunitpoint offset by (toss_distance / (Real(toss_height))) towards toss_angle degrees)
              • Unit - Move (Picked unit) instantly to toss_targetpoint
              • Set toss_flyheight = ((Power(((Real(toss_height)) / 2.00), 2.00)) - ((((Real(toss_height)) / 2.00) - (Real(toss_tempheight))) x (((Real(toss_height)) / 2.00) - (Real(toss_tempheight)))))
              • Animation - Change (Picked unit) flying height to toss_flyheight at 0.00
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • toss_tempheight Equal to toss_height
                • Then - Actions
                  • Unit Group - Remove (Picked unit) from toss_tossedunits
                  • Animation - Change (Picked unit) flying height to 0.00 at 0.00
                  • Special Effect - Create a special effect at toss_pickedunitpoint using Abilities\Spells\Orc\WarStomp\WarStompCaster.mdl
                  • Special Effect - Destroy (Last created special effect)
                  • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in toss_hashtable
                • Else - Actions
              • Custom script: call RemoveLocation (udg_toss_targetpoint)
              • Custom script: call RemoveLocation (udg_toss_pickedunitpoint)
            • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in toss_tossedunits) Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
 
Hm, it seems fine.
Try these changes:

  • Trigger - Turn on Toss Periodic <gen>
Add in the end of the trigger, after the leak cleaning.
• Try a periodic event of 0.03-0.04.

And no, it's not MUI, sorry; you increase a global variable. Example:
A unit casts the spell, the variable increases. When it reaches let's say 45, another unit casts it. The new unit will embrace the variable value of 45, not 0.
 
Level 4
Joined
May 23, 2010
Messages
83
yeah it's not MUI but it works properly and don't leave leaks when it is cast by more than 1 units at the same time :) and that's what i need :)

edit: still got lag
 
Ok, some things to point out:
• Power() function is rather slow. It's better/faster to use x*x than Pow(x,x).
• toss_height doesn't have to be declared on every cast. Simply put that action in a trigger that runs once, e.g. Map Initialization.

  • Set toss_pickunit = (Units within 250.00 of toss_casterpoint)
Instantly make it:
  • Set toss_pickunit = (Units within 250.00 of toss_casterpoint matching (((Matching unit) is a flying unit) Equal to False) and ((Matching unit) is a structure) Equal to False) and ((Picked unit) is alive) Equal to True) and ((Matching unit) Not Equal to (Triggering unit))
So as to remove those ugly conditions in the middle of nowhere.
• Instead of doing this kind of pick-up:
  • Set toss_tossedunit = (Random unit from toss_pickunit)
  • Unit Group - Pick every unit in toss_pickunit and do (Actions)
    • Loop - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • toss_tossedunit Equal to (Picked unit)
        • Then - Actions
          • Hashtable - Save (Angle from (Position of (Picked unit)) to toss_targetpoint) as (Key angle) of (Key (Picked unit)) in toss_hashtable
          • Hashtable - Save 0 as (Key height) of (Key (Picked unit)) in toss_hashtable
          • Hashtable - Save (Distance between (Position of (Picked unit)) and toss_targetpoint) as (Key distance) of (Key (Picked unit)) in toss_hashtable
        • Else - Actions
          • Hashtable - Clear all child hashtables of child (Key (Picked unit)) in toss_hashtable
Do this:
In the beginning of your trigger add the actions:
  • Custom script: local unit u
  • Custom script: local integer id = GetHandleId(u)
then, after the action
  • Set toss_tossedunit = (Random unit from toss_pickunit)
use the action
  • Custom script: set u = udg_toss_tossedunit
Then, save the Hashtable values on "u" like this:
  • Set Point1 = (Position of (toss_tossedunit))
  • Custom script: call SaveReal (udg_toss_hashtable, id, StringHash("height"), 0)
  • Custom script: call SaveReal (udg_toss_hashtable, id, StringHash("distance"), DistanceBetweenPoints(udg_Point1, udg_toss_targetpoint)
  • Custom script: call SaveReal (udg_toss_hashtable, id, StringHash("angle"), AngleBetweenPoints (udg_Point, udg_toss_Targetpoint)
  • Custom script: call RemoveLocation (udg_Point1)
Finally, in the end of the trigger add this:
  • Custom script: set u = null
 
Level 4
Joined
May 23, 2010
Messages
83
now it doesn't work, i did exactly as you told me, i just can't stand why did it got laggy, as i clear all child values in hashtable. so it's better to use unit custom values rather than hashtables in this case? ir is there another usage for custom values on spells triggers?
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Pharaoh_ said:
Power() function is rather slow. It's better/faster to use x*x than Pow(x,x).

Code:
x * x = x^2
Pow(x, x) = x^x

When you're just multiplying one variable by another, the multiplier operator "*" is obviously faster, though when you're doing even x³ it can be faster to use Pow(x, 3), depending on what kind of variable declarations are required. It's fairly straight-forward, typically shorter code performs faster.

Pharaoh_! You're losin' it!
 
Level 4
Joined
May 23, 2010
Messages
83
ok got that but any solution for the problem? the trigger is not deactivated when there's no units in the group? i tried too many times to remove this stupid lag, but it may be the map... someone knows about functions that may be causing lag? hashtables etc?
 
Code:
x * x = x^2
Pow(x, x) = x^x

When you're just multiplying one variable by another, the multiplier operator "*" is obviously faster, though when you're doing even x³ it can be faster to use Pow(x, 3), depending on what kind of variable declarations are required. It's fairly straight-forward, typically shorter code performs faster.

Pharaoh_! You're losin' it!

Remember though, they are doing the same thing internally, aside from the fact that Pow() is a function call and I assume it performs a loop to calculate X to the proper exponent. Pow() is only needed really when the exponent isn't constant/known. :thumbs_up:

Berb! You're losin' it!

EDIT: Unless it is something specific to this thread, I dunno. I haven't read it yet.

EDIT2: I've skimmed the code a bit, I suggest you attach a blank map with the code. Then we can test if it really lags or if it is just your computer. ;)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
Remember though, they are doing the same thing internally, aside from the fact that Pow() is a function call and I assume it performs a loop to calculate X to the proper exponent. Pow() is only needed really when the exponent isn't constant/know

It really depends. Nobody knows the internal code for Warcraft III other than Blizzard employees. If they use crappy techniques then chances are their Pow function will suck ass, though it may not (used in the correct circumstances). So far it seems multiplication is faster, though; in this case I would say absolutely.
 
Well the game is written in C or C++, or a combination of the two. In C/++ there are far quicker operations than in JASS. For example, a recursive method/function/routine is noticeably faster for performing mathematical operations.

I assume so, but generally (unless you define your own) the powers need to take into fractional/negative exponents into their algorithm. Since JASS doesn't have separate functions based on integer/fractional/negative exponents, I assume it would be slower opposed to manually multiplying with the operator as long as you know the exponent. Well, all in all I guess there is no real difference, aside from nanoseconds. :ugly: I don't even know why I mention these things, I'm just bored. =\
 
Code:
x * x = x^2
Pow(x, x) = x^x

When you're just multiplying one variable by another, the multiplier operator "*" is obviously faster, though when you're doing even x³ it can be faster to use Pow(x, 3), depending on what kind of variable declarations are required. It's fairly straight-forward, typically shorter code performs faster.

Pharaoh_! You're losin' it!

First off, my bad, I meant Pow(x,2), not (x,x).
Secondly, about Pow(), I initially searched forums to confirm that is is slower than the direct count and then I asked PurgeandFire111; it's weird how the results aligned with each other.
 
Level 4
Joined
May 23, 2010
Messages
83
ok i know some very basic jass but im not interested learning i now, as i thought i got to convert some spells to jass or vjass and toss is an example for it :)
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
If you use my Projectile library it's really easy to make a unit act as a projectile. This can make tossing the unit pretty easy. If you're not interested in learning vJass then you probably won't be able to use it, though.
 
Status
Not open for further replies.
Top