Flightcaptain93 0 Posted December 13, 2016 Hello :) I have this type of code in one of my missions. for "_i" from 1 to 100 do { _nil = [_cs,_hpfirst,_hpsecond,_dest] execVM "scripts\carspawn.sqf"; _number = floor (random 941) + 60; sleep _number; }; In the script different cars with a different amount of passengers are generated. They get waypoints etc. But i think does once the script startet twice it affect the other script. Is it possible to start the script multiple times without having any influence on each other? I´m new into scripting. Thanks guys. Share this post Link to post Share on other sites
R3vo 2654 Posted December 13, 2016 Where's the question? Share this post Link to post Share on other sites
Flightcaptain93 0 Posted December 13, 2016 This is the code of the carspawnscript. I have a roadblock with a bargate. If 1 car is standing infront of it the second car has to hold at an other spot. The car holds infront of the bargate and continues driving if the bargate is opend. But if the second car spawn the first won´t continue after i open the gate... if (isServer) then { _cs = (_this select 0); _hpfirst = (_this select 1); _hpsecond = (_this select 2); _dest = (_this select 3); sleep 1; if (firstpoint) then { sleep 5; }; if (firstpoint) then { firstpoint = false; publicvariableserver "firstpoint"; call ray_traffic_fnc; _driver = driver car; _groupd = group _driver; sleep 1; _wp = _groupd addWaypoint [_hpfirst, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {sleep 1; (((bargate animationPhase "Door_1_rot") == 1) && ((car distance2D bargate) <= 20) && ((speed car) <= 1))}; firstpoint = true; publicvariableserver "firstpoint"; sleep 1; _wp = _groupd addWaypoint [[11509.3,6270.87,0],0]; _wp = _groupd addWaypoint [_dest, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {(car distance2D _dest) <= 50}; {car deleteVehicleCrew _x} forEach crew car; deletevehicle car; } else { if (secondpoint) then { secondpoint = false; publicvariableserver "secondpoint"; call ray_traffic_fnc; _driver = driver car; _groupd = group _driver; _wp = _groupd addWaypoint [_hpsecond, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {sleep 1; firstpoint}; _firstpoint = false; _secondpoint = true; publicvariableserver "firstpoint"; publicvariableserver "secondpoint"; sleep 10; _wp = _groupd addWaypoint [_hpfirst, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {sleep 1; (((bargate animationPhase "Door_1_rot") == 1) && ((car distance2D bargate) <= 20) && ((speed car) <= 1))}; _wp = _groupd addWaypoint [[11509.3,6270.87,0],0]; _firstpoint = true; publicvariableserver "firstpoint"; sleep 1; _wp = _groupd addWaypoint [_dest, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {(car distance2D _dest) <= 50}; {car deleteVehicleCrew _x} forEach crew car; deletevehicle car; } else { hint "NO SPAWN POSSIBLE"; }; }; }; and the traffic_function ray_traffic_fnc = { _cararray = ["C_truck_02_covered_F","C_offroad_01_F","C_SUV_01_F","I_C_Offroad_02_unarmed_F"]; _carspawn = _cararray call BIS_fnc_selectRandom; car = _carspawn createVehicle _cs; car setdir 180; clearweaponcargoglobal car; clearmagazinecargoglobal car; clearitemcargoglobal car; clearbackpackcargoglobal car; _freePositionscargo = car emptyPositions "cargo"; hint format ["Cargoplaces car: %1",_freePositionscargo]; sleep 2; _comander = car emptyPositions "Commander"; _gunner = car emptyPositions "Gunner"; _comgun = _comander + _gunner; _unitcountcar = _freePositionscargo + _comgun + 1; hint format ["Cargo with driver, gunner etc: %1",_unitcountcar]; sleep 2; _randompassenger = floor (random _unitcountcar); hint format ["Crew (minus): %1",_randompassenger]; sleep 2; _crewnumber = _unitcountcar - _randompassenger; hint format ["Crew (spawn): %1",_crewnumber]; sleep 3; for "_i" from 1 to _crewnumber do { grp = creategroup civilian; _man = grp createUnit ["C_Man_casual_4_F_tanoan", _cs, [], 5, "PRIVATE"]; _needofdriver = car emptyPositions "Driver"; if (_needofdriver == 1) then { _man moveindriver car; } else { _man moveincargo car; }; }; }; Share this post Link to post Share on other sites
killzone_kid 1333 Posted December 13, 2016 if (isServer) then { then publicvariableserver "firstpoint"; Not sure why would you do this, your script is already running on server. Share this post Link to post Share on other sites
theend3r 83 Posted December 14, 2016 12 hours ago, Flightcaptain93 said: In the script different cars with a different amount of passengers are generated. They get waypoints etc. But i think does once the script startet twice it affect the other script. Is it possible to start the script multiple times without having any influence on each other? Yes, execVM starts a new scope so the scripts don't disrupt each other as long as you keep using purely local variables (starting with _). Share this post Link to post Share on other sites
Flightcaptain93 0 Posted December 14, 2016 After i switchet the car variable to a local one. _car. The variable _car is first called in my ray_traffic_fnc where the car is spawned... is it possible to give the information about _car into the part of the script after the ray_traffic_fnc?? because now i get the error that the variable _car is not defined... call ray_traffic_fnc; _driver = driver car; Share this post Link to post Share on other sites
Flightcaptain93 0 Posted December 14, 2016 22 hours ago, killzone_kid said: if (isServer) then { then publicvariableserver "firstpoint"; Not sure why would you do this, your script is already running on server. Thanks :) i removed that Share this post Link to post Share on other sites
theend3r 83 Posted December 15, 2016 13 hours ago, Flightcaptain93 said: After i switchet the car variable to a local one. _car. The variable _car is first called in my ray_traffic_fnc where the car is spawned... is it possible to give the information about _car into the part of the script after the ray_traffic_fnc?? because now i get the error that the variable _car is not defined... call ray_traffic_fnc; _driver = driver car; Of course it is, just call the function with parameters: [param1, param2...] call ray_traffic_fnc; (in this case [_car] call ray_traffic_fnc) and define the parameter in the function with either _car = _this select 0 or params["_car"]. 1 Share this post Link to post Share on other sites
Flightcaptain93 0 Posted December 15, 2016 okay i did this but i get still the error that _car is not defined in the line after the ray_traffic_fnc; [_car] call ray_traffic_fnc; //here the _car is spawned and get the information from the car _driver = driver _car; /// <---- here is the script error that _car isnt defined... Share this post Link to post Share on other sites
davidoss 552 Posted December 15, 2016 for "_i" from 1 to 100 do { null = [_cs,_hpfirst,_hpsecond,_dest] execVM "scripts\carspawn.sqf"; _number = floor (random 941) + 60; sleep _number; }; if (isServer) then { _cs = (_this select 0); _hpfirst = (_this select 1); _hpsecond = (_this select 2); _dest = (_this select 3); sleep 1; if (firstpoint) then { sleep 5; }; if (firstpoint) then { firstpoint = false; publicvariableserver "firstpoint"; _car = [_cs] call ray_traffic_fnc; _driver = driver _car; _groupd = group _driver; sleep 1; _wp = _groupd addWaypoint [_hpfirst, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {sleep 1; (((bargate animationPhase "Door_1_rot") == 1) && ((_car distance2D bargate) <= 20) && ((speed _car) <= 1))}; firstpoint = true; publicvariableserver "firstpoint"; sleep 1; _wp = _groupd addWaypoint [[11509.3,6270.87,0],0]; _wp = _groupd addWaypoint [_dest, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {(_car distance2D _dest) <= 50}; {deleteVehicle _x} forEach (crew _car); deletevehicle _car; } else { if (secondpoint) then { secondpoint = false; publicvariableserver "secondpoint"; _car = [_cs] call ray_traffic_fnc; _driver = driver _car; _groupd = group _driver; _wp = _groupd addWaypoint [_hpsecond, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {sleep 1; firstpoint}; _firstpoint = false; _secondpoint = true; publicvariableserver "firstpoint"; publicvariableserver "secondpoint"; sleep 10; _wp = _groupd addWaypoint [_hpfirst, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {sleep 1; (((bargate animationPhase "Door_1_rot") == 1) && ((_car distance2D bargate) <= 20) && ((speed _car) <= 1))}; _wp = _groupd addWaypoint [[11509.3,6270.87,0],0]; _firstpoint = true; publicvariableserver "firstpoint"; sleep 1; _wp = _groupd addWaypoint [_dest, 0]; _wp setWaypointCombatMode "BLUE"; _wp setWaypointSpeed "Limited"; _wp setWaypointBehaviour "CARELESS"; _wp setWaypointtype "MOVE"; waituntil {(_car distance2D _dest) <= 50}; {deleteVehicle _x} forEach (crew _car); deletevehicle _car; } else { hint "NO SPAWN POSSIBLE"; }; }; }; ray_traffic_fnc = { params ["_cs"]; _cararray = ["C_truck_02_covered_F","C_offroad_01_F","C_SUV_01_F","I_C_Offroad_02_unarmed_F"]; _car = (selectRandom _cararray) createVehicle _cs; _car setdir 180; clearweaponcargoglobal _car; clearmagazinecargoglobal _car; clearitemcargoglobal _car; clearbackpackcargoglobal _car; _freePositionscargo = _car emptyPositions "cargo"; hint format ["Cargoplaces car: %1",_freePositionscargo]; sleep 2; _comander = _car emptyPositions "Commander"; _gunner = _car emptyPositions "Gunner"; _comgun = _comander + _gunner; _unitcountcar = _freePositionscargo + _comgun + 1; hint format ["Cargo with driver, gunner etc: %1",_unitcountcar]; sleep 2; _randompassenger = floor (random _unitcountcar); hint format ["Crew (minus): %1",_randompassenger]; sleep 2; _crewnumber = _unitcountcar - _randompassenger; hint format ["Crew (spawn): %1",_crewnumber]; sleep 3; for "_i" from 1 to _crewnumber do { _grp = creategroup civilian; _man = _grp createUnit ["C_Man_casual_4_F_tanoan", _cs, [], 5, "PRIVATE"]; _needofdriver = _car emptyPositions "Driver"; if (_needofdriver == 1) then { _man moveindriver _car; } else { _man moveincargo _car; }; }; _car }; Share this post Link to post Share on other sites
theend3r 83 Posted December 16, 2016 6 hours ago, Flightcaptain93 said: okay i did this but i get still the error that _car is not defined in the line after the ray_traffic_fnc; [_car] call ray_traffic_fnc; //here the _car is spawned and get the information from the car _driver = driver _car; /// <---- here is the script error that _car isnt defined... You only read half of my post, right? Share this post Link to post Share on other sites
Flightcaptain93 0 Posted December 18, 2016 Thanks it worked out :) yeah sorry I got a little bit of false understanding... english isnt my mother language. But it worked after i read it correctly :) thanks Share this post Link to post Share on other sites