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

Spawning trigger assistance

Status
Not open for further replies.
Level 4
Joined
Jan 17, 2018
Messages
112
Hi all,

I'm fiddling around with the spawning of units and made the following script that makes sense to me but doesn't work :S

Code:
Events
- Unit - A unit enters Region 024 <gen>
- Time - Every 2.00 Seconds of game time
Conditions
- ((Triggering unit) is A ground unit) Equal to ((Triggering unit) is in (Random 2 units from (Units in (Playable map area))))
Actions
Unit - Create 1 Redeemer for (Owner of (Triggering unit)) at (((Owner of (Triggering unit)) start location) offset by (0.00, 0.00)) facing Default  building facing degrees

What I'd like the code to do is: You must have 2 units standing in the region to spawn an unit called Redeemer every 2 seconds until you remove the units from the region.

Edit: How do I move this script myself to the right section?
 
Last edited:
Your Trigger has mixed up many informations in one, therefore should not be solve in one trigger.

Inside the Event " Time - Every 2.00 Seconds of game time" triggering Unit is not set (aka no unit) and therefore can not be a ground unit nor it can be part of units of units in playable map.

Splitup the task in multiple triggers so each becomes more simple, you could do a logic flow like below:
  1. Enter the region
  2. Leave region
  3. death (while in region)
  4. spawning the redeemer, with the 2 seconds timer.

How To Post Your Trigger
 
Level 4
Joined
Jan 17, 2018
Messages
112
  • Redeemer
    • Events
      • Unit - A unit enters Region 024 <gen>
    • Conditions
      • (Number of units in (Units in Region 024 <gen>)) Equal to 2
    • Actions
      • Unit - Create 1 Redeemer for (Owner of (Triggering unit)) at (((Owner of (Triggering unit)) start location) offset by (0.00, 0.00)) facing Default building facing degrees
      • For each (Integer A) from 1 to 1000, do (Actions)
        • Loop - Actions
          • Unit - Create 1 Redeemer for (Owner of (Triggering unit)) at ((Owner of (Triggering unit)) start location) facing (Random point in (Playable map area))
          • Wait 4.00 seconds
          • Trigger - Run (This trigger) (checking conditions)
I know you're not suppose to use wait, but I can't find "set time delay" as recommended.
With this script, it spawns a unit every 4 seconds, but I must let 1 unit at a time enter the region, how do I fix this so that I can just select 2 units and let them run into the region triggering the script?
 
Level 4
Joined
Jan 17, 2018
Messages
112
You do not need that loop.
When the event "enters region" fires the entering unit is not yet inside the region.
Easy Fix is place a little bit bigger region at the same spot and check units inside that bigger region, but use the enter region from the smaller one.

I have 100 units like the above, would this still be the easy fix? Or is there perhaps a different trigger I can copy paste for all 100?
 
That is for units, then don't use regions at all, base it on units. make a group of all control Points.
Every x seconds of gametime change ownership of the point.
Every y seconds of gametime spawn a redeemer for its current owner.

  • Redeem trigger
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • -------- Change ownership every second --------
      • Unit Group - Pick every unit in RedeemGroup and do (Actions)
        • Loop - Actions
          • Set Loc = (Position of (Picked unit))
          • Set Max = 0
          • Set Player = Neutral Passive
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Group = (Units within 300.00 of Loc matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is A structure) Equal to False) and ((Owner of (Matching unit)) Equal to (Picked player)))))
              • Unit Group - Remove (Picked unit) from Group
              • Custom script: set bj_wantDestroyGroup = true
              • Set Count = (Number of units in Group)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count Greater than Max
                • Then - Actions
                  • Set Max = Count
                  • Set Player = (Picked player)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_Loc)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Max Greater than or equal to 2
            • Then - Actions
              • Unit - Change ownership of (Picked unit) to Player and Change color
            • Else - Actions
              • Unit - Change ownership of (Picked unit) to Neutral Passive and Change color
      • -------- Every 4 seconds of gametime spawn a unit for the current owner of each point. --------
      • -------- Could be done inside anouther trigger with every 4 seconds but you might encounter execution order problems. --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Execution count of (This trigger)) Equal to 4
        • Then - Actions
          • Unit Group - Pick every unit in RedeemGroup and do (Actions)
            • Loop - Actions
              • Set Player = (Owner of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Player Not equal to Neutral Passive
                • Then - Actions
                  • Set Loc = (Player start location)
                  • Unit - Create 1 Soldat for Player at Loc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_Loc)
                • Else - Actions
          • Custom script: call ResetTrigger( GetTriggeringTrigger() )
        • Else - Actions
  • Redeem Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Add all Units spawning this redeemers to a group --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Circle der Macht)) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to RedeemGroup
 

Attachments

  • Redeemer.w3x
    18.5 KB · Views: 36
Last edited:
Level 4
Joined
Jan 17, 2018
Messages
112
That is for units, then don't use regions at all, base it on units. make a group of all control Points.
Every x seconds of gametime change ownership of the point.
Every y seconds of gametime spawn a redeemer for its current owner.

  • Redeem trigger
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • -------- Change ownership every second --------
      • Unit Group - Pick every unit in RedeemGroup and do (Actions)
        • Loop - Actions
          • Set Loc = (Position of (Picked unit))
          • Set Max = 0
          • Set Player = Neutral Passive
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Group = (Units within 300.00 of Loc matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is A structure) Equal to False) and ((Owner of (Matching unit)) Equal to (Picked player)))))
              • Unit Group - Remove (Picked unit) from Group
              • Custom script: set bj_wantDestroyGroup = true
              • Set Count = (Number of units in Group)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count Greater than Max
                • Then - Actions
                  • Set Max = Count
                  • Set Player = (Picked player)
                • Else - Actions
          • Custom script: call RemoveLocation(udg_Loc)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Max Greater than or equal to 2
            • Then - Actions
              • Unit - Change ownership of (Picked unit) to Player and Change color
            • Else - Actions
              • Unit - Change ownership of (Picked unit) to Neutral Passive and Change color
      • -------- Every 4 seconds of gametime spawn a unit for the current owner of each point. --------
      • -------- Could be done inside anouther trigger with every 4 seconds but you might encounter execution order problems. --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Execution count of (This trigger)) Equal to 4
        • Then - Actions
          • Unit Group - Pick every unit in RedeemGroup and do (Actions)
            • Loop - Actions
              • Set Player = (Owner of (Picked unit))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Player Not equal to Neutral Passive
                • Then - Actions
                  • Set Loc = (Player start location)
                  • Unit - Create 1 Soldat for Player at Loc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_Loc)
                • Else - Actions
          • Custom script: call ResetTrigger( GetTriggeringTrigger() )
        • Else - Actions
  • Redeem Init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- Add all Units spawning this redeemers to a group --------
      • Custom script: set bj_wantDestroyGroup = true
      • Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Circle der Macht)) and do (Actions)
        • Loop - Actions
          • Unit Group - Add (Picked unit) to RedeemGroup

Wow, thanks for the huge effort. +2 rep. I'll check out the script tonight.
 
Level 4
Joined
Jan 17, 2018
Messages
112
T[/Trigger]

Hey, thanks again for the script. After 2 weeks I could finally check it out. I see the script checks who currently owns the circle of power, but I have 1 area that all players use to spawn units in the battle field. Is there a quick fix to the script that can be done? As I see the whole script is focused on ownership of the area, a quick brainstorm is to add 8 circle of powers (total number of players) to each region that spawns units?
 
Level 4
Joined
Jan 17, 2018
Messages
112
  • Redeem trigger
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RedeemGroup and do (Actions)
        • Loop - Actions
          • Set Loc = (Position of (Picked unit))
          • Set Max = 0
          • Set Player = Neutral Passive
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Group = (Units within 300.00 of Loc matching ((((Matching unit) is alive) Equal to True) and ((((Matching unit) is A structure) Equal to False) and ((Owner of (Matching unit)) Equal to (Picked player)))))
              • Unit Group - Remove (Picked unit) from Group
              • Custom script: set bj_wantDestroyGroup = true
              • Set Count = (Number of units in Group)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count Greater than Max
                • Then - Actions
                  • Set Max = Count
                  • Set Player = (Owner of (triggering unit))
                • Else - Actions
          • Custom script: call RemoveLocation(udg_Loc)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Max Greater than or equal to 2
              • Player Not equal to Neutral Passive
              • (Execution count of (This trigger)) Equal to 4
            • Then - Actions
              • Set Loc = (Player start location)
              • Unit - Create 1 Footman for Player at Loc facing Default building facing degrees
              • Custom script: call RemoveLocation(udg_Loc)
            • Else - Actions
              • Custom script: call ResetTrigger( GetTriggeringTrigger() )
This is my failed attempt at making the script work as I would like. Can anyone please assist in making it so that if any amount of players match the condition on one circle of power, it will spawn an unit at their starting location?
 
Well i missunderstood you last time as you want all players be able to use 1 point at the same time.

this should do the trick, Spawns 1 Unit for each Point for each player having atleast 2 units nearby.
  • Redeem trigger
    • Events
      • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RedeemGroup and do (Actions)
        • Loop - Actions
          • -------- Reset Counter for all Players --------
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Count[(Player number of (Picked player))] = 0
          • -------- Get Units around --------
          • Set Loc = (Position of (Picked unit))
          • Set Group = (Units within 240.00 of Loc matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) is A ground unit) Equal to True)))
          • -------- Remove the location object --------
          • Custom script: call RemoveLocation(udg_Loc)
          • -------- Exclude the circle from beeing counted --------
          • Unit Group - Remove (Picked unit) from Group
          • -------- autodestroy the temp group --------
          • Custom script: set bj_wantDestroyGroup = true
          • -------- count up for each player the amount of units they have around --------
          • Unit Group - Pick every unit in Group and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Owner of (Picked unit)))
              • Set Count[Index] = (Count[Index] + 1)
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Picked player))
              • -------- this player has at least 2 units in the group. --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Greater than or equal to 2
                • Then - Actions
                  • Set Loc = (Player start location)
                  • Unit - Create 1 Soldat for (Picked player) at Loc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_Loc)
                • Else - Actions
 
Level 4
Joined
Jan 17, 2018
Messages
112
Well i missunderstood you last time as you want all players be able to use 1 point at the same time.

this should do the trick, Spawns 1 Unit for each Point for each player having atleast 2 units nearby.
  • Redeem trigger
    • Events
      • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RedeemGroup and do (Actions)
        • Loop - Actions
          • -------- Reset Counter for all Players --------
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Count[(Player number of (Picked player))] = 0
          • -------- Get Units around --------
          • Set Loc = (Position of (Picked unit))
          • Set Group = (Units within 240.00 of Loc matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) is A ground unit) Equal to True)))
          • -------- Remove the location object --------
          • Custom script: call RemoveLocation(udg_Loc)
          • -------- Exclude the circle from beeing counted --------
          • Unit Group - Remove (Picked unit) from Group
          • -------- autodestroy the temp group --------
          • Custom script: set bj_wantDestroyGroup = true
          • -------- count up for each player the amount of units they have around --------
          • Unit Group - Pick every unit in Group and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Owner of (Picked unit)))
              • Set Count[Index] = (Count[Index] + 1)
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Picked player))
              • -------- this player has at least 2 units in the group. --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Greater than or equal to 2
                • Then - Actions
                  • Set Loc = (Player start location)
                  • Unit - Create 1 Soldat for (Picked player) at Loc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_Loc)
                • Else - Actions

Yea, I've learned posting around these parts that my posts aren't clear :D. Thanks for fixing it, gonna give it a try in a bit.
 
Level 4
Joined
Jan 17, 2018
Messages
112
I've entered your script exactly as is but it's not working, makes me think I probably declared by variables incorrectly.
My count is an Integer array
Group - Unit group
Index - Integer
Loc - Point
RedeemGroup - Unit Group
 
Level 4
Joined
Jan 17, 2018
Messages
112
Not working
it does not spawn units?
or error when writing?​

i made a small misstake:
Set Loc = (Player start location)
-> Set Loc = ((Picked Player) start location)​
The variable types are correct.

you filled the redeemGroup?
And if yes how you filled it.

I used the same Redeemgroup as your third post here.

The unit doesn't spawn at all. I tried with 2 players standing on it and also as 1 player. Will try it with your Loc adjustment.
 
Level 4
Joined
Jan 17, 2018
Messages
112
I've spent 5 minutes making sure I match your script line for line and there is no unit being spawned, perhaps my eye is off as I've fixed a few mistakes I made from the first time I thought I matched it line for line. Please check that I entered it exactly as you have to make sure I did it right:
  • Redeem trigger
    • Events
      • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RedeemGroup and do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Count[(Player number of (Picked player))] = 0
          • Set Loc = (Position of (Picked unit))
          • Set Group = (Units within 300.00 of Loc matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) is A ground unit) Equal to True)))
          • Custom script: call RemoveLocation(udg_Loc)
          • Unit Group - Remove (Picked unit) from Group
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in Group and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Owner of (Picked unit)))
              • Set Count[Index] = Count[(Index + 1)]
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Picked player))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Greater than or equal to 2
                • Then - Actions
                  • Set Loc = ((Picked player) start location)
                  • Unit - Create 1 Footman for (Picked player) at Loc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_Loc)
                • Else - Actions
 
Level 4
Joined
Jan 17, 2018
Messages
112
Set Count[Index] = Count[(Index + 1)]
^^ wrong. Currently sets the counter to match the counter of the next player.
->
But you wana count units up, Therefore the next line is right.
set Count[Index] = Count[Index] + 1

Motherf. Need to be so precise. It seems to work, I assume it only works for players so I can't test it 100% yet, thanks a lot, this component is 90% of my map. Hehe
 
Level 4
Joined
Jan 17, 2018
Messages
112
Plugged in my laptop and both players spawned units. Thanks a lot, hopefully I'm not too lazy and post the map in say 3 weeks.
 
Level 4
Joined
Jan 17, 2018
Messages
112
Set Count[Index] = Count[(Index + 1)]
^^ wrong. Currently sets the counter to match the counter of the next player.
->
But you wana count units up, Therefore the next line is right.
set Count[Index] = Count[Index] + 1

Hi again. I would just like to find out, how would I go about modifying this trigger so that each player can have a limited amount of the unit? I've implemented the trigger on many units, but I'd like one of my units to be limited per player.
 
Level 15
Joined
Jul 9, 2008
Messages
1,552
Add a unit group Varable and check how manny units are in it before creating the units

  • Redeem trigger
    • Events
      • Time - Every 4.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in RedeemGroup and do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Count[(Player number of (Picked player))] = 0
          • Set Loc = (Position of (Picked unit))
          • Set Group = (Units within 300.00 of Loc matching ((((Matching unit) is alive) Equal to True) and (((Matching unit) is A ground unit) Equal to True)))
          • Custom script: call RemoveLocation(udg_Loc)
          • Unit Group - Remove (Picked unit) from Group
          • Custom script: set bj_wantDestroyGroup = true
          • Unit Group - Pick every unit in Group and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Owner of (Picked unit)))
              • Set Count[Index] = Count[(Index + 1)]
          • Player Group - Pick every player in (All players) and do (Actions)
            • Loop - Actions
              • Set Index = (Player number of (Picked player))
              • Set CountGroup = (Units in (Playable map area) matching (((Owner of (Matching unit)) Equal to (Picked player)) and ((Unit-type of (Matching unit)) Equal to Footman)))
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Count[Index] Greater than or equal to 2
                  • (Number of units in CountGroup) Greater than or equal to 20(How ever manny u want the limit)
                • Then - Actions
                  • Set Loc = ((Picked player) start location)
                  • Unit - Create 1 Footman for (Picked player) at Loc facing Default building facing degrees
                  • Custom script: call RemoveLocation(udg_Loc)
                • Else - Actions
              • Custom script: DestroyGroup(udg_CountGroup)
 
Status
Not open for further replies.
Top