HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Efficient Victory/Defeat Trigger

12-09-2007, 12:40 AM#1
WNxCryptic
What would be the best way to write a defeat/victory trigger for 3 different forces of 3 players (3v3v3)..

Each player has 1 hero, and the defeat conditions are that all 3 heroes of the same team are dead (while there's at least 1 alive, there's a chance that the other players can revive their heroes).

Victory conditions are that the other two teams' heroes are all dead.

I can't figure out a way to write this in a single trigger...I definately don't want to have a BUNCH of triggers that all run anytime a player leaves/hero dies to check the conditions mentioned above..

And no, the heroes are not in any global unit variables. (so checking if udg_hero1 is dead and udg_hero2 is dead and udg_hero3 is dead, and so on, is out of the question.)
12-09-2007, 01:43 AM#2
Deaod
Warning, Pseudo Code:

Trigger 1:
Event: Hero is created
Actions:
Store each hero into a global var //(if you havent done that already)


Trigger 2:
Event: Player Leaves
Actions:
Kill his hero
Set CanReviveHeroOfPlayer[...] to false

Trigger 3:
Event: Every 10 Seconds
Actions:
Loop through every Player of Force 1 and check if his hero is still alive
____If every hero is dead defeat that team
________Set IsForce1Defeated to true

Loop through every Player of Force 2 and check if his hero is still alive
____If every hero is dead defeat that team
________Set IsForce2Defeated to true

Loop through every Player of Force 3 and check if his hero is still alive
____If every hero is dead defeat that team
________Set IsForce3Defeated to true

If IsForce2Defeated equals true and IsForce3Defeated equals true then end game with victory for Force 1

If IsForce1Defeated equals true and IsForce3Defeated equals true then end game with victory for Force 2

If IsForce1Defeated equals true and IsForce2Defeated equals true then end game with victory for Force 3

End of Pseudo Code

Hope I could help.

Deaod
12-09-2007, 03:46 AM#3
WNxCryptic
Thanks for the help, however:

Quote:
And no, the heroes are not in any global unit variables. (so checking if udg_hero1 is dead and udg_hero2 is dead and udg_hero3 is dead, and so on, is out of the question.)

I'm not using global variables, and periodically checking the defeat conditions is inefficient, although I appreciate the help..I'll probably just go through and write some mini-functions and condense it..oh well.

Thanks for your help though.
12-09-2007, 06:17 AM#4
Strilanc
Periodically checking is the only way to be sure. Do you really want people to be stuck in the game because the victory trigger failed to fire? Checking if 12 heroes are alive every 10 seconds isn't going to lag.
12-09-2007, 06:30 AM#5
darkwulfv
You're making it hard for yourself and others by not assigning the heroes to global variables.

What is really wrong with that? If you think it's gonna lag, it won't; my map checks for 10 heroes every second with no lag at all.
12-09-2007, 07:59 AM#6
grim001
"I'm not using global variables" is like saying "I'm not using local variables"
12-09-2007, 10:40 AM#7
cheekyvimto
I've not been doing this for very long atall really, so I understand if my answer is skipped, but it makes sense to me, from what I have learnt over the past week to assign all heros for each team into their own team variable.

Trigger:
Map Initialisation
Collapse Events
Map initialization
Conditions
Collapse Actions
-------- Creating Force 1 --------
Player Group - Add Player 1 (Red) to Force1
Player Group - Add Player 2 (Blue) to Force1
Player Group - Add Player 3 (Teal) to Force1
-------- Creating Force 2 --------
Player Group - Add Player 4 (Purple) to Force2
Player Group - Add Player 5 (Yellow) to Force2
Player Group - Add Player 6 (Orange) to Force2
-------- Creating Force 3 --------
Player Group - Add Player 7 (Green) to Force3
Player Group - Add Player 8 (Pink) to Force3
Player Group - Add Player 9 (Grey) to Force3

Then To check for the Defeat conditions for the team first you need to know how many players are still alive.

Trigger:
Remove Player from Force
Collapse Events
Unit - A unit Dies
Collapse Conditions
((Triggering unit) is A Hero) Equal to True
Collapse Actions
Collapse -------- Check for Player 1 --------
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Owner of (Triggering unit)) Equal to Player 1 (Red)
(Unit-type of (Triggering unit)) Equal to Player1Hero
Collapse Then - Actions
Player Group - Remove Player 1 (Red) from Force1
Collapse Else - Actions
Do Nothing
-------- Check for Player 2 etc etc etc --------

That would remove players from Force[X], but on Hero Revive you would want to add the players back into the correct force. I would imagine the trigger would be similar to that above, but you would use
Trigger:
Player Group - Add Player 1 (Red) to Force1

Then to check for team defeats, you could use something like what Silvenon suggested for me, yesterday.

Trigger:
Collapse Team Defeat - Force 1
Collapse Events
Unit - A unit dies
Collapse
Collapse Conditions
Number of players in Force1 is Equal to (or less than) 0
Collapse
Collapse Actions
Custom script: call DestroyTrigger(GetTriggeringTrigger())
Game - Display defeat to <that team, Force[1]>


Makes sense to me anyhow.

Sorry if this isn't what your looking for, but I find the best way to learn is to try explain it to others.

/cheeky
12-09-2007, 04:13 PM#8
darkwulfv
He doesn't want to use globals of any kind, which pretty much halts your method.


If he'd use damn globals this could be done in an instant.
12-09-2007, 04:52 PM#9
WNxCryptic
Yea, the concept of globalizing the heroes into an array is simple and that code could be pretty easily written, although I appreciate your help.

I'm just looking for a method to correctly evaluate the victory/defeat conditions without those globals.
12-09-2007, 06:51 PM#10
darkwulfv
It's near impossible without overcomplicating it. Sorry.
12-09-2007, 08:03 PM#11
WNxCryptic
Guess I'll be doing a global array, then. :(
12-09-2007, 11:00 PM#12
darkwulfv
Can you answer to us why making a global array for the heroes is such a big deal?? You could've had your problem solved ages ago if you'd just made the arrays.
12-10-2007, 12:34 AM#13
grim001
Quote:
Originally Posted by WNxCryptic
Guess I'll be doing a global array, then. :(

I think you somehow got the incorrect idea that using globals is a bad thing
12-10-2007, 02:45 AM#14
WNxCryptic
Its a bad programming concept, or habit..whatever you want to call it.

I was hoping to avoid it.
12-10-2007, 03:01 AM#15
grim001
You mean the fact that you think using globals is bad is a bad concept?