• 🏆 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!

[Spell] Use WorldBounds for GUI?

Status
Not open for further replies.
Level 12
Joined
May 16, 2020
Messages
660
Hi guys,

In my map I use missiles and currently have no world bound protection, which I read can cause crashes.

I found 2 options:

Is one of these "better"? And would this library automatically work or do I need to perform a X and Y coordinate (coming from the worldbound system) check before moving a unit?

Cheers
 
Level 11
Joined
May 29, 2008
Messages
132
The library by Almia provides a "SetUnitBoundedX " and "SetUnitBoundedY", which can be used to move a unit, bounded by the world bounds. Nestharus's library just provides a easy way to look up the world bounds, but you need to do the check manually.
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,562
These systems are nothing special, they just save you the hassle of having to check the bounds of your map manually.

You can get these values yourself by looking the bottom left corner of the World Editor. It will display the current X,Y,Z of your mouse position. Then you create four Real variables, minX, minY, maxX, and maxY, and set them to the appropriate values.

minX = Left bounds.
minY = Bottom bounds.
maxX = Right bounds.
maxY = Top bounds.

If your map is square then this is extra simple to do because your minX will be a negative version of your maxX and your minY will be a negative version of your maxY.

That being said, they're still useful since they do the work for you. The World Bounds system seems to be the most useful because it provides functions like "IsPointInMap" that you can call to get a True/False value based on the results.

  • Custom script: local boolean b
  • Custom script: set b = IsPointInMap(x, y)
^b will be set to either True or False, True if the given x/y coordinates are inside the map bounds.
 
Last edited:
Level 14
Joined
Sep 28, 2011
Messages
968
I heard that if you are using jass then function calls have a non negligible cost(that is still low) and so that inlining could be a good idea.(use multiple times "run custom script" to check for the bounds)
If you are using lua then the extra cost might be negligible.
 
Last edited:
Level 12
Joined
May 16, 2020
Messages
660
Sorry @Uncle I have troubles applying what you wrote. If I add this custom script, it gives me the following error:

"locals are only supported at the top of the function"

  • Elune Arrow Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer EluneArrow_Integer) from 1 to EluneArrow_Index, do (Actions)
        • Loop - Actions
          • Set VariableSet EluneArrow_PointTemp[1] = (Position of EluneArrow_Arrow[EluneArrow_Integer])
          • Set VariableSet EluneArrow_PointTemp[2] = (EluneArrow_PointTemp[1] offset by 27.00 towards (Facing of EluneArrow_Arrow[EluneArrow_Integer]) degrees.)
          • Set VariableSet EluneArrow_Pos_X = (X of EluneArrow_PointTemp[2])
          • Set VariableSet EluneArrow_Pos_Y = (Y of EluneArrow_PointTemp[2])
          • Custom script: local boolean b
          • Custom script: set b = IsPointInMap(udg_EluneArrow_Pos_X, udg_EluneArrow_Pos_Y)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
            • Else - Actions
          • Unit - Move EluneArrow_Arrow[EluneArrow_Integer] instantly to EluneArrow_PointTemp[2]
          • Custom script: call SetUnitX(udg_EluneArrow_Arrow[udg_EluneArrow_Integer], udg_EluneArrow_Pos_X)
          • Custom script: call SetUnitY(udg_EluneArrow_Arrow[udg_EluneArrow_Integer], udg_EluneArrow_Pos_Y)
          • Set VariableSet EluneArrow_DistanceTravel[EluneArrow_Integer] = (EluneArrow_DistanceTravel[EluneArrow_Integer] + 27.00)
          • Rest....
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,562
That's because locals are only supported at the top of the function :p But what it really means is that local CREATION is only supported at the top.

In other words, move "local boolean b" to the top of your trigger, so it's the first action.
 
Level 12
Joined
May 16, 2020
Messages
660
Thanks, worked, but... how do I check the local variable b in GUI?

I guess this needs a custom command again?

  • Elune Arrow Loop
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Custom script: local boolean b
      • For each (Integer EluneArrow_Integer) from 1 to EluneArrow_Index, do (Actions)
        • Loop - Actions
          • Set VariableSet EluneArrow_Point[1] = (Position of EluneArrow_Arrow[EluneArrow_Integer])
          • Set VariableSet EluneArrow_Point[2] = (EluneArrow_Point[1] offset by 27.00 towards (Facing of EluneArrow_Arrow[EluneArrow_Integer]) degrees.)
          • -------- --------
          • Set VariableSet EluneArrow_Pos_X = (X of EluneArrow_Point[2])
          • Set VariableSet EluneArrow_Pos_Y = (Y of EluneArrow_Point[2])
          • Custom script: set b = IsPointInMap(udg_EluneArrow_Pos_X, udg_EluneArrow_Pos_Y)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • HERE CONDITION IF B = TRUE
            • Then - Actions
              • Custom script: call SetUnitX(udg_EluneArrow_Arrow[udg_EluneArrow_Integer], udg_EluneArrow_Pos_X)
              • Custom script: call SetUnitY(udg_EluneArrow_Arrow[udg_EluneArrow_Integer], udg_EluneArrow_Pos_Y)
              • -------- --------
              • Set VariableSet EluneArrow_DistanceTravel[EluneArrow_Integer] = (EluneArrow_DistanceTravel[EluneArrow_Integer] + 27.00)
              • Set VariableSet EluneArrow_Stun[EluneArrow_Integer] = (EluneArrow_Stun[EluneArrow_Integer] + (0.05 + (0.01 x (Real((Level of Elune's Arrow for EluneArrow_Caster[EluneArrow_Integer]))))))
              • Set VariableSet EluneArrow_Damage[EluneArrow_Integer] = (EluneArrow_Damage[EluneArrow_Integer] + 3.24)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • EluneArrow_Boolean_B[EluneArrow_Integer] Equal to False
                  • EluneArrow_DistanceTravel[EluneArrow_Integer] Greater than (EluneArrow_DistanceMax x 0.50)
                • Then - Actions
                  • Special Effect - Create a special effect attached to the origin of EluneArrow_Arrow[EluneArrow_Integer] using Abilities\Weapons\DruidoftheTalonMissile\DruidoftheTalonMissile.mdl
                  • Set VariableSet EluneArrow_Effect_B[EluneArrow_Integer] = (Last created special effect)
                  • Set VariableSet EluneArrow_Boolean_B[EluneArrow_Integer] = True
                • Else - Actions
              • -------- CHECK IF ENEMY IN RANGE --------
              • Set VariableSet EluneArrow_GroupHit = (Units within 96.00 of EluneArrow_Point[2] matching ((((Matching unit) is A structure) Not equal to True) and ((((Matching unit) is alive) Equal to True) and (((Matching unit) belongs to an enemy of (Owner of EluneArrow_Caster[EluneArrow_Integer]).) Equal to
              • Set VariableSet EluneArrow_GroupRandom[EluneArrow_Integer] = (Random 1 units from EluneArrow_GroupHit)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (EluneArrow_GroupRandom[EluneArrow_Integer] is empty) Equal to False
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • EluneArrow_Boolean_B[EluneArrow_Integer] Equal to True
                    • Then - Actions
                      • Set VariableSet EluneArrow_Stun[EluneArrow_Integer] = EluneArrow_StunMax[EluneArrow_Integer]
                      • Set VariableSet EluneArrow_Damage[EluneArrow_Integer] = EluneArrow_DamageMax[EluneArrow_Integer]
                    • Else - Actions
                  • Unit Group - Pick every unit in EluneArrow_GroupRandom[EluneArrow_Integer] and do (Actions)
                    • Loop - Actions
                      • Set VariableSet EluneArrow_Target = (Picked unit)
                      • Unit - Cause EluneArrow_Caster[EluneArrow_Integer] to damage EluneArrow_Target, dealing EluneArrow_Damage[EluneArrow_Integer] damage of attack type Spells and damage type Magic
                      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                        • If - Conditions
                          • EluneArrow_Boolean_B[EluneArrow_Integer] Equal to True
                        • Then - Actions
                          • Special Effect - Create a special effect attached to the origin of EluneArrow_Target using war3mapImported\MoonFireSlash.mdx
                          • Special Effect - Destroy (Last created special effect)
                        • Else - Actions
                      • Set VariableSet EluneArrow_Boolean_A[EluneArrow_Integer] = True
                      • Unit - Create 1 Dummy (Ground/Speed 0) for (Owner of EluneArrow_Caster[EluneArrow_Integer]) at EluneArrow_Point[2] facing Default building facing degrees
                      • Set VariableSet EluneArrow_Dummy = (Last created unit)
                      • Unit - Add Elune's Arrow (Stun) to (Last created unit)
                      • Ability - Set Ability: (Unit: EluneArrow_Dummy's Ability with Ability Code: Elune's Arrow (Stun))'s Real Level Field: Duration - Normal ('adur') of Level: 0 to EluneArrow_Stun[EluneArrow_Integer]
                      • Ability - Set Ability: (Unit: EluneArrow_Dummy's Ability with Ability Code: Elune's Arrow (Stun))'s Real Level Field: Duration - Hero ('ahdu') of Level: 0 to EluneArrow_Stun[EluneArrow_Integer]
                      • Unit - Order EluneArrow_Dummy to Human Mountain King - Storm Bolt EluneArrow_Target
                      • Unit - Add a 0.50 second Generic expiration timer to EluneArrow_Dummy
                      • Floating Text - Create floating text that reads (String((Integer((EluneArrow_Stun[EluneArrow_Integer] + 0.50))))) above EluneArrow_Target with Z offset -100.00, using font size 10.00, color (54.00%, 43.00%, 89.00%), and 0.00% transparency
                      • Floating Text - Change (Last created floating text): Disable permanence
                      • Floating Text - Set the velocity of (Last created floating text) to 72.00 towards 90.00 degrees
                      • Floating Text - Change the lifespan of (Last created floating text) to 5.00 seconds
                      • Floating Text - Change the fading age of (Last created floating text) to 2.00 seconds
                      • Custom script: call DestroyGroup (udg_EluneArrow_GroupRandom[udg_EluneArrow_Integer])
                • Else - Actions
              • Custom script: call DestroyGroup (udg_EluneArrow_GroupHit)
              • Custom script: call RemoveLocation (udg_EluneArrow_Point[1])
              • Custom script: call RemoveLocation (udg_EluneArrow_Point[2])
            • Else - Actions
              • -------- ARROW IS OUTSIDE WORLD BOUNDS --------
              • Set VariableSet EluneArrow_Boolean_A[EluneArrow_Integer] = True
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • EluneArrow_Boolean_A[EluneArrow_Integer] Equal to True
                  • EluneArrow_DistanceTravel[EluneArrow_Integer] Greater than EluneArrow_DistanceMax
            • Then - Actions
              • Unit - Kill EluneArrow_Arrow[EluneArrow_Integer]
              • Special Effect - Destroy EluneArrow_Effect_A[EluneArrow_Integer]
              • Special Effect - Destroy EluneArrow_Effect_B[EluneArrow_Integer]
              • Set VariableSet EluneArrow_Caster[EluneArrow_Integer] = EluneArrow_Caster[EluneArrow_Index]
              • Set VariableSet EluneArrow_Arrow[EluneArrow_Integer] = EluneArrow_Arrow[EluneArrow_Index]
              • Set VariableSet EluneArrow_Boolean_A[EluneArrow_Integer] = EluneArrow_Boolean_A[EluneArrow_Index]
              • Set VariableSet EluneArrow_Boolean_B[EluneArrow_Integer] = EluneArrow_Boolean_B[EluneArrow_Index]
              • Set VariableSet EluneArrow_DistanceTravel[EluneArrow_Integer] = EluneArrow_DistanceTravel[EluneArrow_Index]
              • Set VariableSet EluneArrow_Stun[EluneArrow_Integer] = EluneArrow_Stun[EluneArrow_Index]
              • Set VariableSet EluneArrow_Damage[EluneArrow_Integer] = EluneArrow_Damage[EluneArrow_Index]
              • Set VariableSet EluneArrow_Effect_A[EluneArrow_Integer] = EluneArrow_Effect_A[EluneArrow_Index]
              • Set VariableSet EluneArrow_Effect_B[EluneArrow_Integer] = EluneArrow_Effect_B[EluneArrow_Index]
              • Set VariableSet EluneArrow_Index = (EluneArrow_Index - 1)
              • Set VariableSet EluneArrow_Integer = (EluneArrow_Integer - 1)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • EluneArrow_Index Equal to 0
                • Then - Actions
                  • Trigger - Turn off (This trigger)
                • Else - Actions
            • Else - Actions
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,562
Actually, I forgot that you could just use a global variable and not a local:
  • Custom script: set udg_NewBoolean = IsPointInMap(udg_EluneArrow_Pos_X, udg_EluneArrow_Pos_Y)


But for future reference if the above is not possible.
You can use Custom script to create the If Then Else:
  • Custom script: If b then
  • put GUI actions here
  • Custom script: endif
Or create a new global Boolean and set it to be equal to b:
  • Custom script: set udg_NewBoolean = b
Then you can reference NewBoolean as you would with any variable.
 
Last edited:
Status
Not open for further replies.
Top