Jump to content
Sign in to follow this  
dreadedentity

"onPlayerConnected" stackedEventHandler and JIP's

Recommended Posts

SEH:

1. What is a stacked event handler?

2. Can I use it simply by putting "[arguments] call BIS_fnc_addStackedEventHandler" in my init.sqf?

3. How does a stacked event handler keep compatibility between official and community content?

4. How is this better than using onPlayerConnected/onPlayerDisconnected, commands that were already included?

JIP:

1. Will the code argument in my "onPlayerConnected" stackedEventHandler declaration run for every player that joins the server?

2. What's the best way to handle JIP's?

3. Everything else you guys know relating to JIP's.

Sorry there's a lot of questions in this post, guys. I realize that not all of you will know the answer to every one so just answer what you can. I'm trying to make a mission that interacts with a database using @iniDB so my players can have persistent stats, vehicles, and maybe even buildings. The real problem here is that I have no idea what will happen when a player joins in progress, what/where code will be run and stuff like.

None of iniDB's code can be run on a client machine because I don't want my clients to have to download the addon. Because of this, I'll need to query the server to get player data, have the server read the database, then send that back to the client. I have kind of an idea on how to do this:

playerArray = [owner player, getPlayerUID player];
publicVariableServer "playerArray"; //server query

//iniDB code
(_this select 0) publicVariableClient "data";

What I'm confused about is how to save the variables passed with publicVariableServer/publicVariableClient because they don't return anything and pretty much anything related to JIP's

Share this post


Link to post
Share on other sites

To answer your JIP question, or at least your #2 in that section :p.

I use the below in the init.sqf, I put it above everything that is in the init.sqf:

if (!isServer && isNull player) then {isJIP=true;} else {isJIP=false;};

if (!isDedicated) then
{
waitUntil {!isNull player && isPlayer player};
sidePlayer = side player;
};

Basically all this does is make sure that before anything is initialized to/for the player, that the player is not null and has been assigned a side and designates the player as a JIP, so the server knows to include the new JIP player with the rest. It helps combat object creation client/server side as well as possibly helping with variable value transfer for JIPs.

Edited by JShock

Share this post


Link to post
Share on other sites

SEH:

1. What is a stacked event handler?

It stacks a set of code routines to call when the event fires. Will make more sense once you read the rest.

2. Can I use it simply by putting "[arguments] call BIS_fnc_addStackedEventHandler" in my init.sqf?

No. The structure is [Name, eventType, code] call BIS_fnc_addStackedEventHandler;

Where ..

Name is a STRING and is just a name to associate the passed code with the event that is going to call it. This name can later be used to remove the code from the list of code to be called when the event fires.

EVENTTYPE is a STRING it is the name of the original command you want this code to be associated under. e.g onMapSingleClick or onPlayerConnected etc

CODE is {code} the code you want run when the event fires

3. How does a stacked event handler keep compatibility between official and community content?

The original commands onMapSingleClick, onPlayerConnected etc have a one off usage. e.g calling onPlayerConnected {//blah}, when a player connects blah will happen.

Trouble is if some other script say from a mod your using also needed to use onPlayerConnected (onPlayerConnected {//mods blah}) then one will overwrite the other. Depending on which snippet was run last would depend on what would happen when onPlayerConnected fires.

What the function addStackedEventHandler does is store these snippets and then when onPlayerConnected fires runs each piece.

So you are basically still only using the one instance of onPlayerConnected but the function handles firing multiple pieces of code for that one event.

4. How is this better than using onPlayerConnected/onPlayerDisconnected, commands that were already included?

As above the commands are a one off usage. Using the commands could overwrite an event that has been setup else where.

JIP:

1. Will the code argument in my "onPlayerConnected" stackedEventHandler declaration run for every player that joins the server?

Yes.

2. What's the best way to handle JIP's?

Either this or initPlayerLocal.sqf or initPlayerServer.sqf which are automatically run. EventScripts

Maybe worth a read

3. Everything else you guys know relating to JIP's.

Pfff Its black magic i tells you. Even when you think you have a handle on it, something will bite you in the arse. read read and read the forums. If in doubt ask but this along with MP scripting is a large topic.

Stands for Join In Progress.

Means your not hardcore as you were not there at mission start.

Does not mean Jump In Plane, first come first served.

:D

Share this post


Link to post
Share on other sites

Pfff Its black magic i tells you. Even when you think you have a handle on it, something will bite you in the arse. read read and read the forums. If in doubt ask but this along with MP scripting is a large topic.

^ Love it :p and so very true.

Share this post


Link to post
Share on other sites
JIP... Stands for Join In Progress. Means your not hardcore as you were not there at mission start. Does not mean Jump In Plane, first come first served.

:D

And there was I thinking it stood for "Jizz in Pants".. :811:

Share this post


Link to post
Share on other sites

Thanks for the explanations guys, very helpful. Just to cement the concept, I could put this:

["JIP_event", "onPlayerConnected", {
hintSilent str _this;
}, "You are a JIP"] call BIS_fnc_addStackedEventHandler;

in my init.sqf, and any JIP's will get that hint, correct?

Do JIP's ever run init.sqf also or should I also add "null = [] execVM "JIPscript.sqf";" (nonexistent)? Will players that immediately reconnect to the server after restart (before briefing) also count as a connected player? Sorry for all the questions guys, I normally would just test all these things, but I'm not sure how to test it since I'm just one guy.

Share this post


Link to post
Share on other sites

I do believe the answer is yes, to at least the first question, I'll leave the answer to the second up to one of the others.

Share this post


Link to post
Share on other sites
but I'm not sure how to test it since I'm just one guy.
Set yourself up a dedicated server can be on the same machine as where you will run your client.

Make sure you have persistent = 1; in your server config and any test missions have respawn = 3; in their description.ext (if its not a respawn mission then it wont stay persistent when the last player leaves) with a respawn marker. Think thats all you need.

Then you can join your server, start a mission up, then disconnected back to MP server page, rejoin and the mission should still be running and you should be presented with the lobby rather than the select mission page. At which point you are joining as a JIP.

Share this post


Link to post
Share on other sites

Interesting StackedEventhandler. Ironically I learned about stacks learning how CPU's work. Basically this is a stack

--- Stack --- The eventHandler when fired will queue your program code into stacks and await each execution but first instructions are the last ones which are out meaning the first in last out, last is executed first because it is at the bottom of the stack.

Program code A <---- First in

----\/---- then

Program Code B

----\/---- then

Program Code C

----\/---- then

Program Code D ---> Last out

Thats all a stack is. So a stacked event handler could be used to intialise multiple things for a client on player connect e.g run code when they JIP Executing that "STACK" of instructions.

Edited by Polymath820

Share this post


Link to post
Share on other sites

addStackedEventHandler is not a stack in the true sense of the word as your describing Polymath820. It really is just an array of code to call when the event fires.

e.g vary basic example

//Some functions
function_1 = {hint "Im function 1";};
function_2 = {hint "Im function 2";};
function_3 = {hint "Im function 3";};

//Our addStack function
addStack = {
if (isNil "function_stack") then {
	function_stack = [];
};

function_stack set [count function_stack, _this];

onPlayerConnected {
	{
		[] spawn _x;
	}forEach function_stack;
};
};

//Add the functions to the stack to be called onPlayerConnected
function_1 call addStack;
function_2 call addStack;
function_3 call addStack;

Share this post


Link to post
Share on other sites
Thanks for the explanations guys, very helpful. Just to cement the concept, I could put this:

["JIP_event", "onPlayerConnected", {
hintSilent str _this;
}, "You are a JIP"] call BIS_fnc_addStackedEventHandler;

in my init.sqf, and any JIP's will get that hint, correct?

Not really, unless Neokika went out of his way and made onPlayerConnected to call BIS_fnc_MP. By default onPlayerConnected is executed on the server only, while hint is command for a client with interface. If you host the game yourself, only you will see the hint, if it runs on dedicated, no one will see it.

Share this post


Link to post
Share on other sites
Do JIP's ever run init.sqf
Yes after they have been initialised and connected to their bodies. See Initialization Order in previous link from post #3 Maybe worth a read
JIP Players

Same as above, but there's no Briefing this time. init.sqf seems to run after the player gets control of his character

Will players that immediately reconnect to the server after restart (before briefing) also count as a connected player?

Again from thee link above..

After Briefing

if onPlayerConnected was setup in e.g. init.sqf, it will now process all the players connected in order of connected

onPlayerConnected will process new players after they are connected to their player body. So JIP player connects, world initializes, he gets control of his character, now the onPlayerConnected fires on the server.

Although that document was written a few years ago I believe it still holds true for Arma 3.

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  

×