• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Solved] Problem with Last Created Unit

Status
Not open for further replies.
Level 8
Joined
Jun 26, 2019
Messages
318
Hello. I have problem with the last created unit trigger, and also with the last special effect created. If 2 players casting same ability at same time, it will cause the first unit created and special effect created to becomes not be the last unit created and special effect created anymore because of other player used the same ability at same time or almost same time, you know. I am thinking custom of value, you know, number of player casting the ability? How do you make variables to work like number of player casting ability to match for the last unit created and last special effect created?


  • Cast Capsize2
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Kaboom! (Goblin Sapper)
    • Actions
      • Set VariableSet AS_TempPoint[10] = (Position of (Triggering unit))
      • Unit - Create 1 for Neutral Passive at AS_TempPoint[10] facing (Position of (Triggering unit))
      • Set VariableSet ExplosionEffect = (Last created unit)
      • Wait 1.00 seconds
      • Unit - Remove ExplosionEffect from the game
      • Special Effect - Create a special effect at AS_TempPoint[10] using Environment\LargeBuildingFire\LargeBuildingFire1.mdl
      • Set VariableSet SpecialEffect = (Last created special effect)
      • Wait 2.00 seconds
      • Special Effect - Destroy SpecialEffect
-----------------------------------------------------------

How do I make it work with number of player like this?
Example:

(Trigger Player 1)
Event:
Unit begins casting an ability



if
Condition:
Ability being cast equal to Kaboom

Ability being cast equal to Player 1


then

Action:
Create unit with Player 1
Variables with Player 1
Create special effect with Player 1
Variables with Player 1
Triggering Unit with Player 1





(Trigger Player 2)
Event:
Unit begins casting an ability



if
Condition:
Ability being cast equal to Kaboom

Ability being cast equal to Player 2


then

Action:
Create unit with Player 2
Variables with Player 2
Create special effect with Player 2
Variables with Player 2
Triggering Unit with Player 2





(Trigger Player 3)
Event:
Unit begins casting an ability



if
Condition:
Ability being cast equal to Kaboom

Ability being cast equal to Player 3


then

Action:
Create unit with Player 3
Variables with Player 3
Create special effect with Player 3
Variables with Player 3

Triggering Unit with Player 3


-----------------------------------------------------------
 
Level 12
Joined
Feb 5, 2018
Messages
521
Create integer variable
Then set variable myinteger = player number of owner of unit(triggering unit)

To make it more efficient you should also store the player owning the unit into player Variable.

Add index arrays on other variables
Variable X[myinteger] = xxx
Variable Y[myinteger] = xxx
 
Level 12
Joined
Feb 5, 2018
Messages
521
  • X
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Kaboom! (Goblin Sapper)
    • Actions
      • -------- >>>Locals<<< --------
      • -------- Put locals always at the top of the trigger --------
      • Custom script: local unit udg_TempUnit
      • Custom script: local unit udg_TempCaster
      • Custom script: local location udg_TempPoint
      • -------- --------------------------------------------- --------
      • Custom script: set udg_TempCaster = GetTriggerUnit()
      • -------- --------------------------------------------- --------
      • Custom script: set udg_TempPoint = GetUnitLoc(udg_TempCaster)
      • Unit - Create 1 ExplosionEffect for (Owner of TempCaster) at TempPoint facing (Facing of TempCaster) degrees
      • Custom script: set udg_TempUnit = GetLastCreatedUnit()
      • Wait 1.00 seconds
      • Unit - Remove TempUnit from the game
      • -------- ---Increase global integer--- --------
      • Set VariableSet TempInteger = (TempInteger + 1)
      • Special Effect - Create a special effect at TempPoint using Environment\LargeBuildingFire\LargeBuildingFire1.mdl
      • Set VariableSet TestSFX[TempInteger] = (Last created special effect)
      • Wait 2.00 seconds
      • Special Effect - Destroy TestSFX[TempInteger]
      • Set VariableSet TempInteger = (TempInteger - 1)
      • Custom script: call RemoveLocation (udg_TempPoint)
This should work. It just needs a better recycle for the special effect. Other than that it runs smoothly.

If someone could fix the special effect recycle, maybe @Uncle :)
 

Attachments

  • BattleShips.w3m
    17.4 KB · Views: 21

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,594
@DoomBlade
You can use another Integer as a 2nd Index.

You increase the new one Integer after the 2.00 second wait and then use it as the Index for TestSFX.

Then at the end add an If Then Else, "If TempInteger1 = TempInteger2 then set TempInteger1 = 0 and set TempInteger = 2". Note that these two Integers need to be unique and used ONLY for this effect.

Like this:
  • Actions
    • Set VariableSet Int1 = (Int1 + 1)
    • -------- --------
    • Special Effect - Create a special effect at (Center of (Playable map area)) using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
    • Set VariableSet Sfx[Int1] = (Last created special effect)
    • -------- --------
    • Wait 3.00 seconds
    • -------- --------
    • Set VariableSet Int2 = (Int2 + 1)
    • Special Effect - Destroy Sfx[Int2]
    • -------- --------
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • Int1 Equal to Int2
      • Then - Actions
        • Set VariableSet Int1 = 0
        • Set VariableSet Int2 = 0
      • Else - Actions
So if another unit casts the spell during that 3.00 second wait, Int1 will have increased by 1, thus Int2 will not be equal to it once the Wait is over.
 
Level 12
Joined
Feb 5, 2018
Messages
521
  • X
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Kaboom! (Goblin Sapper)
    • Actions
      • -------- >>>Locals<<< --------
      • -------- Put locals always at the top of the trigger --------
      • Custom script: local unit udg_TempUnit
      • Custom script: local unit udg_TempCaster
      • Custom script: local location udg_TempPoint
      • -------- --------------------------------------------- --------
      • Custom script: set udg_TempCaster = GetTriggerUnit()
      • -------- --------------------------------------------- --------
      • Custom script: set udg_TempPoint = GetUnitLoc(udg_TempCaster)
      • Unit - Create 1 ExplosionEffect for (Owner of TempCaster) at TempPoint facing (Facing of TempCaster) degrees
      • Custom script: set udg_TempUnit = GetLastCreatedUnit()
      • Wait 1.00 seconds
      • Unit - Remove TempUnit from the game
      • -------- ---Increase global integer--- --------
      • Set VariableSet TempInteger = (TempInteger + 1)
      • Special Effect - Create a special effect at TempPoint using Environment\LargeBuildingFire\LargeBuildingFire1.mdl
      • Set VariableSet TestSFX[TempInteger] = (Last created special effect)
      • Wait 2.00 seconds
      • Set VariableSet TempInteger2 = (TempInteger2 + 1)
      • Special Effect - Destroy TestSFX[TempInteger2]
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • TempInteger Equal to TempInteger2
        • Then - Actions
          • Set VariableSet TempInteger = 0
          • Set VariableSet TempInteger2 = 0
        • Else - Actions
      • Custom script: call RemoveLocation (udg_TempPoint)
Here is the final trigger and a test map with the final version.
You are welcome. And thanks for help Uncle! :)
 

Attachments

  • BattleShips2.0.w3m
    17.5 KB · Views: 16
Status
Not open for further replies.
Top