Jump to content
Sign in to follow this  
Double Doppler

Using createUnit to send commands over the network - efficiency

Recommended Posts

After reading the topic in the BIKI about createUnit, and how the unit's init on creation could be used to broadcast code, I tried it out for myself. I wrote a function as the following:

_code  = _this;
_name = format ["DDOPPLER_pvMan_%1",round (random 5000)];

_name = "US_Soldier_EP1" createUnit [getpos server, group server, format["call compile %1; %2 = this",_code,_name]];
sleep 0.1;
deleteVehicle _name;

Where "server" is a placed game logic. It worked, however, is this really efficient by modern scripting standards? Do "createUnit" and "deleteVehicle" take up computing time for all connected machines? Is the conventional use of publicVariable and "addPublicVariableEventHandler" more efficient or less? My type of code will be run on all machines (except the server) and will be broadcast very frequently (it triggered by the "fired" eventhandler, which is added to the init of all units on mission start).

Share this post


Link to post
Share on other sites

one does NOT send code over net - from missions

you only send the identifier what the target needs to execute (a number) and if needed parameters (data)

(or you use the pV/pVEH name as identifier)

as everyone has the complete code from the mission already

drop the createUnit idea, nor consider to use sVI (basically the same). pV+pVEH is the way to go.

use forum search to learn why (ref Sickboy/Xeno and others)

remote code execution is only for dev console or client/server side only addons

Share this post


Link to post
Share on other sites

This is very interesting - I am used to working with sending code through the network due to the inefficiently written "life mission" scripts.

So what you mean is that instead of broadcasting code over the network, I could store this code as a string in an array, then write a PVEH so that the variable's value would be the index of that array to compile?

array_public_code = [
"player say ""profanity"";", // code examples
"player sideChat ""test"";"
];

pVar = 0;
"pVar" addPublicVariableEventHandler {
   call compile (array_public_code select (_this select 1))
};

pVar = 1;
publicVariable "pVar"

And I am supposing now a request for the command "player sidechat ""test"";" would now be send over the network?

Also what sending arrays (as parameters) over the network? Does that affect performance greatly?

What I am also thinking of is:

pVar = ["player","sideChat","zombies are attacking us!"]
"pVar" addPublicVariableEventHandler {
   call compile (array_public_code select ((_this select 1) call fnc_public_compile))
};

fnc_public_compile = {
   _object1   = _this select 0;
   _command = _this select 1;
   _object2   = _this select 2;
   call compile format ["%1 %2 %3",_object1,_command,_object2];
};
pVar = ["player","sideChat","zombies!"];
publicVariable "pVar"

And all that would be sent through the network would be ["player","sideChat","zombies!"].

Excuse the possible syntax errors but I am just demonstrating the concept. Are these two methods what you are possibly reffering to?

Or would I have to write specialized functions for each command to be sent over the network accepting multiple parameters (hence the command array method in the first example would have to be used again). What I am concerned with in this idea is the space taken up by the functions (there will by many).

If not can you point me to a code snippet of what you are talking about then?

Share this post


Link to post
Share on other sites

Yes, you would need a seperate pVEH for each command, ...you could could condence them some but I would advise against it.

PVEH works the same way a "fired" EH works, every time the weapon fires the code in the EH is exe.

With pVEH when you update the var and braudcast it with PV the EH will fire and run your code.

The great thing about it is like in the fired EH the engine passes information to the EH, we can pass info to our pVEH as well.

That's the big upside to the CBA system, it can pass a whole array of data to the EH and it only uses one internal cba var.

I'm at work, so I can't write you an example, but if some else hasent by the time I get home I will.

Share this post


Link to post
Share on other sites

You could get the best (lowest) network traffic probably by using numbers to describe what the message is and then send any arguments along. However, I like the CBA event based system. It might be slightly less network efficient, but then I usually don't send messages often at short intervals:

["ZmbAtt", {
 (_this select 0) sideChat "Zombies are attacking us!";
}] call CBA_fnc_addEventHandler,

To send the msg:

["ZmbAtt", [player]] call CBA_fnc_globalEvent

It is not too difficult to set up a similar system if you do not use CBA. I even have a 100 line script that gives me the exact functionality.

However, I don't understand why you need to send anything at all. You say you want to send data based on the fired event handler? Well the fired event handler accepts a global argument (only hit and killed don't) so you can just add the event hander for the relevant units on all machines meaning no need for (manual) network traffic?

Share this post


Link to post
Share on other sites

publicVariable "TAG_p_WithoutParameter";

"TAG_p_WithoutParameter" addPublicVariableEventHandler
{
hintSilent "PVEH without parameter";
};

TAG_p_WithParameter = 4711;

publicVariable "TAG_p_WithParameter";

"TAG_p_WithParameter" addPublicVariableEventHandler
{
_parameter = _this select 1;
_message = format["PVEH with parameter: %1",_parameter];
hintSilent _message;
};

TAG_p_WithMultipleParameters = [4711,4722];

publicVariable "TAG_p_WithMultipleParameters";

"TAG_p_WithMultipleParameters" addPublicVariableEventHandler
{
_parameters = _this select 1;
_parameterOne = _parameters select 0;
_parameterTwo = _parameters select 1;
_message = format["PVEH with multiple parameters: 1: %1; 2: %2",_parameterOne,_parameterTwo];
hintSilent _message;
};

Share this post


Link to post
Share on other sites

Hold on... with the simple code that I am sending - i.e. spawn, switchMove and say commands, wouldn't that amount to the same size as the parameter arrays? (Since the strings for the animation to play or player to use are the longest length). Would writing code into a string, then sending it through the network, then using PVEH to compile that string work? (for small commands)

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  

×