Page 1 of 1

Detecting Players Joining

Posted: Sun Jul 19, 2009 1:28 pm
by Fiodis
How would you detect players joining in MP via LUA? I searched the list of LUA fucntions and found a few:

Code: Select all

ScriptCB_IsJoinDone 
ScriptCB_CancelJoin 
ScriptCB_LaunchJoin 
ScriptCB_UpdateJoin 
ScriptCB_BeginJoin 
[/size]
But I'm not sure how I'd use them. Could these be used to detect when a player joins?

Re: Detecting Players Joining

Posted: Sun Jul 19, 2009 6:35 pm
by [RDH]Zerted
No, those help you join a game and you can tell you joined just by looking at the screen.

The v1.3 patch r117 added a function which returns a list of player names. You can use this with a timer and periodically count whos in the server and who isn't.

First, use the team counts to determine the amount of people on each team. When the count changes, grab the player list and see who wasn't on it the last time you grabbed it (you will need to store a copy of the list from each last time it was gotten). You can use this to see which players joined/stopped playing the game. Note, this doesn't track any spectators.

Theres no other way to do it.

Re: Detecting Players Joining

Posted: Mon Jul 20, 2009 10:47 am
by Fiodis
That's fine by me; I just wanted to use that processPlayers function for something and wanted players to be included in it even if they joined after the server started, in the middle of a game.

If I use that method, where I check to see if the team count changes, why would I need a timer?

Re: Detecting Players Joining

Posted: Mon Jul 20, 2009 1:36 pm
by [RDH]Zerted
There is a lua function to get the amount of players on a team. It is far faster and 'lighter' then the v1.3 patch's processPlayers. There is nothing that tells you when the team counts change.

You have to use a timer to get the current team count, wait a bit, then get it again to see if the count changed. If it did change, then you know someone joined (if its higher) or someone left (if its lower). There is a small chance that someone both joined and left, in which case the count would have stayed the same. You can use processPlayers to look at the player's names inorder to see who exactly joined or left the game.

Re: Detecting Players Joining

Posted: Mon Jul 20, 2009 4:46 pm
by Fiodis
Ah, thanks. Er, how would I store the table in order to compare it to a more recent one?

Re: Detecting Players Joining

Posted: Mon Jul 20, 2009 9:59 pm
by Frisbeetarian
Set it to a variable. Nearly anything in Lua can be set to a variable, even functions.

Re: Detecting Players Joining

Posted: Tue Jul 21, 2009 11:30 am
by Fiodis
Thanks. That sounds easy enough.