HG-Bonfire
New Member
- Reaction score
- 22
Hey! Haven't stopped by here in about 2 years. Well... I need some guidance on a trigger I've been working on.
The trigger can be a bit complex, so I'll try my best to explain. Every second of game time, a trigger finds all villagers on the map, and checks a range of 500 around each peasant to see if any enemy units are in the viewing range. If there is an enemy unit, the peasant is assigned the custom value of 1, meaning it has became alarmed. When this happens, the peasant is assigned to a an array variable Peasants[peasantnumber] and the trigger Peasantsalarmed runs. In Peasantsalarmed, The map finds all guards on the map, Calculates which of the guards is physically closest to the peasant, and assigns the guard to a variable. Then it orders the peasant to move to the guard. The third trigger in this build is Guards. Guards checks every second to see if the distance between the variably stored Peasant and Variably stored Guard is less than or equal to 100 and that the peasant is alarmed (custom value of 1) and that the guard is alarmed (custom value of 2, don't ask me why, I'm not sure). If this condition is met, the Guard and the Peasant go back to where the peasant first saw the enemy, and when they arrive the guard waits for 10 seconds, then returns to his original location.
However, that is not all. One of the Heroes in the game, the General, has an ability with 3 levels that effect the trigger when the peasant meets the guard. Level 1 - The map is pinged to the location where the Peasant last saw the enemy. Level 2 - The area surrounding the location where the peasant saw the enemy is revealed. Both are pretty simple. Level 3 gets trickier. In Level 3, the Trigger for guards, instead of causing the guard to go to the peasant's location, will instead run the trigger Guard Special. In Guard special, the guard is replaced with an Elite Guard for 60 seconds, and control over the guard is given to the player who controls the general. The map is also pinged to the location where the peasant saw the enemy and the map around that spot is revealed. During the Elite Guard time, the peasant will follow the guard. After 60 seconds, the guard reverts to normal and the guard and peasant return to their original location.
All of the stuff above, works fine.
The problem is that I think I made a fundamental error in the trigger. You see, I want this trigger to be able to run multiple times at once with different peasants and guards simultaneously, and tried to code it as such. But I screwed it up pretty bad, and I'm going to have to go back in and try to salvage it into working order. Before I go in, I'd like to get your help. Here's the triggers (Note: These are rough draft, they probably leak, a lot, and are likely inefficient and slow. I'll work on that after I have it working)
All variables are initially 0 or false, with the exception of Distance, which is some arbitrarily large number (think its a billion, maybe)
Peasants
Peasants Alarmed
Guards
Guard Special
Guardtimer (Initially Off)
I'm fairly certain the problem stems from the variable PeasantNumber. It is weaved through the entire program, and it doesn't work at all as I intended.
Anybody feel up to it to sort this mess out?
Edit: Oh and if you really feel generous... could you help me to leak-proof it as well?
The trigger can be a bit complex, so I'll try my best to explain. Every second of game time, a trigger finds all villagers on the map, and checks a range of 500 around each peasant to see if any enemy units are in the viewing range. If there is an enemy unit, the peasant is assigned the custom value of 1, meaning it has became alarmed. When this happens, the peasant is assigned to a an array variable Peasants[peasantnumber] and the trigger Peasantsalarmed runs. In Peasantsalarmed, The map finds all guards on the map, Calculates which of the guards is physically closest to the peasant, and assigns the guard to a variable. Then it orders the peasant to move to the guard. The third trigger in this build is Guards. Guards checks every second to see if the distance between the variably stored Peasant and Variably stored Guard is less than or equal to 100 and that the peasant is alarmed (custom value of 1) and that the guard is alarmed (custom value of 2, don't ask me why, I'm not sure). If this condition is met, the Guard and the Peasant go back to where the peasant first saw the enemy, and when they arrive the guard waits for 10 seconds, then returns to his original location.
However, that is not all. One of the Heroes in the game, the General, has an ability with 3 levels that effect the trigger when the peasant meets the guard. Level 1 - The map is pinged to the location where the Peasant last saw the enemy. Level 2 - The area surrounding the location where the peasant saw the enemy is revealed. Both are pretty simple. Level 3 gets trickier. In Level 3, the Trigger for guards, instead of causing the guard to go to the peasant's location, will instead run the trigger Guard Special. In Guard special, the guard is replaced with an Elite Guard for 60 seconds, and control over the guard is given to the player who controls the general. The map is also pinged to the location where the peasant saw the enemy and the map around that spot is revealed. During the Elite Guard time, the peasant will follow the guard. After 60 seconds, the guard reverts to normal and the guard and peasant return to their original location.
All of the stuff above, works fine.
The problem is that I think I made a fundamental error in the trigger. You see, I want this trigger to be able to run multiple times at once with different peasants and guards simultaneously, and tried to code it as such. But I screwed it up pretty bad, and I'm going to have to go back in and try to salvage it into working order. Before I go in, I'd like to get your help. Here's the triggers (Note: These are rough draft, they probably leak, a lot, and are likely inefficient and slow. I'll work on that after I have it working)
All variables are initially 0 or false, with the exception of Distance, which is some arbitrarily large number (think its a billion, maybe)
Peasants
Code:
Peasants
Events
Time - Every 1.00 seconds of game time
Conditions
Actions
Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Villager (Male))) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units within 1000.00 of (Position of (Picked unit)) matching ((((Owner of (Picked unit)) is an ally of (Owner of (Matching unit))) Equal to False) and (((Matching unit) is alive) Equal to True)))) Greater than 0
(Custom value of (Picked unit)) Equal to 0
Then - Actions
For each (Integer A) from 1 to 20, do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Check[(Integer A)] Equal to False
Then - Actions
Set PeasantNumber = (Integer A)
Set Peasant[PeasantNumber] = (Picked unit)
Set Check[PeasantNumber] = True
Set Spotted[PeasantNumber] = (Position of Peasant[PeasantNumber])
Unit - Set the custom value of Peasant[PeasantNumber] to 1
Trigger - Run Peasants Alarmed <gen> (ignoring conditions)
Skip remaining actions
Else - Actions
Else - Actions
Peasants Alarmed
Code:
Peasants Alarmed
Events
Conditions
Actions
Unit Group - Pick every unit in (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Footman)) and do (Actions)
Loop - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Distance between (Position of Peasant[PeasantNumber]) and (Position of (Picked unit))) Less than Distance
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Custom value of (Picked unit)) Equal to 0
Then - Actions
Set Guard[PeasantNumber] = (Picked unit)
Set Distance = (Distance between (Position of Peasant[PeasantNumber]) and (Position of (Picked unit)))
Else - Actions
Else - Actions
Unit - Set the custom value of Guard[PeasantNumber] to 2
Unit - Order Peasant[PeasantNumber] to Move To (Position of Guard[PeasantNumber])
Set Distance = 1000000.00
Guards
Code:
Guards
Events
Time - Every 1.00 seconds of game time
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Distance between (Position of Guard[PeasantNumber]) and (Position of Peasant[PeasantNumber])) Less than 100.00
(Custom value of Guard[PeasantNumber]) Equal to 2
(Custom value of Peasant[PeasantNumber]) Equal to 1
Then - Actions
Unit - Set the custom value of Guard[PeasantNumber] to 1
Unit - Set the custom value of Peasant[PeasantNumber] to 2
Set GuardSpot[PeasantNumber] = (Position of Guard[PeasantNumber])
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Notification for Notification) Equal to 1
Then - Actions
Game - Display to (All allies of (Owner of Notification)) the text: A peasant has infor...
Cinematic - Ping minimap for (All allies of (Owner of Notification)) at Spotted[PeasantNumber] for 10.00 seconds
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Notification for Notification) Equal to 2
Then - Actions
Game - Display to (All allies of (Owner of Notification)) the text: A peasant has infor...
Cinematic - Ping minimap for (All allies of (Owner of Notification)) at Spotted[PeasantNumber] for 10.00 seconds
Player Group - Pick every player in (All allies of (Owner of Notification)) and do (Actions)
Loop - Actions
Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility from Spotted[PeasantNumber] to a radius of 1000.00
Set Visibility[PeasantNumber] = (Last created visibility modifier)
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Notification for Notification) Equal to 3
Then - Actions
Game - Display to (All allies of (Owner of Notification)) the text: A peasant has infor...
Cinematic - Ping minimap for (All allies of (Owner of Notification)) at Spotted[PeasantNumber] for 10.00 seconds
Player Group - Pick every player in (All allies of (Owner of Notification)) and do (Actions)
Loop - Actions
Visibility - Create an initially Enabled visibility modifier for (Picked player) emitting Visibility from Spotted[PeasantNumber] to a radius of 1000.00
Set Visibility[PeasantNumber] = (Last created visibility modifier)
Trigger - Run Guard Special <gen> (ignoring conditions)
Skip remaining actions
Else - Actions
Unit - Order Guard[PeasantNumber] to Attack-Move To Spotted[PeasantNumber]
Unit - Order Peasant[PeasantNumber] to Move To Spotted[PeasantNumber]
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Region centered at Spotted[PeasantNumber] with size (100.00, 100.00)) contains Guard[PeasantNumber]) Equal to True
(Custom value of Guard[PeasantNumber]) Equal to 1
Then - Actions
Unit - Set the custom value of Guard[PeasantNumber] to 0
Wait 10.00 seconds
Unit - Set the custom value of Peasant[PeasantNumber] to 0
Unit - Order Guard[PeasantNumber] to Attack-Move To GuardSpot[PeasantNumber]
Visibility - Destroy Visibility[PeasantNumber]
Set Check[PeasantNumber] = False
Set Guard[PeasantNumber] = No unit
Set Peasant[PeasantNumber] = No unit
Set PeasantNumber = 0
Else - Actions
Guard Special
Code:
Guard Special
Events
Conditions
Actions
Unit - Replace Guard[PeasantNumber] with a Elite Guard using The new unit's max life and mana
Set Guard[PeasantNumber] = (Last replaced unit)
Unit - Change ownership of Guard[PeasantNumber] to (Owner of Notification) and Retain color
Trigger - Turn on Guardtimer <gen>
Wait until (Guardreset Equal to True), checking every 1.00 seconds
Set Guardreset = False
Unit - Replace Guard[PeasantNumber] with a Footman using The old unit's relative life and mana
Set Guard[PeasantNumber] = (Last replaced unit)
Unit - Change ownership of Guard[PeasantNumber] to Player 5 (Yellow) and Change color
Unit - Set the custom value of Guard[PeasantNumber] to 0
Unit - Set the custom value of Peasant[PeasantNumber] to 0
Unit - Order Guard[PeasantNumber] to Attack-Move To GuardSpot[PeasantNumber]
Unit - Order Peasant[PeasantNumber] to Move To Spotted[PeasantNumber]
Visibility - Destroy Visibility[PeasantNumber]
Set Check[PeasantNumber] = False
Set Guard[PeasantNumber] = No unit
Set Peasant[PeasantNumber] = No unit
Set PeasantNumber = 0
Guardtimer (Initially Off)
Code:
Guardtimer
Events
Time - Every 1.00 seconds of game time
Conditions
Actions
Unit - Order Peasant[PeasantNumber] to Move To (Position of Guard[PeasantNumber])
Set Guardtimer[PeasantNumber] = (Guardtimer[PeasantNumber] + 1)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Guardtimer[PeasantNumber] Greater than or equal to 60
Then - Actions
Set Guardtimer[PeasantNumber] = 0
Set Guardreset = True
Trigger - Turn off (This trigger)
Else - Actions
I'm fairly certain the problem stems from the variable PeasantNumber. It is weaved through the entire program, and it doesn't work at all as I intended.
Anybody feel up to it to sort this mess out?
Edit: Oh and if you really feel generous... could you help me to leak-proof it as well?