Jump to content
Sign in to follow this  
monotone

Run local script command on each client in MP

Recommended Posts

I'm making a script about light object.

I want to create a growing helper when any user in MP call it.

So,my script includes setlightbrightness which works only on executed machine.

I found BIS_fnc_MP but it only works with functions,not commands.

How can I execute "local" commands on every machine?

Edited by Monotone

Share this post


Link to post
Share on other sites

A function can be anything from a one line command to code of several 100th of lines.

- So put your "one liner", :) noting bad about it, in an extra file,

- compile that file on computers needed or everywhere,

- hand the function over to BIS_fnc_MP.

For more specific help, more details are needed.

greetings Na_Palm

Share this post


Link to post
Share on other sites

A function looks like this (let us assume this is in init.sqf):

FUNC_I_WANT_EXECUTED = {

_a_passed_parameter = _this select 0;
hint format ["My function just executed%1",_a_passed_parameter];

};

To use the function somewhere in another script executed everywhere:

[[", because I called it."],"FUNC_I_WANT_EXECUTED",nil,true] spawn BIS_fnc_MP;

or locally:

[", because I called it."] call FUNC_I_WANT_EXECUTED;

Should produce a hint with "My function just executed, because I called it." (assuming I have not made any syntax errors here).

Edited by Jacmac

Share this post


Link to post
Share on other sites

Two options. First create a file called initPlayerLocal.sqf and everything that you have inside that file will run local to the player when they connect to the mission. There you can easily put the command without using BIS_fnc_MP. Second if you call it through a script you try this out.

[[{*Your code*}],"BIS_fnc_Spawn",target,false] spawn BIS_fnc_MP;

Share this post


Link to post
Share on other sites

Shouldn't use BIS_fnc_spawn with fnc_MP. It will work, that's true. But the way it works is overkill and can hurt performance. The way it was explained to me, is that will will be run globally for each person. Not the way you want though. Each person will send the command to everyone else. So if you have 5 players, and you use the code above, it will be executed 25 times. That's the most common useage you see on the BIS forums here, but it's not right.

Much better to make your own function and send that through fnc_MP.

Share this post


Link to post
Share on other sites

BIS_fnc_Spawn shouldn't spawn something globally. That is why I put target in the target parameter for BIS_fnc_MP so it will only execute for that object only.

BIS_fnc_Spawn

private ["_params","_code"];

_params = [];
_code = [_this,0,{},[{},[]]] call bis_fnc_param;

if (typename _code == typename []) then {
_params = [_this,0,[]] call bis_fnc_param;
_code = [_this,1,{},[{}]] call bis_fnc_param;
};

_params call _code

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  

×