Jump to content
Sign in to follow this  
ZNorQ

Setvariable in mp environment

Recommended Posts

As I've understood, I can use setVariable to "attach" information to a specific vehicle.

So I've used it for my ammo trucks to indicate how many ammo crate it carries. There is a function to unload ammo crates from the truck, as long as there are any onboard.

Example;

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">vehicle player setVariable["nAmmoCrates", 10];

My question is; Any changes in this variable, will that be automatically broadcasted (publicVariable'd) to all clients, and if not - how do I do that?

ZNorQ

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">(vehicle player) setVehicleInit "this setVariable ['nAmmoCrates', 10]";

processInitCommands;

Problem is that new joiners will receive all vehicleInits that have been processed before. So if you 10 times change the variable with the above method, all those 10 executions will also be executed on newly joined players.

I myself also send the current time in the vehicle init, f.i something like this:

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">(vehicle player) setVehicleInit format["if(time-%1<60)then{this setVariable ['nAmmoCrates', 10]}",time];

processInitCommands;

This would only execute the VehicleInit if the time would not differ more than 60 seconds from the timestamp.

However, differences in programming methods could lead to not even needing to send this data over the network, all depending on for what you need it and how it works biggrin_o.gif

A possibility would be f.i to let the server keep all the counts... players send the request to unload an ammo crate to the server, and the server responds with a crate if there was still left, but responds with error message if no more available. This way you don't need to keep track of the counts on all machines smile_o.gif

Share this post


Link to post
Share on other sites

Crap, this really complicates things. Wonder why the setVariable is local? Wouldn't it be more logical to use this in an global space - or rather have an option for it to be local/global?

Thing is, the initializations are not done in the init line of the truck, but it is a script that adds the variable to every truck at start-up. It automatically detects if there are any ammo trucks.

Anyway, I'm understanding this as 'no, it doesn't publicVariable the setVariable changes.

ZNorQ

Share this post


Link to post
Share on other sites
However, differences in programming methods could lead to not even needing to send this data over the network, all depending on for what you need it and how it works biggrin_o.gif

A possibility would be f.i to let the server keep all the counts... players send the request to unload an ammo crate to the server, and the server responds with a crate if there was still left, but responds with error message if no more available. This way you don't need to keep track of the counts on all machines smile_o.gif

See you updated your response.. tounge2.gif

Good idea about that server. Think I have to look into that solution. I guess every time the player in the ammo trucks does any changes in the crate count (load/unloads) the setVariable is performed on the server, and not on clients.

ZNorQ

Share this post


Link to post
Share on other sites
Problem is that new joiners will receive all vehicleInits that have been processed before.

I also call clearVehicleInit afterwards. Perhaps that fixes the JIP issues.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// GLexec is a Game Logic

GLexec setVehicleInit _code;

processInitCommands;

clearVehicleInit GLexec;

Good advice with centralising the logic on the server.

Share this post


Link to post
Share on other sites
Problem is that new joiners will receive all vehicleInits that have been processed before.
I also call clearVehicleInit afterwards. Perhaps that fixes the JIP issues.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// GLexec is a Game Logic

GLexec setVehicleInit _code;

processInitCommands;

clearVehicleInit GLexec;

Good advice with centralising the logic on the server.well, last time I discussed clearVehicleInit, they told me the example in the biki is wrong. You can not remove the vehicleInits after it was processed (processInitCommands).

Well, yes you could run the clearVehicleInit command, but it would still be sent to JIP players smile_o.gif

There is a possibility that this clearVehicleInit does work as long as you execute it on the server, because he is the one who will send the list with vehicleInits to the JIPpers, not the other clients smile_o.gif

(Damn I hate this uncertainty, nothing beats testing and figuring out on my own biggrin_o.gif)

I solved basicly all my issues with the v1.09beta function: addPublicVariableEventHandler, boy do I love it smile_o.gif

Wrote a new Network Engine that uses 1 variable per machine to send commands, with possibility to specify if all clients + server, only server, only clients, or specific clients (due to unique ID) must execute the command. Saves 100's, maybe 1000's, of vehicleInits that got synced at the start. And you only have to worry about the last command sent out being synced to JIP players smile_o.gif (all publicVariables are synced to jippers at join)

The coolness is now also that you can use arrays and publicvar them, basicly making it possible to send objects like groups and vehicles in one send.

The problem with vehicleInit's are that they are strings. You can of course do something with the object you run the vehicleInit on (THIS), but you would have to run an Init per object or use extra publicVariables to work with more than 1 object at once.

While using a publicVariable array that contains data used; destination, code to execute, and extra parameters like objects etc, gives you all the possibilities in the world smile_o.gif

Share this post


Link to post
Share on other sites

To me it has seemed that when you clear the vehicle init, there is nothing to send and nothing is sent.

--Ben

Share this post


Link to post
Share on other sites
Problem is that new joiners will receive all vehicleInits that have been processed before.
I also call clearVehicleInit afterwards. Perhaps that fixes the JIP issues.

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">// GLexec is a Game Logic

GLexec setVehicleInit _code;

processInitCommands;

clearVehicleInit GLexec;

Good advice with centralising the logic on the server.

well, last time I discussed clearVehicleInit, they told me the example in the biki is wrong. You can not remove the vehicleInits after it was processed (processInitCommands).

Well, yes you could run the clearVehicleInit command, but it would still be sent to JIP players smile_o.gif

There is a possibility that this clearVehicleInit does work as long as you execute it on the server, because he is the one who will send the list with vehicleInits to the JIPpers, not the other clients smile_o.gif

(Damn I hate this uncertainty, nothing beats testing and figuring out on my own biggrin_o.gif)

I solved basicly all my issues with the v1.09beta function: addPublicVariableEventHandler, boy do I love it smile_o.gif

Wrote a new Network Engine that uses 1 variable per machine to send commands, with possibility to specify if all clients + server, only server, only clients, or specific clients (due to unique ID) must execute the command. Saves 100's, maybe 1000's, of vehicleInits that got synced at the start. And you only have to worry about the last command sent out being synced to JIP players smile_o.gif (all publicVariables are synced to jippers at join)

The coolness is now also that you can use arrays and publicvar them, basicly making it possible to send objects like groups and vehicles in one send.

The problem with vehicleInit's are that they are strings. You can of course do something with the object you run the vehicleInit on (THIS), but you would have to run an Init per object or use extra publicVariables to work with more than 1 object at once.

While using a publicVariable array that contains data used; destination, code to execute, and extra parameters like objects etc, gives you all the possibilities in the world smile_o.gif

I have maked simmilar way.

I use two pulbic variables to send what i need from CLIENT to SERVER or back, from SERVER to ONE/ALL CLIENT.

I use two public variales ServerToClient (STC) and ClientToServer (CTS). Clients are receiving STC variable, adn thransmiting thru CTS variable. Server oposit.

Server have updated array of connected players (thru onPlayerConnect/Disconnect).

Every receive/transmith have unique mID(mesasgeID), and pID(playerID). PID is need when server need to send something to one pc with this pID. mID is random number unique for every one message/connection.

Every client first must "reserve" the "line" for him self, and then can send message or command. They send his mIDs to CTS and waiting, for permission received thru variable STC. When they receive thery mID back, they can transmith comand/string to the server. Server receive this string thru CTS variable and send back to the client acknowledge about that. Comunication is ended, server send 0 to the CTS var,, that means is ready to receive another reservation from another client or script which is waiting to send something.

Every client and server is cycling on one variable so no "variable" broadcas storm would be there. You can be sure, that message will be transmithed to the server, but somethime that takes more time, because in one momment there can communicate only two PCs other commands wait for line reservation. I use that for starting some other scripts on client.

Server and client when receive command, they execute them, or they can investigate what it is, so you can make condition, which command executed, and which is message to display or soo.

Its not ready to publish, but i have working version. It is very good for multiplayer servers where are connected many many players and you don't wish to have laags by sending everything thru objectsinit or many public variables.

Share this post


Link to post
Share on other sites

Nice one mate! I choose to use a variable per client as this means you can have multiple sends/receives at the same time and dont have any kinds of "lag". It very much depends on what you want to use it for though. Some things is no problem if it lags, but other things... tounge2.gif

Share this post


Link to post
Share on other sites

Hmm OK to add my own spoon into this bowl, I'm trying to implement a ProcessInitCommand method to get all DMSmokeEffects to distribute code to all players so all should see the same sort of smoke.

I was worried that using this method would overwrite all other init code, but from what I read this is not the case? It is all stacked & processed in order? That's cool if it is smile_o.gif I have to confess I don't fully understand the command yet.

ProcessInitCommand will make all machines process all current inits on all vehicles whenever it is used?

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  

×