Detecting Players Joining

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Detecting Players Joining

Post 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?
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Detecting Players Joining

Post 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.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Detecting Players Joining

Post 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?
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Detecting Players Joining

Post 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.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Detecting Players Joining

Post by Fiodis »

Ah, thanks. Er, how would I store the table in order to compare it to a more recent one?
User avatar
Frisbeetarian
Jedi
Jedi
Posts: 1233
Joined: Wed Sep 12, 2007 3:13 pm

Re: Detecting Players Joining

Post by Frisbeetarian »

Set it to a variable. Nearly anything in Lua can be set to a variable, even functions.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Detecting Players Joining

Post by Fiodis »

Thanks. That sounds easy enough.
Post Reply