Jump to content
Sign in to follow this  
[kh]jman

onPlayerConnected

Recommended Posts

onPlayerConnected is not firing on the dedicated server for the first player to start the mission. Is anyone else aware of this and if so if there a workaround?

Share this post


Link to post
Share on other sites

The name of the first "player" is always:

__SERVER__

You can use it or not, for example:

if (_name == "__SERVER__") exitWith {};

Edit:

The following OPC event triggers with the first human player.

Please be aware that you can't stack OPC and OPD, means you can't use it more than once (in a mission and in an addon for example, one will override the other).

http://dev-heaven.net/issues/14956

Xeno

Edited by Xeno

Share this post


Link to post
Share on other sites

It fires for each player as long as there is a delay between player connections.

log:

(uid's star'd out)

// playerconnected.sqf Player 1

JayArmA2Lib: [sERVER MSG: Player check connecting [KH]Rick, id 13****7]

JayArmA2Lib: [sERVER MSG: Player connected [KH]Rick, id 1e+007]

JayArmA2Lib: [sERVER MSG: Player [KH]Rick, Connected to kellys heroes player database]

JayArmA2Lib: [sERVER MSG: Player [KH]Rick, puid 13****7]

JayArmA2Lib: [sERVER MSG: Number of players in db found, 4]

JayArmA2Lib: [sERVER MSG: Players listed in db, [string,"'Joe Bloggs'","'123456'","'37'"]]

JayArmA2Lib: [sERVER MSG: Players listed in db, ["'4'","'[KH]Jman'","'72***9'","'8'"]]

JayArmA2Lib: [sERVER MSG: Players listed in db, ["'7'","'Sgt.Awol'","'85***3'","'0'"]]

JayArmA2Lib: [sERVER MSG: Players listed in db, ["'10'","'[KH]Rick'","'13****7'","'0'"]]

JayArmA2Lib: [sERVER MSG: Found, '[KH]Rick', entry in db]

JayArmA2Lib: [sERVER MSG: Welcome back, [KH]Rick]

JayArmA2Lib: [sERVER MSG: Database player id: 10]

JayArmA2Lib: [sERVER MSG: Database player puid: 13****7]

JayArmA2Lib: [sERVER MSG: Database player name: [KH]Rick]

JayArmA2Lib: [sERVER MSG: Database player score: 0]

JayArmA2Lib: [sERVER MSG: Number of connected players, 1]

JayArmA2Lib: [sERVER MSG: Located player's array in CONNECTEDPLAYERS, Key, ["13****7","[KH]Rick"] Element,13****7 ]

JayArmA2Lib: [sERVER MSG: player, [KH]Rick _key, 0 _puid, 13****7, insert at position, 2 _newscore, 1]

// playerconnected.sqf Player 2

JayArmA2Lib: [sERVER MSG: Player connected [KH]Jman, id 1.80763e+009]

JayArmA2Lib: [sERVER MSG: Player [KH]Jman, Connected to kellys heroes player database]

JayArmA2Lib: [sERVER MSG: Player [KH]Jman, puid 72***9]

JayArmA2Lib: [sERVER MSG: Number of players in db found, 4]

JayArmA2Lib: [sERVER MSG: Players listed in db, [string,"'Joe Bloggs'","'123456'","'37'"]]

JayArmA2Lib: [sERVER MSG: Players listed in db, ["'4'","'[KH]Jman'","'72***9'","'8'"]]

JayArmA2Lib: [sERVER MSG: Found, '[KH]Jman', entry in db]

JayArmA2Lib: [sERVER MSG: Welcome back, [KH]Jman]

JayArmA2Lib: [sERVER MSG: Database player id: 4]

JayArmA2Lib: [sERVER MSG: Database player puid: 72***9]

JayArmA2Lib: [sERVER MSG: Database player name: [KH]Jman]

JayArmA2Lib: [sERVER MSG: Database player score: 8]

JayArmA2Lib: [sERVER MSG: Number of connected players, 2]

JayArmA2Lib: [sERVER MSG: Located player's array in CONNECTEDPLAYERS, Key, ["72***9","[KH]Jman"] Element,72***9 ]

JayArmA2Lib: [sERVER MSG: player, [KH]Jman _key, 1 _puid, 72***9, insert at position, 2 _newscore, 9]

// playerconnected.sqf Player 3

JayArmA2Lib: [sERVER MSG: Player connected [KH]Nat, id 4.97006e+008]

JayArmA2Lib: [sERVER MSG: Player [KH]Nat, Connected to kellys heroes player database]

JayArmA2Lib: [sERVER MSG: Player [KH]Nat, puid 3****2]

JayArmA2Lib: [sERVER MSG: Number of players in db found, 4]

JayArmA2Lib: [sERVER MSG: Players listed in db, [string,"'Joe Bloggs'","'123456'","'37'"]]

JayArmA2Lib: [sERVER MSG: Players listed in db, ["'4'","'[KH]Jman'","'7****9'","'8'"]]

JayArmA2Lib: [sERVER MSG: Players listed in db, ["'7'","'Sgt.Awol'","'8****3'","'0'"]]

JayArmA2Lib: [sERVER MSG: Players listed in db, ["'10'","'[KH]Rick'","'1*****7'","'4'"]]

JayArmA2Lib: [sERVER MSG: Number of connected players, 3]

JayArmA2Lib: [sERVER MSG: Located player's array in CONNECTEDPLAYERS, Key, ["3****2","[KH]Nat"] Element,3****2 ]

JayArmA2Lib: [sERVER MSG: player, [KH]Nat _key, 2 _puid, 3****2, insert at position, 2 _newscore, 1]

JayArmA2Lib: [sERVER MSG: SQL output: insert into players (pname, puid) values ('[KH]Nat',3****2)]

// playerdisconnected.sqf Player 2

JayArmA2Lib: [sERVER MSG: Player [KH]Jman, left the server]

JayArmA2Lib: [sERVER MSG: Number of connected players, 3]

JayArmA2Lib: [sERVER MSG: Located player's array in CONNECTEDPLAYERS, Key, ["7****9","[KH]Jman",9] Element,7****9 ]

JayArmA2Lib: [sERVER MSG: Got [KH]Jman CONNECTEDPLAYERS arrayPos: _key: 0, _pscore: 9]

JayArmA2Lib: [sERVER MSG: Player [KH]Jman, Connected to kellys heroes player database]

JayArmA2Lib: [sERVER MSG: SQL output: update players set pscore = '9' where puid = '7****9']

JayArmA2Lib: [sERVER MSG: Player [KH]Jman, removed from CONNECTEDPLAYERS]

JayArmA2Lib: [sERVER MSG: Number of CONNECTEDPLAYERS, 2 ]

JayArmA2Lib: [sERVER MSG: Player [KH]Rick, found in CONNECTEDPLAYERS]

JayArmA2Lib: [sERVER MSG: Player [KH]Nat, found in CONNECTEDPLAYERS]

So supposing there were 5 players all waiting in the lobby, when the admin selects the 'ok' button to begin the mission how many onPlayerConnect's are fired? one per player or just the 1st player or just the 5th player? or non at all?

Also when the last player on the server leaves and the onPlayerDisconnect trigger is fired the _SERVER_ player immediately leaves too (if not a persistent server which I don't want).

log:

[sERVER MSG: Number of connected players, 2]

JayArmA2Lib: [sERVER MSG: Located player's array in CONNECTEDPLAYERS, Key, ["30***2","[KH]Nat"] Element, 30***2 ]

JayArmA2Lib: [sERVER MSG: player, [KH]Nat _key, 1 _puid, 30***2, insert at position, 2 _newscore, 2]

JayArmA2Lib: [sERVER MSG: Player [KH]Nat, left the server]

JayArmA2Lib: [sERVER MSG: Player [KH]Rick, left the server]

JayArmA2Lib: [sERVER MSG: Player __SERVER__, left the server]

Is there a way to delay the __SERVER__ leaving so that I can write some data out to my db. As you can see above the server terminates before my script has a chance to complete.

Edited by [KH]Jman

Share this post


Link to post
Share on other sites

Sickboy mentions the following on dev-heaven (http://dev-heaven.net/issues/14956)

Only if we get OPC/OPD events that can be used like normal eventhandlers :)

You mean what we already have in CBA? :D

["cba_network_opc", { /* doMagick */ }] call CBA_fnc_addEventHandler;

["cba_network_opd", { /* doMagick */ }] call CBA_fnc_addEventHandler;

yet I cannot find any documentation on cba_network_opc & cba_network_opd

Share this post


Link to post
Share on other sites

onPlayerConnected should always work, regardless if there is delay or no delay between player connections.

There's no docu on cba_network_opc and d because they aren't officially supported features since I ripped out onPlayerConnected usage from CBA (and replaced it with a custom implementation of player connected), because as Xeno pointed out, it can only be used by 1 script, and mission makers seem to want to use them :D

You could use cba's OPC, but it gives no benefit if you already use onPlayerConnected directly.

Currently OPD is unimplemented.

Still, if you want to use cba OPC, you can use this;

["cba_network_opc", { _this call myOnPlayerConnectedFunction }] call CBA_fnc_addEventHandler;

the following parameters are sent to the function:

[player,getPlayerUID player,name player,isClass(configFile>>'CfgPatches'>>'cba_main')]

(As of CBA 0.7.1 dev)

Edited by Sickboy

Share this post


Link to post
Share on other sites

CBA OPC seems a little better implemented than the default OPC since yours sends the player's object too and the default only sends player name, id and uid.

Using the default OPC & having to loop through all players connected and identifying the calling player's object by the player uid is a little cumbersome and more importantly taking valuable time.

onPlayerConnected should always work, regardless if there is delay or no delay between player connections.

Thats good to know, my code must be failing to handle more than one at a time, probably my array is getting fubar'd, I will have to check my code again.

Is there a way to delay the __SERVER__ leaving so that I can write some data out to my db.?

Share this post


Link to post
Share on other sites
Jman;1795049']

Is there a way to delay the __SERVER__ leaving so that I can write some data out to my db.?

No, there isn't.

But the script should still be executed completely for the last player if you don't run it scheduled (means, no execVM and no spawn).

Xeno

Share this post


Link to post
Share on other sites

This is the flow I have atm....

init.sqf

#define PP preprocessfilelinenumbers

[] spawn {

sleep 5;

initFinished = false;

gameStarted = false;

[] spawn compile PP "weatherSync.sqf";

[] call compile PP "arrays.sqf";

[] spawn compile PP "globals.sqf";

[] spawn compile PP "initPlayer.sqf";

// [] call compile PP "respawn.sqf";

[] call compile PP "modifiers.sqf";

[] call compile PP "strings.sqf";

call removeModifiers;

call haltOnError;

// call displayVersion;

initFinished = true;

gameStarted = true;

};

initPlayer.sqf

if (isServer) then {

CONNECTEDPLAYERS = [];

publicVariable "CONNECTEDPLAYERS";

onPlayerConnected "[_id, _name, _uid] execVM ""playerConnected.sqf""";

onPlayerDisconnected "[_id, _name, _uid] execVM ""playerDisconnected.sqf""";

};

Could you elablorate on what you mean in respect for the above context?

Thank you btw, I've only just started to get my head around this scripting language, I'm more used to AS3, PHP and PERL ;)

Edited by [KH]Jman

Share this post


Link to post
Share on other sites

You start the scripts in OPC and OPD with execVM.

This means that the script will start at least one frame after you have executed it in OPC/OPD.

So if the mission/game ends in the frame when the last player leaves the execVM won't be started anymore.

Use call function or call compile preprocess... "script.sqf" (without sleep and waituntils in the script/function) and it should work.

Xeno

Share this post


Link to post
Share on other sites

I've made an error with the values passed to OPC, it should reflect the original as much as possible, will be fixed for next update

[name player,getPlayerUID player,player,isClass(configFile>>'CfgPatches'>>'cba_main')]

Another advantage over the normal OPC is that you can use the same syntax (call to addEventhandler) on clients ;-)

On a side note, since latest CBA build the CBA OPC event will work with all clients, before only CBA clients created the event.

Edited by Sickboy

Share this post


Link to post
Share on other sites

On a side note, since latest CBA build the CBA OPC event will work with all clients, before only CBA clients created the event.

Does this mean that CBA only needs to be enabled server-side and not on clients with respect to OPC?

Share this post


Link to post
Share on other sites
Jman;1795141']Does this mean that CBA only needs to be enabled server-side and not on clients with respect to OPC?
This is correct since latest version.

Share this post


Link to post
Share on other sites
You start the scripts in OPC and OPD with execVM.

This means that the script will start at least one frame after you have executed it in OPC/OPD.

So if the mission/game ends in the frame when the last player leaves the execVM won't be started anymore.

Use call function or call compile preprocess... "script.sqf" (without sleep and waituntils in the script/function) and it should work.

Xeno

I changed:

onPlayerDisconnected "[_id, _name, _uid] execVM ""playerDisconnected.sqf""";

To:

onPlayerDisconnected "[_id, _name, _uid] call compile preprocessfilelinenumbers ""playerDisconnected.sqf""";

and now I get an error:

2010/11/24, 23:56:59 Error in expression <[_id, _name, _uid] call compile preprocessfilelinenumbers "playerDisconnected.sqf">

2010/11/24, 23:56:59 Error position: <"playerDisconnected.sqf">

2010/11/24, 23:56:59 Error Missing ;

Edited by [KH]Jman

Share this post


Link to post
Share on other sites

For info:

Fixed:

onPlayerDisconnected {[_id, _name, _uid] call compile preprocessfilelinenumbers "playerDisconnected.sqf"};

Share this post


Link to post
Share on other sites

Post removed. (Not relevent)

Edited by [KH]Jman

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×