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

Add condition to respawn trigger

Status
Not open for further replies.
Level 7
Joined
May 30, 2018
Messages
290
Hey hey :)

Can somebody help me with following trigger:

  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to |cff000080Water Conjurer|r
          • (Unit-type of (Triggering unit)) Equal to |cff008000Nature Conjurer|r
          • (Unit-type of (Triggering unit)) Equal to |cffff0000Fire Conjurer|r
    • Actions
      • Game - Display to (All players) the text: A Conjurer has died...
      • Set VariableSet RespawnLocation = (Position of (Triggering unit))
      • Wait 25.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Triggering player) at RespawnLocation facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_RespawnLocation)
How/in which way I could add a condition that checks if the town hall-building of the player is alive, before he is allowed to respawn. In other words: if a players town hall died, he shouldnt be able to respawn anymore.
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
maybe this will do the trick:
  • (All units of (Units owned by (Triggering player) matching (((Triggering unit) is A town-hall-type unit) Equal to True)) are dead) Equal to True
there is probably a more straightforward way to do it...
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,512
You should use Owner of Triggering Unit not Triggering Player.

And RespawnLocation can change during that 25.00 second Wait so the trigger will break if another one of those unit-types dies during this waiting period.

EnderWiggins suggestion could work but remember to use Matching unit when using the Matching function. "Matching unit is a Town-hall-type" not "Triggering unit".

I'd personally keep track of the Town Hall unit(s) with an Integer or Unit Group as they're created/destroyed so you can always reference this value.

Condition could look like: TownHallCount[player number of triggering player] greater than 0

If you only have and will only have 1 Town Hall at a time, then you can save it as a Unit variable and reference it instead. TownHallUnit[player number of triggering player] is Alive = True.
 
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
You should use Owner of Triggering Unit not Triggering Player.

And RespawnLocation can change during that 25.00 second Wait so the trigger will break if another one of those unit-types dies during this waiting period.

EnderWiggins suggestion could work but remember to use Matching unit when using the Matching function. "Matching unit is a Town-hall-type" not "Triggering unit".

I'd personally keep track of the Town Hall unit(s) with an Integer or Unit Group as they're created/destroyed so you can always reference this value.

Condition could look like: TownHallCount[player number of triggering player] greater than 0

If you only have and will only have 1 Town Hall at a time, then you can save it as a Unit variable and reference it instead. TownHallUnit[player number of triggering player] is Alive = True.

I tried your approach, but Iam not entirely sure, if iam on the correct path.

  • Test
    • Events
      • Unit - A unit Finishes construction
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Conjurer Librum
    • Actions
      • Set VariableSet TownHallCount = ((Number of living Conjurer Librum units owned by (Owner of (Triggering unit))) + 1)
  • Test Copy
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to Conjurer Librum
    • Actions
      • Set VariableSet TownHallCount = ((Number of living Conjurer Librum units owned by (Owner of (Triggering unit))) - 1)
  • Respawn
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to |cff00ffffWater Conjurer|r
          • (Unit-type of (Triggering unit)) Equal to |cff008000Nature Conjurer|r
          • (Unit-type of (Triggering unit)) Equal to |cffff0000Fire Conjurer|r
      • And - All (Conditions) are true
        • Conditions
          • TownHallCount Greater than 0
    • Actions
      • Game - Display to (All players) the text: A Conjurer has died...
      • Set VariableSet RespawnLocation = (Position of (Triggering unit))
      • Wait 25.00 seconds
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Triggering player) at RespawnLocation facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_RespawnLocation)
Not sure, what I did wrong :s
 
Level 7
Joined
May 30, 2018
Messages
290
maybe this will do the trick:
  • (All units of (Units owned by (Triggering player) matching (((Triggering unit) is A town-hall-type unit) Equal to True)) are dead) Equal to True
there is probably a more straightforward way to do it...

Thanks, Ill try that :)!

I just implemented your suggestion, but shouldn't the last part be "Equal to False" not "true" ? Since I want the players to not be able to respawn when they dont have this building.
 
Last edited:

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,512
((Number of living Conjurer Librum units owned by (Owner of (Triggering unit))) + 1) = The number of Town Halls + 1, so it'll always be 1 more than you have. Then when you subtract you're subtracting down into the negatives (total + 1).

You want to do:
  • Set TownHallCount = TownHallCount + 1
And:
  • Set TownHallCount = TownHallCount - 1
Also, you don't need that AND in your conditions. Conditions by default are And.
 
Level 7
Joined
May 30, 2018
Messages
290
You should use Owner of Triggering Unit not Triggering Player.

And RespawnLocation can change during that 25.00 second Wait so the trigger will break if another one of those unit-types dies during this waiting period.

EnderWiggins suggestion could work but remember to use Matching unit when using the Matching function. "Matching unit is a Town-hall-type" not "Triggering unit".

I'd personally keep track of the Town Hall unit(s) with an Integer or Unit Group as they're created/destroyed so you can always reference this value.

Condition could look like: TownHallCount[player number of triggering player] greater than 0

If you only have and will only have 1 Town Hall at a time, then you can save it as a Unit variable and reference it instead. TownHallUnit[player number of triggering player] is Alive = True.

+ what would be a good way to fix the RespawnLocation problem?
 
Level 21
Joined
Mar 29, 2020
Messages
1,237
Thanks, Ill try that :)!

I just implemented your suggestion, but shouldn't the last part be "Equal to False" not "true" ? Since I want the players to not be able to respawn when they dont have this building.

yep. and note Uncle's comment on me accidentally leaving it (triggering unit) instead of (matching unit.). and then delete that and just do what uncle said bc it's probably 10 times better:grin:
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,512
Your method is fine too Wiggins, except that it might count Town Halls that are still under construction, which might be undesirable. I just prefer having more control over these things.

Here's some trigger examples of how you can make the respawn work. The unit-type conditions are missing/incorrect but I don't have access to the units in your map so I just chose random units:
  • add
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Set VariableSet TownHallCount[(Player number of (Triggering player))] = (TownHallCount[(Player number of (Triggering player))] + 1)
  • subtract
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set VariableSet TownHallCount[(Player number of (Triggering player))] = (TownHallCount[(Player number of (Triggering player))] - 1)
This one is basically your original trigger but the Point is set after the Wait which prevents the issues I described before.
  • respawn simple
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
          • (Unit-type of (Triggering unit)) Equal to Knight
          • (Unit-type of (Triggering unit)) Equal to Rifleman
      • TownHallCount[(Player number of (Triggering player))] Greater than 0
    • Actions
      • Wait 25.00 seconds
      • Set VariableSet TempPoint = (Position of (Triggering unit))
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Owner of (Triggering unit)) at TempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_TempPoint)
This one is done with mostly custom script (Jass). Hard to understand but basically I declare a few local variables, pl = Triggering Player, loc = Position of Triggering unit, and ut = Unit-Type of Triggering unit. Then after a 25.00 second Wait I run the function CreateUnitAtLoc(). This function needs to be filled out like so: CreateUnitAtLoc(player, unittype, location, angle)

So I plug in the variables I created earlier (pl, loc, ut) into this function and it creates the correct unit (270 = It's facing angle). I then clean up the Leaks at the bottom by removing the Location and "nulling" pl and loc (certain types of local variables need to be nulled in Jass to prevent leaks).
  • respawn advanced
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
          • (Unit-type of (Triggering unit)) Equal to Knight
          • (Unit-type of (Triggering unit)) Equal to Rifleman
      • TownHallCount[(Player number of (Triggering player))] Greater than 0
    • Actions
      • Custom script: local player pl = GetTriggerPlayer()
      • Custom script: local location loc = GetUnitLoc(GetTriggerUnit())
      • Custom script: local integer ut = GetUnitTypeId(GetTriggerUnit())
      • Wait 25.00 seconds
      • Custom script: call CreateUnitAtLoc(pl, ut, loc, 270)
      • Custom script: call RemoveLocation (loc)
      • Custom script: set pl = null
      • Custom script: set loc = null
The advanced respawn trigger is nice because it doesn't suffer from any rare but potential issues. It's probably not necessary though, so you can use the simple one if you'd like.
 
Last edited:
Level 7
Joined
May 30, 2018
Messages
290
Your method is fine too Wiggins, except that it might count Town Halls that are still in construction, which might be undesired. I just prefer having more control over these things.

Here's some trigger examples of how you can make the respawn work. The unit-type conditions are missing/incorrect but I don't have access to the units in your map so I just chose random units:
  • add
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Set VariableSet TownHallCount[(Player number of (Triggering player))] = (TownHallCount[(Player number of (Triggering player))] + 1)
  • subtract
    • Events
      • Unit - A unit Dies
    • Conditions
    • Actions
      • Set VariableSet TownHallCount[(Player number of (Triggering player))] = (TownHallCount[(Player number of (Triggering player))] - 1)
This one is basically your original trigger but the Point is set after the Wait which prevents the issues I described before.
  • respawn simple
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
          • (Unit-type of (Triggering unit)) Equal to Knight
          • (Unit-type of (Triggering unit)) Equal to Rifleman
      • TownHallCount[(Player number of (Triggering player))] Greater than 0
    • Actions
      • Wait 25.00 seconds
      • Set VariableSet TempPoint = (Position of (Triggering unit))
      • Unit - Create 1 (Unit-type of (Triggering unit)) for (Owner of (Triggering unit)) at TempPoint facing Default building facing degrees
      • Custom script: call RemoveLocation(udg_TempPoint)
This one is done with mostly custom script (Jass). Hard to understand but basically I declare a few local variables, pl = Triggering Player, loc = Position of Triggering unit, and ut = Unit-Type of Triggering unit. Then after a 25.00 second Wait I run the function CreateUnitAtLoc(). This function needs to be filled out like so: CreateUnitAtLoc(player, unittype, location, angle)

So I plug in the variables I created earlier (pl, loc, ut) into this function and it creates the correct unit (270 = It's facing angle). I then clean up the Leaks at the bottom by removing the Location and "nulling" pl and loc (certain types of local variables need to be nulled in Jass to prevent leaks).
  • respawn advanced
    • Events
      • Unit - A unit Dies
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to Footman
          • (Unit-type of (Triggering unit)) Equal to Knight
          • (Unit-type of (Triggering unit)) Equal to Rifleman
      • TownHallCount[(Player number of (Triggering player))] Greater than 0
    • Actions
      • Custom script: local player pl = GetTriggerPlayer()
      • Custom script: local location loc = GetUnitLoc(GetTriggerUnit())
      • Custom script: local integer ut = GetUnitTypeId(GetTriggerUnit())
      • Wait 25.00 seconds
      • Custom script: call CreateUnitAtLoc(pl, ut, loc, 270)
      • Custom script: call RemoveLocation (loc)
      • Custom script: set pl = null
      • Custom script: set loc = null
The advanced respawn trigger is nice because it doesn't suffer from any rare but potential issues. It's probably not necessary though, so you can use the simple one if you'd like.


Thank you for your efforts @Uncle and you too @Ender Wiggins , you helped me out a lot!!!
 
Status
Not open for further replies.
Top