Gudsawn 93 Posted August 18, 2013 I need to execute a script on all clients using: ["myScript.sqf","BIS_fnc_execVM",true,true] spawn BIS_fnc_MP; However, the script also requires some parameters (_unit). How would I pass this information to myScript.sqf while still using BIS_fnc_MP? Local example: _nul = [_unit] execVM "myScript.sqf"; J Share this post Link to post Share on other sites
galzohar 31 Posted August 18, 2013 https://community.bistudio.com/wiki/BIS_fnc_MP Should have all the examples you need. If you still don't understand, feel free to ask :) Share this post Link to post Share on other sites
Gudsawn 93 Posted August 18, 2013 https://community.bistudio.com/wiki/BIS_fnc_MPShould have all the examples you need. If you still don't understand, feel free to ask :) Thanks for your reply. I've already checked this page which has been very useful until now. I tried: ["{hint "Hello World!";}","BIS_fnc_spawn",true,true] spawn BIS_fnc_MP; as stated on the BI page. However, it doesn't appear to work. I then tried: ["{_nul = [_unit] execVM ""myScript.sqf"";}","BIS_fnc_spawn",true,true] spawn BIS_fnc_MP; Which still doesn't appear to work. Any suggestions? Share this post Link to post Share on other sites
kylania 567 Posted August 18, 2013 Don't send entire scripts via BIS_fnc_MP, make your script a function instead and just pass the params: [["string", object, [1,2,3]], "MY_fnc_customFunction", nil, true] spawn BIS_fnc_MP; So something like: [_unit, "MY_fnc_myScript"] spawn BIS_fnc_MP; What's _unit though? Because having everyone run a script on the same object might not be what you want. Share this post Link to post Share on other sites
Larrow 2805 Posted August 18, 2013 (edited) However, the script also requires some parameters (_unit). How would I pass this information to myScript.sqf while still using BIS_fnc_MP?You need to provide the params bis_fnc_exevm needs which is [params to send to script, scriptName]; [[_unit, "myScript.sqf"],"BIS_fnc_execVM",true,true] spawn BIS_fnc_MP; BIS_fnc_execVM executes _unit execVM "myscript.sqf" myscript.sqf _passedunit = _this or [[[_unit], "myScript.sqf"],"BIS_fnc_execVM",true,true] spawn BIS_fnc_MP; BIS_fnc_execVM executes [_unit] execVM "myscript.sqf" myscript.sqf _passedunit = _this select 0; Edited August 18, 2013 by Larrow Share this post Link to post Share on other sites
Gudsawn 93 Posted August 18, 2013 Don't send entire scripts via BIS_fnc_MP, make your script a function instead and just pass the params: [["string", object, [1,2,3]], "MY_fnc_customFunction", nil, true] spawn BIS_fnc_MP; So something like: [_unit, "MY_fnc_myScript"] spawn BIS_fnc_MP; What's _unit though? Because having everyone run a script on the same object might not be what you want. Ah, excellent. I made the script into a function and everything works perfectly. _unit is the name of a player which has been 'jailed'. So when a player is jailed all players should then see something like: "John Smith was jailed" in the server global chat or as a hint. Share this post Link to post Share on other sites
Gudsawn 93 Posted August 19, 2013 (edited) I've now ran into another issue. // myScript.sqf player setPos (getPos _unit); Putting a script into a function and running it via: MY_fnc_do = compile preprocessFile "myScript.sqf"; [_unit], "MY_fnc_do", nil, true] spawn BIS_fnc_MP; Works. However, the functions only ever seem to be run locally and won't run on all clients as it should. When I execute the scripts however (instead of calling them as functions), everything works as it should: [[[_unit],"myScript.sqf"],"BIS_fnc_execVM",nil,true] spawn BIS_fnc_MP; Why is this? I could just stick with executing scripts (since it works) rather than calling functions, but it wouldn't be as efficient. Edited August 19, 2013 by JamieG Share this post Link to post Share on other sites
Tajin 348 Posted August 19, 2013 I guess its because _unit is a local variable that is not available on the other clients. Use a global variable instead and you should be fine. Share this post Link to post Share on other sites
kylania 567 Posted August 19, 2013 You're not passing _unit at all, and you're making something like that persistent which you don't want. Your examples didn't work since you called it wrong in the first part (yay for turning off script errors huh?) So you're intending to have a function that teleports all players to a specific _unit? JAM_fnc_allPlayersToUnit = { _unit = _this select 0; player setPos (getPos _unit); }; [[_unit], "JAM_fnc_allPlayersToUnit"] spawn BIS_fnc_MP; You don't need the nil since it defaults to all players anyway. You don't want the true (the persistent flag), since you don't want this to happen to ever player that joins the game do you? Share this post Link to post Share on other sites
Larrow 2805 Posted August 19, 2013 (edited) // myScript.sqf [color="#FF0000"][b]_unit = _this select 0;[/b][/color] player setPos (getPos _unit); MY_fnc_do = compile preprocessFile "myScript.sqf"; [color="#FF0000"][b][[/b][/color][_unit], "MY_fnc_do", nil, true] spawn BIS_fnc_MP; Edited August 19, 2013 by Larrow Share this post Link to post Share on other sites
kylania 567 Posted August 19, 2013 _unit is the name of a player which has been 'jailed'. So when a player is jailed all players should then see something like: "John Smith was jailed" in the server global chat or as a hint. For this you don't need BIS_fnc_MP at all, nor functions really. A publicVaribleEventhandler can do it. init.sqf: // From Occupation "GlobalHint" addPublicVariableEventHandler { private ["_GHint"]; _GHint = _this select 1; hint parseText format["%1", _GHint]; }; To global hint people: _unit = name player; // or name of whoever. _myHint = format["<t size='1.25'>%1</t> <t size='1.25' color='#ff0000'>was jailed!</t>", _unit]; GlobalHint = _myHint; publicVariable "GlobalHint"; hintSilent parseText _myHint; Share this post Link to post Share on other sites