Shadow
TH.net Regular
- Reaction score
- 23
I'm making a mini game race where its elimination style (keep racing till your the last one standing). Each player has a certain amount of lives and the race will loop if either of these occur. (Unless there is one racer left standing that is.)
So I have 2 triggers.
- 1 If a player reaches the finish line.
-1 If all players die.
Both kinda do similar things they check to see if there is more then 1 player with at least 1 life.
The 2nd trigger check to see how many lives the
So I sorta got it to work but I am certain that they do leak, and are inefficient. I'll show you them anyways.
Code:
Variable Name Type
Racer Unit Array
Stampeder Unit Array
Randomizer Integer
Player String Array
ScoreBoard Multiboard
End Integer
LapsWon Integer Array
Users_Total Integer
Rank Integer Array
Place Integer Array
RacerGroup Unit Group
Users Integer
TeleportSFX Special Effect Array
Int Integer
Trigger:
- Finish Line
- Events
- Unit - A unit enters FinishLine1 <gen>
- Unit - A unit enters FinishLine2 <gen>
- Unit - A unit enters FinishLine3 <gen>
- Unit - A unit enters FinishLine4 <gen>
- Unit - A unit enters FinishLine5 <gen>
- Unit - A unit enters FinishLine6 <gen>
- Unit - A unit enters FinishLine7 <gen>
- Conditions
- Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- ((Triggering unit) has buff Speed Bonus) Equal to True
- Then - Actions
- For each (Integer A) from 1 to 5, do (Actions)
- Loop - Actions
- Unit - Remove Speed (Neutral Hostile) from Racer[(Integer A)]
- Loop - Actions
- For each (Integer A) from 0 to 3, do (Actions)
- Loop - Actions
- Unit - Remove Speed Stampeder (Neutral Hostile) from Stampeder[(Integer A)]
- Loop - Actions
- For each (Integer A) from 1 to 5, do (Actions)
- Else - Actions
- If - Conditions
- Trigger - Turn off (This trigger)
- Trigger - Turn off Rollers <gen>
- Set Randomizer = (Random integer number between 1 and 10)
- For each (Integer A) from 1 to 5, do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Owner of (Triggering unit)) Equal to (Player((Integer A)))
- Then - Actions
- Game - Display to (All players) for 30.00 seconds the text: (Player[(Integer A)] + ((Name of (Player((Integer A)))) + |r finished first!))
- Set LapsWon[(Integer A)] = (LapsWon[(Integer A)] + 1)
- Multiboard - Set the text for ScoreBoard item in column 3, row ((Integer A) + 1) to (String(LapsWon[(Integer A)]))
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- Sound - Play GoodJob <gen>
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- End Greater than or equal to (Users_Total - 1)
- Then - Actions
- Set Rank[(Player number of (Owner of (Triggering unit)))] = 1
- Set Place[1] = (Owner of (Triggering unit))
- Unit - Remove (Triggering unit) from the game
- Trigger - Run Winner <gen> (checking conditions)
- Else - Actions
- Trigger - Run NextLap <gen> (checking conditions)
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Events
Trigger:
- NextLap
- Events
- Conditions
- Actions
- Wait 5.00 seconds
- Set Int = (Random integer number between 1 and 5)
- For each (Integer A) from 1 to 5, do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Racer[(Integer A)] is alive) Equal to True
- Then - Actions
- Unit - Move Racer[(Integer A)] instantly to RacerLocs[Int], facing 45.00 degrees
- Unit - Pause Racer[(Integer A)]
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Int Equal to 5
- Then - Actions
- Set Int = 1
- Else - Actions
- Set Int = (Int + 1)
- If - Conditions
- Else - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Lives[(Integer A)] Greater than 0
- ((Player((Integer A))) slot status) Equal to Is playing
- Then - Actions
- Unit - Create 1 Racer for (Player((Integer A))) at RacerLocs[(Integer A)] facing 45.00 degrees
- Set Racer[(Integer A)] = (Last created unit)
- Camera - Lock camera target for (Player((Integer A))) to Racer[(Integer A)], offset by (0.00, 0.00) using Default rotation
- Unit Group - Add Racer[(Integer A)] to RacerGroup
- Unit - Pause Racer[(Integer A)]
- Set Lives[(Integer A)] = (Lives[(Integer A)] - 1)
- Multiboard - Set the text for ScoreBoard item in column 2, row ((Integer A) + 1) to (String(Lives[(Integer A)]))
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Int Equal to 5
- Then - Actions
- Set Int = 1
- Else - Actions
- Set Int = (Int + 1)
- If - Conditions
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Or - Any (Conditions) are true
- Conditions
- Randomizer Equal to 1
- Randomizer Equal to 5
- Randomizer Equal to 10
- Conditions
- Or - Any (Conditions) are true
- Then - Actions
- Trigger - Run Speed Round <gen> (checking conditions)
- Else - Actions
- If - Conditions
- Trigger - Add to Race Start <gen> the event (Time - Elapsed game time is 3.00 seconds)
- Trigger - Turn on Rollers <gen>
Trigger:
- All Racers Dead
- Events
- Unit - A unit Dies
- Conditions
- (Unit-type of (Triggering unit)) Equal to Racer
- Actions
- For each (Integer A) from 1 to 5, do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Owner of (Triggering unit)) Equal to (Player((Integer A)))
- Then - Actions
- Set Lives[(Integer A)] = (Lives[(Integer A)] - 1)
- Multiboard - Set the text for ScoreBoard item in column 2, row ((Integer A) + 1) to (String(Lives[(Integer A)]))
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- Camera - Lock camera target for (Owner of (Triggering unit)) to Stampede 0001 <gen>, offset by (0.00, 0.00) using The unit's rotation
- For each (Integer A) from 1 to 5, do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (Owner of (Triggering unit)) Equal to (Player((Integer A)))
- Lives[(Integer A)] Equal to 0
- Then - Actions
- Set End = (End + 1)
- Set Rank[(Integer A)] = Users
- Set Users = (Users - 1)
- Game - Display to (All players) the text: ((String(Rank[(Integer A)])) + Test message)
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- (All units of RacerGroup are dead) Equal to True
- Then - Actions
- Set Int = (Random integer number between 1 and 5)
- For each (Integer A) from 0 to 3, do (Actions)
- Loop - Actions
- Unit - Remove Speed Stampeder (Neutral Hostile) from Stampeder[(Integer A)]
- Special Effect - Create a special effect at (Position of Stampeder[(Integer A)]) using Abilities\Spells\Human\MassTeleport\MassTeleportCaster.mdl
- Set TeleportSFX[(Integer A)] = (Last created special effect)
- Unit - Move Stampeder[(Integer A)] instantly to Stampede[(Integer A)]
- Unit - Hide Stampeder[(Integer A)]
- Trigger - Turn off Rollers <gen>
- Loop - Actions
- Set Randomizer = (Random integer number between 1 and 10)
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- ((Triggering unit) has buff Speed Bonus) Equal to True
- Then - Actions
- For each (Integer A) from 1 to 5, do (Actions)
- Loop - Actions
- Unit - Remove Speed (Neutral Hostile) from Racer[(Integer A)]
- Loop - Actions
- For each (Integer A) from 0 to 3, do (Actions)
- Loop - Actions
- Unit - Remove Speed Stampeder (Neutral Hostile) from Stampeder[(Integer A)]
- Loop - Actions
- For each (Integer A) from 1 to 5, do (Actions)
- Else - Actions
- If - Conditions
- Game - Display to (All players) for 3.00 seconds the text: |cffdc143cAll racer...
- For each (Integer A) from 1 to 5, do (Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Lives[(Integer A)] Greater than 0
- ((Player((Integer A))) slot status) Equal to Is playing
- Then - Actions
- Unit Group - Remove Racer[(Integer A)] from RacerGroup
- Unit - Create 1 Racer for (Player((Integer A))) at RacerLocs[Int] facing 45.00 degrees
- Set Racer[(Integer A)] = (Last created unit)
- Camera - Lock camera target for (Player((Integer A))) to Racer[(Integer A)], offset by (0.00, 0.00) using Default rotation
- Special Effect - Create a special effect attached to the origin of Racer[(Integer A)] using Abilities\Spells\Human\Resurrect\ResurrectTarget.mdl
- Set ReviveSFX[(Integer A)] = (Last created special effect)
- Unit Group - Add Racer[(Integer A)] to RacerGroup
- Unit - Pause Racer[(Integer A)]
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Int Equal to 5
- Then - Actions
- Set Int = 1
- Else - Actions
- Set Int = (Int + 1)
- If - Conditions
- Else - Actions
- Unit Group - Remove Racer[(Integer A)] from RacerGroup
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- Loop - Actions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- Or - Any (Conditions) are true
- Conditions
- Randomizer Equal to 1
- Randomizer Equal to 5
- Randomizer Equal to 10
- Conditions
- Or - Any (Conditions) are true
- Then - Actions
- Trigger - Run Speed Round <gen> (checking conditions)
- Else - Actions
- If - Conditions
- If (All Conditions are True) then do (Then Actions) else do (Else Actions)
- If - Conditions
- End Greater than or equal to (Users_Total - 1)
- Then - Actions
- Game - Display to (All players) the text: ((String(End)) + (>= + (String((Users_Total - 1)))))
- Set Place[1] = (Owner of (Triggering unit))
- Trigger - Run Winner <gen> (checking conditions)
- Else - Actions
- Trigger - Add to Race Start <gen> the event (Time - Elapsed game time is 3.00 seconds)
- Trigger - Turn on Rollers <gen>
- If - Conditions
- Else - Actions
- If - Conditions
- For each (Integer A) from 1 to 5, do (Actions)
- Events
So first, there must be a much more efficient way, I feel like i'm using a hammer to drive a tac. How would you approach this problem? Then I need help identifying leaks and such.
Last edited: