HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Optimizing triggers

06-18-2004, 02:17 PM#1
Faradome
There are some Gestalten in my trigger list that may need a little downsizing and optimizing, if not to increase speed, then just so that I won't get laughed at.

This is for a TD.

Firstly, players quitting. Is there a better way than just

When Player 1 leaves
// update creep hit points, update team 1 playercount, kill all his towers //

When Player 2 leaves
// update creep hit points, update team 1 playercount, kill all his towers //

(...)

When Player 11 leaves
// update creep hit points, update team 2 playercount, kill all his towers //


I haven't found out a way to detect any player leaving - is there?

Secondly, spawning creeps. There are 15 different creeps, and they are randomized, but both teams should get the same creeps. Their strength is modified by giving an [increasing] HP% handicap bonus to Player 6 and Player 12, the two computer players. Additionally, creeps may take off more than 1 penalty point on leaking, depending on their strength.

Set RndNbr = random number from 1 to 15

If RndNbr = 1
Then for A=1 to 10 do
spawn unit MonsterSheep at Team1Spawn for Player 6
order last created unit to go to point Team1FirstCorner
set unit variable of last created unit to 10
spawn unit MonsterSheep at Team2Spawn for Player 12
order last created unit to go to point Team2FirstCorner
set unit variable of last created unit to 10

If RndNbr = 2
Then for A=1 to 20 do
spawn unit Warthog at Team1Spawn for Player 6
order last created unit to go to point Team1FirstCorner
set unit variable of last created unit to 5
spawn unit Warthog at Team2Spawn for Player 12
order last created unit to go to point Team2FirstCorner
set unit variable of last created unit to 5

(...)



Ugh. There has to be a better way. Any suggestions? :)
06-18-2004, 05:08 PM#2
PatruX
For you first question there is an event called "Player - Leaves Game".
06-18-2004, 05:39 PM#3
Panto
Patrux, that event is what he's using; it's player-specific. What he's doing is probably the simplest effective method, but alternatively one could add "Player Leaves" events to the trigger with another trigger that detects what players are in the game.

As far as the second method, I would set all of your creeps into a unit-type array, where the index of the creep is equal to the round number that he spawns in. That way, you can make just one set of actions and spawn unittypeArrayCreep[RndNbr].
06-18-2004, 10:49 PM#4
R3N3G4D3
1. You can put all events in one trigger, because events work as "OR", not "AND". Then for actions use triggering player.

2. First of all, use arrays like panto said, except that RndNbr is number of creeps, not level number. So you have some other variable for levels like i (unittypeArrayCreep[i]). And for number of creeps spawning do this:
get your RndNbr, then do:

Then for A=1 to (RndNbr)x10 do
spawn unit unittypeArrayCreep[i] at Team1Spawn for Player 6
order last created unit to go to point Team1FirstCorner
set unit variable of last created unit to 10
spawn unit unittypeArrayCreep[i] at Team2Spawn for Player 12
order last created unit to go to point Team2FirstCorner
set unit variable of last created unit to 10

I'm not sure exactly what your unit variable is for so I left it unchanged.
06-18-2004, 11:22 PM#5
Milkman
Or you use a periodic event on 2 seconds that fires a bunch of condition check triggers that do what you want. It's not laggy, in my experience that is. Blizzard even used it.