Page 1 of 1
Counting players including those in spectator
Posted: Sun Mar 05, 2006 1:11 pm
by Waylander76
Hi All
I've used a player counting script from this forum and it works how I want
it to, but the problem is it doesn't take into account players in spectator
and only if there is 1 player on the map.
What I want it to do is count the alive players on each team and then run
a thread to play a sound when there are either no allies or axis left alive.
What it does at the moment is to play the sounds when you join the game
as both axis and allies players are nil.
When I select a side it will see that there are no opposition players and
run the win thread .
With 2 ppl on the map it runs as it should
It's a SH obj map the thread is below.
Please could somebody point me in the right direction as to what I need
to add so that it accounts for players in spectator and only 1 player on the map, waiting for others to join?
Thanks in advance!
Code: Select all
count_players:
while(1)
{
level.allies = 0
level.axis = 0
for(local.i=1;local.i<=$player.size;local.i++)
{
if(isAlive $player[local.i])
{
if($player[local.i].dmteam=="allies")
{
level.allies++
}
else if($player[local.i].dmteam=="axis")
{
level.axis++
}
}
}
}
if (level.allies == 0)
{
thread allies_dead
}
if (level.axis == 0)
{
thread axis_dead
}
wait 1
}
end
allies_dead:
wait 2
$axis_win_speaker playsound axis_win_snd
teamwin axis
end
axis_dead:
wait 2
$allies_win_speaker playsound allies_win_snd
teamwin allies
end
spectator
Posted: Sun Mar 05, 2006 1:50 pm
by tltrude
have you tried this:
else if($player[local.i].dmteam=="spectator")
level.spectator++
Btw, dmteam can returns 'allies', 'axis', 'spectator', or 'freeforall'.
Posted: Sun Mar 05, 2006 4:03 pm
by Waylander76
Tom thaks again for helping me
By reading the forum i did think I'd need to put
else if($player[local.i].dmteam=="spectator")
level.spectator++
in there somewhere but that's what I'm not sure about...where would I put it in my script and what would I do with the value level.spectator?
I can see I have definate uses for level.axis and level.allies , if level.axis is 0 do this,if level.allies is 0 do this....
but i don't have one for level.spectator.
if level.spectator >= 1 then do what??
Thanks again for helping!
Posted: Sun Mar 05, 2006 7:00 pm
by ViPER
I don't think you need to do anything with spectator, but try conditioning your while statement
while($player.size > 1)
***edit***
forget that^^^^ it wont work because you will never see win condition of 1 player - Think of a clever way to condition your while or -
you could count your players first with an if at the end - then count again to exec your team win thread. count up - then count down
if((level.axis > 1) && (level.allies > 1))
{
Thread count_players
end
}
Posted: Sun Mar 05, 2006 10:33 pm
by Waylander76
Viper if i put that in then I get a bad token error RIGHT_BRACES }
Yet if i don't put it in it works as described before.
Also is the line if((level.axis > 1) && (level.allies > 1)) allright where
it is or does it need to be near the start of the thread?
If i conditioned the while statement as suggested while($player.size > 1)
does this mean that if there is only one player then the win threads
wouldn't run even if the player was in spec?
However if another joined then the count thread would count the players
and then execute the victory threads?
Code: Select all
count_players:
while(1)
{
level.allies = 0
level.axis = 0
for(local.i=1;local.i<=$player.size;local.i++)
{
if(isAlive $player[local.i])
{
if($player[local.i].dmteam=="allies")
{
level.allies++
}
else if($player[local.i].dmteam=="axis")
{
level.axis++
}
}
}
}
if (level.allies == 0)
{
thread allies_dead
}
if (level.axis == 0)
{
thread axis_dead
}
if((level.axis > 1) && (level.allies > 1))
{
thread count_players
end
}
wait 1
}
end
Posted: Mon Mar 06, 2006 5:17 am
by ViPER
looks like the last } is 1 too many.
try this (not tested) im sure theres a simpler way, but this is what I was thinking, something like this -
Code: Select all
countup_players:
while(1)
{
level.allies = 0
level.axis = 0
for(local.dude=1;local.dude <= $player.size;local.dude++)
{
if ($player[local.dude].dmteam == "axis")
level.axis++
if ($player[local.dude].dmteam == "allies")
level.allies++
}
if((level.axis > 1) && (level.allies > 1))
{
thread countdown_players
end
}
wait 1
}
end
countdown_players:
while(1)
{
level.allies = 0
level.axis = 0
for(local.i=1;local.i<=$player.size;local.i++)
{
if(isAlive $player[local.i])
{
if($player[local.i].dmteam=="allies")
{
level.allies++
}
else if($player[local.i].dmteam=="axis")
{
level.axis++
}
}
}
if (level.allies == 0)
{
thread allies_dead
}
if (level.axis == 0)
{
thread axis_dead
}
wait 1
}
end
Posted: Mon Mar 06, 2006 8:52 am
by Waylander76
Viper tried your code this morning and it doesn't work.
Well something's happening as I don't get the repeating sounds
when only 1 player is on the map.
When 2 players are on the map
When the axis win the axis win sound isn't played and when the allies win
the allies win sound isn't played.
This leads me to believe it's not executing the 'thread countdown_players'
line in the first thread.
Will try again when I get in from work.
Thanks for the help so far.
threads
Posted: Mon Mar 06, 2006 10:41 am
by tltrude
You need to rethink what you want to do. The standard obj script already has threads for ending the game when the last team player is killed. All you need to do is insert your sounds into those threads.
Btw, to stop a while loop, the command is "break" not "end".
Posted: Mon Mar 06, 2006 11:55 am
by ViPER
Tom's right - other than the sound what are you trying to do ?
This works script wise, not sure about the teamwin or sound -
Code: Select all
countup_players:
while(1)
{
level.allies = 0
level.axis = 0
for(local.dude=1;local.dude <= $player.size;local.dude++)
{
if ($player[local.dude].dmteam == "axis")
level.axis++
if ($player[local.dude].dmteam == "allies")
level.allies++
}
if((level.axis > 0) && (level.allies > 0))
{
thread countdown_players
break
}
wait 1
}
end
countdown_players:
while(1)
{
level.allies = 0
level.axis = 0
for(local.i=1;local.i<=$player.size;local.i++)
{
if(isAlive $player[local.i])
{
if($player[local.i].dmteam=="allies")
{
level.allies++
}
else if($player[local.i].dmteam=="axis")
{
level.axis++
}
}
}
if (level.allies == 0)
{
thread allies_dead
}
if (level.axis == 0)
{
thread axis_dead
}
wait 1
}
end
allies_dead:
wait 1
$axis_win_speaker playsound axis_win_snd
teamwin axis
iprintln "dead"
end
axis_dead:
wait 1
$allies_win_speaker playsound allies_win_snd
teamwin allies
iprintln "dead"
end
Posted: Mon Mar 06, 2006 1:44 pm
by Waylander76
All I was trying to do is play a sound when either the axis or allies win screen is displayed
As the sound was played when all the obj's were completed but not when
the axis killed the allies and vice versa I thought i'd need a script to
do it.
I didn't want to start messing with the standard scripts because I wouldn't know where to start!
If however it's just inserting the playsound line then I think I could cope with that!
Again thanks for all the help you two have given
**EDITED to add **
Viper: tried your script and it works just as I wanted so thank you again.
Tom: which is the script that the axis/allies win is defined in?