SpecOp9 0 Posted March 17, 2013 Would this be possible? I want the script to read a list of playable characters, pick a random player from the list, and then execute a script (giving him abilities) that only that player has. I really need to learn scripting because I hate asking these questions. Share this post Link to post Share on other sites
sxp2high 22 Posted March 17, 2013 (edited) You learn by asking... nothing wrong with it :) Select random player _playerList = if (isMuliplayer) then { playableUnits; } else { switchableUnits; }; // For testing in editor mostly _randomPlayer = _playerList call BIS_fnc_selectRandom; _null = [_randomPlayer] execVM "thescript.sqf"; thescript.sqf _player = _this select 0; if (!(local _player)) exitWith {}; // Just in case ... the rest goes here ... Edit: That example was a bit too basic, I think... here is a bit more practical one: Init.sqf // Remote local script execution function btk_fnc_MPexecVMLocal = { private ["_player"]; _player = _this select 0; if (local _player) then { _null = [] execVM "thescript.sqf"; }; }; // Let the server select a player if (isServer) { _playerList = if (isMuliplayer) then { playableUnits; } else { switchableUnits; }; // For testing in editor mostly _randomPlayer = _playerList call BIS_fnc_selectRandom; [[_randomPlayer], "btk_fnc_MPexecVMLocal"] call BIS_fnc_mp; }; Edited March 17, 2013 by sxp2high Share this post Link to post Share on other sites
SpecOp9 0 Posted March 17, 2013 (edited) Thanks sxp, I changed "thescript.sqf" to camera.sqf just for testing, is there anything else I need to change? Much to my dismay I'm starting to be able to read code and somewhat understand what each line does. Edited March 17, 2013 by SpecOp9 Share this post Link to post Share on other sites
sxp2high 22 Posted March 17, 2013 Wrote that from the top of my head without testing, but... nope, should be good to go like that. Share this post Link to post Share on other sites
SpecOp9 0 Posted March 17, 2013 I cut the mission down to 1 player and 1 playable just to narrow it down to a 50/50 chance of a camera.sqf, but it doesn't seem to wanna execute :( Share this post Link to post Share on other sites
sxp2high 22 Posted March 17, 2013 (edited) Oops, sorry, I forgot a then after isServer, and there was also a typo :D :D Here you go: // Remote local script execution function btk_fnc_MPexecVMLocal = { private ["_player"]; _player = _this select 0; if (local _player) then { _null = [] execVM "camera.sqf"; }; }; // Let the server select a player if (isServer) then { _playerList = if (isMultiplayer) then { playableUnits; } else { switchableUnits; }; // For testing in editor mostly _randomPlayer = _playerList call BIS_fnc_selectRandom; [[_randomPlayer], "btk_fnc_MPexecVMLocal"] call BIS_fnc_mp; }; However, in the editor it will always execute because of the local check. To better test it, or in general, you can change if (local _player) then { to if (player == _player) then { Edited March 17, 2013 by sxp2high Share this post Link to post Share on other sites
SpecOp9 0 Posted March 18, 2013 Awesome, worked. I'll be sure to credit you in the mission credits! Share this post Link to post Share on other sites