Dzou Sisohvat 0 Posted May 15, 2016 Hi everyone. I have some basic knowledge of arma 3 scripting, but this one is really beyond me. I have been trying to make this thing work in numerous ways during the last 3 days but had no success whatsoever. Basically what I am trying to do is: I am creating a MP mission that involves a few police cars. When a player uses addAction ["Lightbar On", "lightbar.sqf]; it turns on the lightbar for the police car. But the problem is that works just locally, and i really want it to sync between all the clients on a dedicated server. My question is, is there a simple-ish way to "suggest" to clients that they should locally exectute a script for that individual car. Well, my attempts were all in vain, now I would kindly ask for some help. If my way of doing it is wrong, is there some better way. This is the lightbar.sqf i borrowed for testing purposes: /* File: fn_copLights.sqf Author: [GSN] Pager & [GSN] Paronity Website: GSNGaming.com Date Created: 2.24.2015 Date Modified: 3.3.2015 v1.3 */ private ["_veh","_lightRed","_lightWhite","_lightBlue","_lightsOn","_brightnessHigh","_brightnessLow","_attach","_leftLights","_rightLights","_type","_attenuation"]; _veh = (_this select 0); _type = typeOf _veh; _sun = (sunOrMoon < 1); if (isNil "_veh" || isNull _veh || !(_veh getVariable "lights")) exitWith {}; _lightRed = [255, 0, 0]; _lightWhite = [255, 255, 255]; _lightBlue = [0, 0, 255]; if (_sun) then { _brightnessLow = 0; _brightnessHigh = 10; _attenuation = [0.001, 3000, 0, 125000]; } else { _brightnessLow = 0; _brightnessHigh = 60; _attenuation = [0.001, 3000, 0, 500000]; }; _flashes = 3; _flashOn = 0.1; _flashOff = 0.001; _leftLights = []; _rightLights = []; _attach = { _isLight = _this select 0; _color = _this select 1; _position = _this select 2; _light = "#lightpoint" createVehicleLocal getPos _veh; _light setLightBrightness 0; _light setLightAmbient [0,0,0]; _light setLightAttenuation _attenuation; _light setLightIntensity 1000; _light setLightFlareSize 1; _light setLightFlareMaxDistance 150; _light setLightUseFlare true; _light setLightDayLight true; switch (_color) do { case "red": { _light setLightColor _lightRed; }; case "white": { _light setLightColor _lightWhite; }; case "blue": { _light setLightColor _lightBlue; }; }; if (_isLight) then { _leftLights pushBack [_light, _position]; } else { _rightLights pushBack [_light, _position]; }; _light lightAttachObject [_veh, _position]; }; switch (_type) do { case "C_Offroad_01_F": { [false, "red", [-0.44, 0, 0.525]] call _attach; [true, "blue", [0.345, 0, 0.525]] call _attach; [false, "red", [0.575, -2.95, -0.77]] call _attach; [true, "blue", [-0.645, -2.95, -0.77]] call _attach; [false, "white", [0.61, 2.2825, -0.355]] call _attach; [true, "white", [-0.695, 2.2825, -0.355]] call _attach; }; case "C_SUV_01_F": { [false, "red", [-0.39, 2.28, -0.52]] call _attach; [true, "blue", [0.38, 2.28, -0.52]] call _attach; [false, "red", [-0.86, -2.75, -0.18]] call _attach; [true, "blue", [0.86, -2.75, -0.18]] call _attach; [false, "white", [0.8, 1.95, -0.48]] call _attach; [true, "white", [-0.8, 1.95, -0.48]] call _attach; }; case "C_Hatchback_01_sport_F": { [false, "red", [-0.03, -0, 0.2]] call _attach; [true, "blue", [-0.03, -0, 0.2]] call _attach; [false, "red", [-0.8, -2.25, -0.3]] call _attach; [true, "blue", [0.78, -2.25, -0.3]] call _attach; [false, "white", [0.75, 1.615, -0.52]] call _attach; [true, "white", [-0.8, 1.615, -0.525]] call _attach; }; case "B_MRAP_01_F": { [false, "red", [-0.85, -0.9, 0.6]] call _attach; [true, "blue", [0.85, -0.9, 0.6]] call _attach; [true, "red", [-0.93, -2.8, 0.6]] call _attach; [false, "blue", [0.93, -2.8, 0.6]] call _attach; [true, "white", [-0.85, 1.475, -0.75]] call _attach; [false, "white", [0.85, 1.475, -0.75]] call _attach; }; }; _lightsOn = true; while {(alive _veh)} do { if (!(_veh getVariable "lights")) exitWith {}; if (_lightsOn) then { for [{_i=0}, {_i<_flashes}, {_i=_i+1}] do { { (_x select 0) setLightBrightness _brightnessHigh; } forEach _leftLights; uiSleep _flashOn; { (_x select 0) setLightBrightness _brightnessLow; } forEach _leftLights; uiSleep _flashOff; }; { (_x select 0) setLightBrightness 0; } forEach _leftLights; for [{_i=0}, {_i<_flashes}, {_i=_i+1}] do { { (_x select 0) setLightBrightness _brightnessHigh; } forEach _rightLights; uiSleep _flashOn; { (_x select 0) setLightBrightness _brightnessLow; } forEach _rightLights; uiSleep _flashOff; }; { (_x select 0) setLightBrightness 0; } forEach _rightLights; }; }; { deleteVehicle (_x select 0) } foreach _leftLights; { deleteVehicle (_x select 0) } foreach _rightLights; _leftLights = []; _rightLights = []; Share this post Link to post Share on other sites
bad benson 1733 Posted May 15, 2016 try this: _car addaction ["Lightbar On", { [[_this select 0], "lightbar.sqf"] remoteExec ["execVM", 0, true]; }]; //or _car addaction ["Lightbar On", { [[[_this select 0], "lightbar.sqf"], "BIS_fnc_execVM", true, true] call BIS_fnc_MP; }]; both aren't tested but based on the wiki stuff i found. here are some source links. https://community.bistudio.com/wiki/remoteExec https://community.bistudio.com/wiki/BIS_fnc_execVM https://community.bistudio.com/wiki/BIS_fnc_MP that should get you started at least. Share this post Link to post Share on other sites
Dzou Sisohvat 0 Posted May 15, 2016 Oh god, thank you very much, I now see that i was thinking about this in a completely wrong way. If I could bother you for just one more moment. How would you break that loop so you could actually disable the lights? Share this post Link to post Share on other sites
jshock 513 Posted May 15, 2016 You could use get/setVariable, setVariable on the vehicle check it in the while loop along with the "alive" check, then in lightbar off, set the variable to false. Share this post Link to post Share on other sites
bad benson 1733 Posted May 15, 2016 you need to store the lights preferably with setvariable on the vehicle. but make sure to not set it to global so you can save the lights local to each client locally on the same vehicle (probably confusing as fuck lol). and then do the same as above with a function that deletes those lights. so at the end of the sqf you have above you add this: _car setvariable ["lights", (_leftlights + _rightlights)]; //saving all lights into one single array on the vehicle now you make a second sqf like this _car = _this select 0; _lights = _car getVariable "lights"; //retrieve light array { deletevehicle _x; } foreach _lights; ///delete all lights and that script you run the same as you ran the other one inside he addaction. like so: [[_car], "lights_OFF.sqf"] remoteExec ["execVM", 0, true]; //or [[[_car], "lights_OFF.sqf"], "BIS_fnc_execVM", true, true] call BIS_fnc_MP; none of this is testing like the stuff before but should give you an idea about what i mean. Share this post Link to post Share on other sites
Dzou Sisohvat 0 Posted May 15, 2016 I am so close that i can actually smell it, sorry for nagging (I know i am trying to do something that is far beyond my level) and I promise that I will actually start learning simpler code, but this actually made it possible for me to understand a ton of stuff. Well, the last problem i have, before this can actually get functional is that it's saying that Error undefined variable in expression: _lights Now, my brain cannot understandthat because in this code you clearly defined _lights as _car get variable "lights"; I am confused because i have no idea how to fix it. _car = _this select 0; _lights = _car getVariable "lights"; //retrieve light array { deletevehicle _x; } foreach _lights; ///delete all lights Share this post Link to post Share on other sites
johnnyboy 3797 Posted May 15, 2016 Not sure if this will work, but try the following to set _lights to an empty array first, before you assign it the getvariable value. I vaguely remember having a similar problem with assigning values to arrays. _car = _this select 0; _lights = []; _lights = _car getVariable "lights"; //retrieve light array { deletevehicle _x; } foreach _lights; ///delete all lights Share this post Link to post Share on other sites
bad benson 1733 Posted May 15, 2016 tbh. i didn't really read your script. problem is that i told you to put the code at the end of the script. but the while loop blocks it. so make sure to put the setvariable stuff before the loop. Share this post Link to post Share on other sites