If my memory serves me right, doing stuffcmd per frame is bad
How would you like commands stuffed onto you per frame! hehe
PutClientInServer() is called every time somebody respawns, so by doing members_team1 = members_team1 + 1; there, your game is thinking more and more people are joining
I think you're best off just doing a find per frame (easiest way) to tally up all the players.
Due to not wanting to do it per frame you're best off creating a 'manager' entity. This entity would then be responsible for handling things like this and you can just do it on that entity without worry about doing it per player per frame, just once for the manage entity per frame (or however often you choose).
To count up all the players per team would be easy, you can even count how many in the game total.
Code: Select all
float members_team1, members_team2, members_total;
void() CountPlayers =
{
local entity e;
members_team1 = members_team2 = members_total = 0;
while(e)
{
if (e.team_no == 1)
members_team1 = members_team1 + 1;
if (e.team_no == 2)
members_team2 = members_team2 + 1;
members_total = members_total + 1;
e = find(e, classname, "player");
}
self.nextthink = time + 1; // only use this if you do the manager thingy!
};
Ok now that's all your things accurately set, you would NOT to do this in PlayerPreThink as it'd be done per player per frame OUCH
Ok for doing the manager style entity, in StarFrame i'd do something like...
Code: Select all
if (!manager_ent) // manager doesn't exist, create it
{
manager_ent = spawn();
manager.think = CountPlayers();
manager.nextthink = time + 1;
}
obviously throw
in defs or something.
The benefit of having the manager is you can obviously do more things than just this in a think, you could make the .think a ManagerUpdate or something, and then have a bunch of functions like counting players, checking for dead/alive players etc. per frame only once, rather than per player per frame.
It's basically how things were handled on Pro-X vaguely.
If this stuff doesn't work properly or there's typos, sorry I've done all this just in the enter message dialog on the forum and haven't actually tried any of this.
Oh... and because you would already be searching through all the players in CountPlayers, you might as well count up all the ones that are dead/alive there too, and get everything over with in 1 hit
Good luck! keep posting as much as you need to