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

[Trigger] Make Neutral Hostile Units Spawn when a player unit dies.

Status
Not open for further replies.
Level 2
Joined
Jan 29, 2018
Messages
11
Im trying to make a Trigger that spawns Neutral Hostile units when a players unit dies,

Example : Player 1 (RED) loses a footman to a mob = After 20 seconds the footman respawns but becomes hostile to all players in the game

I manage to do it almost successfully but there is a problem, and thats the Trigger ONLY effects ground units, Air units are not respawning. I need it to work for ANY unit in the game not just ground.

I'm not really experience when it comes to triggers so im learning.

Im sure i didn't do something right, so feel free to correct me where im wrong... =P

Thank You.
 

Attachments

  • Neutral Hostile Respawn 1.png
    Neutral Hostile Respawn 1.png
    139.6 KB · Views: 56
  • Neutral Hostile Respawn 2.png
    Neutral Hostile Respawn 2.png
    139.6 KB · Views: 26

Uncle

Warcraft Moderator
Level 66
Joined
Aug 10, 2018
Messages
6,726
The problem is that Flying Units don't leave behind corpses. This is because in the Object Editor their Death Type is set to: Can't raise, Does not decay.

The "Does not decay" tag is the important part, this means that the unit is "removed" when it dies, which causes problems in your trigger because it no longer exists after you Wait 20.00 seconds.

One possible solution: Change the Death Type of your Flying Unit(s) so that they can Decay. If they Decay then they will not be removed immediately after dying.

That being said, there are still problems in your trigger:
1) You're creating a Location (Point) memory leak when using "Position of triggering unit".
2) You don't need this Action: Change ownership of constructed structure. This does nothing and doesn't make any sense, there is no constructed structure in this Event.
3) You're destroying the Last Created Special Effect after 3.00 seconds. The problem, Last Created Special Effect is always equal to the most recent Special Effect that you've created.
This means that there's a very good chance that the wrong Special Effect will be destroyed since a new Special Effect created before the 3.00 seconds passes will become the new target for destruction.

Here's a triggered solution that will solve all of your problems and NOT require you to edit the unit's Death Type. It's what I would use if I was you:
  • Unit Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Not equal to Neutral Hostile
    • Actions
      • Custom script: local location udg_TempPoint
      • Custom script: local integer TempInteger = GetUnitTypeId(GetTriggerUnit())
      • -------- --------
      • Set VariableSet TempPoint = (Position of (Triggering unit))
      • Wait 20.00 seconds
      • Custom script: set udg_TempUnitType = TempInteger
      • Unit - Create 1 TempUnitType for Neutral Hostile at TempPoint facing Default building facing degrees
      • -------- --------
      • -------- Special Effect: --------
      • Special Effect - Create a special effect attached to the origin of (Last created unit) using Abilities\Spells\Undead\Darksummoning\DarkSummonTarget.mdl
      • Set VariableSet Delayed_Duration = 3.00
      • Trigger - Run Delayed Destroy Effect <gen> (ignoring conditions)
      • -------- --------
      • -------- Clean Up Memory Leaks: --------
      • Custom script: call RemoveLocation (udg_TempPoint)
      • Custom script: set udg_TempPoint = null
This trigger is a useful system (if you can even call it that) that I made. This allows you to destroy a Special Effect after a designated delay. You can see me taking advantage of it in the above trigger.
  • Delayed Destroy Effect
    • Events
    • Conditions
    • Actions
      • Custom script: local effect sfx = GetLastCreatedEffectBJ()
      • Wait Delayed_Duration seconds
      • Custom script: call DestroyEffect(sfx)
      • Custom script: set sfx = null
Variables Used:
TempPoint = Point
TempInteger = Integer
Delayed_Duration = Real

The first trigger takes advantage of something called Shadowing global variables: local udg_
It allows you to take advantage of local variables in GUI without having to use as much Custom script.
Local variables are great because they are always unique and won't get overwritten if you use Waits in your trigger. Each instance of the trigger will have it's own unique set of these local variables, where as global variables are shared among all of your triggers and will have conflicts especially when using Waits since their values will change.
 

Attachments

  • Unit Dies Example 1.w3m
    18.2 KB · Views: 17
Last edited:
Level 2
Joined
Jan 29, 2018
Messages
11
The reason i put Change ownership of constructed structure, Is i wanted to cause structures to respawn as well.
If you played Starcraft 2 there was a modded gamemode called Imbaleauge, That adds lots of Crazy custom features to UMS games. (User Map Settings)
One of those game modes was "Zombies" Units respawn when they die, So that was my inspiration behind playing around with this trigger.

Uncle, i really appreciate your help Thank You.
 

Uncle

Warcraft Moderator
Level 66
Joined
Aug 10, 2018
Messages
6,726
The reason i put Change ownership of constructed structure, Is i wanted to cause structures to respawn as well.
If you played Starcraft 2 there was a modded gamemode called Imbaleauge, That adds lots of Crazy custom features to UMS games. (User Map Settings)
One of those game modes was "Zombies" Units respawn when they die, So that was my inspiration behind playing around with this trigger.

Uncle, i really appreciate your help Thank You.
Constructed structure is an Event Response that only works in response to the Event: "A unit finishes construction". There is no Constructed structure in the Event "A unit dies", so you're referencing nothing.

You can use Triggering Unit to reference the unit, regardless of whether or not it's a structure. You can also use Dying unit, since that is a working Event Response as well.
 
Last edited:
Level 2
Joined
Jan 29, 2018
Messages
11
The problem is that Flying Units don't leave behind corpses. This is because in the Object Editor their Death Type is set to: Can't raise, Does not decay.

The "Does not decay" tag is the important part, this means that the unit is "removed" when it dies, which causes problems in your trigger because it no longer exists after you Wait 20.00 seconds.

One possible solution: Change the Death Type of your Flying Unit(s) so that they can Decay. If they Decay then they will not be removed immediately after dying.

That being said, there are still problems in your trigger:
1) You're creating a Location (Point) memory leak when using "Position of triggering unit".
2) You don't need this Action: Change ownership of constructed structure. This does nothing and doesn't make any sense, there is no constructed structure in this Event.
3) You're destroying the Last Created Special Effect after 3.00 seconds. The problem, Last Created Special Effect is always equal to the most recent Special Effect that you've created.
This means that there's a very good chance that the wrong Special Effect will be destroyed since a new Special Effect created before the 3.00 seconds passes will become the new target for destruction.

Here's a triggered solution that will solve all of your problems and NOT require you to edit the unit's Death Type. It's what I would use if I was you:
  • Unit Dies
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Not equal to Neutral Hostile
    • Actions
      • Custom script: local location udg_TempPoint
      • Custom script: local integer TempInteger = GetUnitTypeId(GetTriggerUnit())
      • -------- --------
      • Set VariableSet TempPoint = (Position of (Triggering unit))
      • Wait 20.00 seconds
      • Custom script: set udg_TempUnitType = TempInteger
      • Unit - Create 1 TempUnitType for Neutral Hostile at TempPoint facing Default building facing degrees
      • -------- --------
      • -------- Special Effect: --------
      • Special Effect - Create a special effect attached to the origin of (Last created unit) using Abilities\Spells\Undead\Darksummoning\DarkSummonTarget.mdl
      • Set VariableSet Delayed_Duration = 3.00
      • Trigger - Run Delayed Destroy Effect <gen> (ignoring conditions)
      • -------- --------
      • -------- Clean Up Memory Leaks: --------
      • Custom script: call RemoveLocation (udg_TempPoint)
      • Custom script: set udg_TempPoint = null
This trigger is a useful system (if you can even call it that) that I made. This allows you to destroy a Special Effect after a designated delay. You can see me taking advantage of it in the above trigger.
  • Delayed Destroy Effect
    • Events
    • Conditions
    • Actions
      • Custom script: local effect sfx = GetLastCreatedEffectBJ()
      • Wait Delayed_Duration seconds
      • Custom script: call DestroyEffect(sfx)
      • Custom script: set sfx = null
Variables Used:
TempPoint = Point
TempInteger = Integer
Delayed_Duration = Real

The first trigger takes advantage of something called Shadowing global variables: local udg_
It allows you to take advantage of local variables in GUI without having to use as much Custom script.
Local variables are great because they are always unique and won't get overwritten if you use Waits in your trigger. Each instance of the trigger will have it's own unique set of these local variables, where as global variables are shared among all of your triggers and will have conflicts especially when using Waits since their values will change.

Very Sorry for my lack of knowledge, But I'm not really familiar with how to use Shadowing global variables, i downloaded the link that you posted and there its a map with all kinds of weird effects and triggers. I know how to use Variables but on a very basic level.
 

Uncle

Warcraft Moderator
Level 66
Joined
Aug 10, 2018
Messages
6,726
That link is more of a tutorial than anything. I never actually bothered downloading the map.

And I'm shadowing the variables in the first trigger I posted above with the first two lines of Custom script.

Shadowing is basically just converting a Global variable into a Local variable. In this case I'm converting 2 Global variables into Local variables. Local variables are useful because their values won't get overwritten if say the trigger runs again.

The problem with Global variables is that they can only be assigned to one thing at a time (not taking Arrays into consideration). If you Set a global variable to something, EVERY trigger referencing it will be affected by this change as well. Locals don't suffer from this problem.
 
Last edited:
Status
Not open for further replies.
Top