davidoss 552 Posted September 9, 2015 Hi. I want to ask you fellows how to do it better : _handle_damage = [] spawn { while {!isNull highjackveh} do { if (({isPlayer _x AND (_x distance highjackveh) > 600} count (playableUnits + switchableUnits)) != 0) then { highjackveh allowDamage false; } else { highjackveh allowDamage true; }; sleep 20; }; }; This is part of side mission which i create just now. I wanna make this vehicle temporary indestructible because of AI driving skills. In this way the code is repeat constantly until player shows up near. There are no need to repeat the code if the vehicle is already indestructible. Share this post Link to post Share on other sites
R3vo 2654 Posted September 9, 2015 So the AI drives the car until the player steals it right? As soon as a player drives the car, the damage should be activated again? Or is the player supposed to ambush this car to destroy it? Share this post Link to post Share on other sites
davidoss 552 Posted September 9, 2015 There will be ( i hope) a convoy with 3 vehicles driving somewhere ( in reality around the map). In the middle of convoy a truck full witch civilians which are escorted by insurgents. Players need to release safely the civilians . For now i have just a little bit of it done. private ["_startpos", "_safePos", "_hostages", "_unit0", "_unit1", "_unit2", "_unit3", "_unit4", "_unit5", "_unit6", "_unit7", "_unit8", "_unit9", "_unit10", "_unit11", "_unit12", "_unit14_driver", "_unit15", "_handle_fuel", "_handle_damage", "_highjackgrp_waypoints", "_markerhighjackveh", "_highjackvehpos", "_trg"]; _startpos = [minarete_1, minarete_2, minarete_3, minarete_4, minarete_5, minarete_6, minarete_7] call BIS_fnc_selectRandom; _safePos = [getPos _startpos, 20, 100, 30, 0, 0, 0] call BIS_fnc_findSafePos; highjackveh = "RHS_Civ_Truck_02_covered_F" createVehicle _safePos; highjackveh allowDamage false; _hostages = createGroup Civilian; _unit0 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _safePos, [], 0, "FORM"]; _unit1 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _safePos, [], 0, "FORM"]; _unit2 = _hostages createUnit ["LOP_Tak_Civ_Man_04", _safePos, [], 0, "FORM"]; _unit3 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _safePos, [], 0, "FORM"]; _unit4 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _safePos, [], 0, "FORM"]; _unit5 = _hostages createUnit ["LOP_Tak_Civ_Man_04", _safePos, [], 0, "FORM"]; _unit6 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _safePos, [], 0, "FORM"]; _unit7 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _safePos, [], 0, "FORM"]; _unit8 = _hostages createUnit ["LOP_Tak_Civ_Man_04", _safePos, [], 0, "FORM"]; _unit9 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _safePos, [], 0, "FORM"]; _unit10 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _safePos, [], 0, "FORM"]; _unit11 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _safePos, [], 0, "FORM"]; _unit12 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _safePos, [], 0, "FORM"]; { _x moveInCargo highjackveh; } forEach units _hostages; highjackgrp = createGroup RESISTANCE; _unit14_driver = highjackgrp createUnit ["LOP_AM_Infantry_AR", _safePos, [], 0, "FORM"]; _unit15 = highjackgrp createUnit ["LOP_AM_Infantry_Rifleman", _safePos, [], 0, "FORM"]; highjackgrp addVehicle highjackveh; _unit14_driver moveInDriver highjackveh; _unit15 moveInCargo highjackveh; _unit14_driver addEventHandler ["killed", " private ['_spawnPos', '_defencegrp']; _spawnPos = highjackveh modelToWorld [0, -6, 0]; _defencegrp = [_spawnPos, INDEPENDENT, (configfile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Infantry' >> 'LOP_AM_Rifle_squad')] call BIS_fnc_spawnGroup; [_defencegrp,_spawnPos] call BIS_fnc_taskDefend; "]; _handle_fuel = [] spawn { while {!isNull highjackveh} do { if ((getDammage highjackveh) == 0 AND (fuel highjackveh) < 0.5) then { highjackveh setFuel 1; }; sleep 100; }; }; _handle_damage = [] spawn { while {!isNull highjackveh} do { if (({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0) then { highjackveh allowDamage true; }; sleep 20; }; }; _highjackgrp_waypoints = [] spawn { private ["_waypoint0", "_waypoint1", "_waypoint2", "_waypoint3", "_waypoint4", "_waypoint5", "_waypoint6"]; _waypoint0 = highjackgrp addwaypoint [getpos minarete_4, 50]; _waypoint0 setwaypointtype "MOVE"; _waypoint1 = highjackgrp addwaypoint [getpos minarete_2, 50]; _waypoint1 setwaypointtype "MOVE"; _waypoint2 = highjackgrp addwaypoint [getpos minarete_7, 50]; _waypoint2 setwaypointtype "MOVE"; _waypoint3 = highjackgrp addwaypoint [getpos minarete_5, 50]; _waypoint3 setwaypointtype "MOVE"; _waypoint4 = highjackgrp addwaypoint [getpos minarete_1, 50]; _waypoint4 setwaypointtype "MOVE"; _waypoint5 = highjackgrp addwaypoint [getpos minarete_3, 50]; _waypoint5 setwaypointtype "MOVE"; _waypoint6 = highjackgrp addwaypoint [getpos minarete_6, 50]; _waypoint6 setwaypointtype "CYCLE"; }; [west, "release_prisoners", ["Find and release hostages from insurgents convoy. Avoid civilian casualties.", "Capture I.C.C", "Find and release hostages"], objNull, true] spawn BIS_fnc_taskCreate; ["release_prisoners", "CREATED",true] call BIS_fnc_taskSetState; _markerhighjackveh = createMarker ["ICCVeh", getPos highjackveh]; _markerhighjackveh setMarkerType "c_car"; _markerhighjackveh setMarkerColor "ColorGreen"; _markerhighjackveh setMarkerText "I.C.C"; _markerhighjackveh setMarkerSize [1,1]; _highjackvehpos = [] spawn { while {!isNull highjackveh} do { "ICCVeh" setMarkerPos getpos highjackveh; sleep 2; }; }; waitUntil { sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0}; [[hq_logic_papa,"do_assault"],"sideRadio",WEST,false,false] call BIS_fnc_MP; waitUntil { sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0 AND !(alive _unit14_driver)}; _trg = createTrigger ["EmptyDetector", getPos highjackveh]; _trg setTriggerArea [300, 300, 0, false]; _trg setTriggerActivation ["GUER", "NOT PRESENT", false]; _trg setTriggerStatements ["this", "", ""]; waitUntil {sleep 1; triggerActivated _trg}; ["release_prisoners", "SUCCEEDED",true] spawn BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa,"obj_secure"],"sideRadio",WEST,false,false] call BIS_fnc_MP; Share this post Link to post Share on other sites
davidoss 552 Posted September 9, 2015 A clip how it looks at this moment : https://drive.google.com/file/d/0ByRTbY28pkpiRDJrb2RKdlRoTjA/view?usp=sharing Share this post Link to post Share on other sites
davidoss 552 Posted September 11, 2015 HI. I am almost done with my script. // side mission rescue hostages. private ["_startpos", "_hostages", "_highjackgrp", "_highjackgrp1", "_highjackgrp2", "_unit0", "_unit1", "_unit2", "_unit3", "_unit4", "_unit5", "_unit6", "_unit7", "_unit8", "_unit9", "_unit10", "_unit11", "_unit12", "_unit14_driver", "_unit15", "_spawnPos_highjackescortveh1", "_unit16_driver", "_unit17", "_spawnPos_highjackescortveh2", "_unit18_driver", "_unit19", "_handle_fuel", "_handle_damage", "_marker1", "_marker2", "_marker3", "_marker4", "_marker5", "_marker6", "_marker7", "_marker8", "_marker9", "_marker10", "_marker11", "_marker12", "_marker13", "_marker14", "_marker15", "_marker16", "_marker17", "_marker18", "_marker19", "_marker20", "_marker21", "_marker22", "_marker23", "_marker24", "_marker25", "_marker26", "_marker27", "_marker28", "_marker29", "_marker30", "_marker31", "_marker32", "_marker33", "_marker34", "_marker35", "_markerhighjackveh", "_highjackvehpos", "_script_handler","_wp"]; //define start position _startpos = [10256.5,6382.36,0]; // spawn truck highjackveh = "RHS_Civ_Truck_02_covered_F" createVehicle _startpos; highjackveh setdir 275; highjackveh allowDamage false; //spawn hostages _hostages = createGroup Civilian; _unit0 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit1 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit2 = _hostages createUnit ["LOP_Tak_Civ_Man_04", _startpos, [], 0, "FORM"]; _unit3 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit4 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit5 = _hostages createUnit ["LOP_Tak_Civ_Man_04", _startpos, [], 0, "FORM"]; _unit6 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit7 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit8 = _hostages createUnit ["LOP_Tak_Civ_Man_04", _startpos, [], 0, "FORM"]; _unit9 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit10 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit11 = _hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit12 = _hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; {_x moveInCargo highjackveh;} forEach units _hostages; //spawn truck crew ans assign _highjackgrp = createGroup RESISTANCE; _unit14_driver = _highjackgrp createUnit ["LOP_AM_Infantry_AR", _startpos, [], 0, "FORM"]; _unit15 = _highjackgrp createUnit ["LOP_AM_Infantry_Rifleman", _startpos, [], 0, "FORM"]; _unit14_driver setUnitAbility 1; _highjackgrp addVehicle highjackveh; _unit14_driver moveInDriver highjackveh; _unit15 moveInCargo highjackveh; //spawn escort vehicles _spawnPos_highjackescortveh1 = highjackveh modelToWorld [0, -40, 0]; highjackescortveh1 = "LOP_AM_Offroad_M2" createVehicle _spawnPos_highjackescortveh1; highjackescortveh1 setdir 275; highjackescortveh1 allowDamage false; _highjackgrp1 = createGroup RESISTANCE; _unit16_driver = _highjackgrp1 createUnit ["LOP_AM_Infantry_AR", _spawnPos_highjackescortveh1, [], 0, "FORM"]; _unit17 = _highjackgrp1 createUnit ["LOP_AM_Infantry_Rifleman", _spawnPos_highjackescortveh1, [], 0, "FORM"]; _unit16_driver setUnitAbility 1; _highjackgrp1 addVehicle highjackescortveh1; _unit16_driver moveInDriver highjackescortveh1; _unit17 moveInGunner highjackescortveh1; _spawnPos_highjackescortveh2 = highjackveh modelToWorld [0, +40, 0]; highjackescortveh2 = "LOP_AM_Landrover_M2" createVehicle _spawnPos_highjackescortveh2; highjackescortveh2 setdir 283; highjackescortveh2 allowDamage false; _highjackgrp2 = createGroup RESISTANCE; _unit18_driver = _highjackgrp2 createUnit ["LOP_AM_Infantry_AR", _spawnPos_highjackescortveh2, [], 0, "FORM"]; _unit19 = _highjackgrp2 createUnit ["LOP_AM_Infantry_Rifleman", _spawnPos_highjackescortveh2, [], 0, "FORM"]; _unit18_driver setUnitAbility 1; _highjackgrp2 addVehicle highjackescortveh2; _unit18_driver moveInDriver highjackescortveh2; _unit19 moveInGunner highjackescortveh2; //adding eventhandler for each escort unit. It will fire only on one unit and when truck is not destroyed and truck is not moving { _x addEventHandler ["killed", " if (isNil {defencegrp} AND (speed highjackveh) < 1 AND (getDammage highjackveh) < 1) exitWith { private ['_spawnPos']; _spawnPos = highjackveh modelToWorld [0, -5, 0]; defencegrp = [_spawnPos, INDEPENDENT, (configfile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Infantry' >> 'LOP_AM_Rifle_squad')] call BIS_fnc_spawnGroup; [defencegrp,_spawnPos] call BIS_fnc_taskDefend; }; "]; } forEach [_unit14_driver,_unit15,_unit16_driver,_unit17,_unit18_driver,_unit19]; // handle with fuel _handle_fuel = [] spawn { while {!isNull highjackveh} do { { if ((getDammage _x) == 0 AND (fuel _x) < 0.5) then { _x setFuel 1; }; } forEach [highjackveh,highjackescortveh1,highjackescortveh2]; sleep 100; }; }; //handle with dammage. On start all vehicles are indestructible until player are near (handling with ai driving skill) _handle_damage = [] spawn { while {!isNull highjackveh} do { if (({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0) then { highjackveh allowDamage true; highjackescortveh1 allowDamage true; highjackescortveh2 allowDamage true; }; sleep 20; }; }; // create markers for route using Convoy by norrin http://www.armaholic.com/page.php?id=20265 _marker1 = createMarker ["wp1",[9313.21,6604.17]]; _marker2 = createMarker ["wp2",[8248.84,7784.32]]; _marker3 = createMarker ["wp3",[6858.49,8915.2]]; _marker4 = createMarker ["wp4",[5525.81,8913.52]]; _marker5 = createMarker ["wp5",[5610.42,9860.87]]; _marker6 = createMarker ["wp6",[4252.51,9487.58]]; _marker7 = createMarker ["wp7",[3748.94,8921.31]]; _marker8 = createMarker ["wp8",[3696.01,9277.4]]; _marker9 = createMarker ["wp9",[3282.91,9711.89]]; _marker10 = createMarker ["wp10",[3082.37,9952.91]]; _marker11 = createMarker ["wp11",[3862.27,10529.9]]; _marker12 = createMarker ["wp12",[4192.62,11127.4]]; _marker13 = createMarker ["wp13",[4132.38,11747]]; _marker14 = createMarker ["wp14",[4203.8,11765.8]]; _marker15 = createMarker ["wp15",[4234.51,11832]]; _marker16 = createMarker ["wp16",[4642.13,11984.1]]; _marker17 = createMarker ["wp17",[4664.61,11540.1]]; _marker18 = createMarker ["wp18",[5372.24,11299.7]]; _marker19 = createMarker ["wp19",[6103.61,11864.5]]; _marker20 = createMarker ["wp20",[6234.92,11714]]; _marker21 = createMarker ["wp21",[6030.51,11501.5]]; _marker22 = createMarker ["wp22",[6327.49,11292.8]]; _marker23 = createMarker ["wp23",[5611.29,9863.66]]; _marker24 = createMarker ["wp24",[5516.58,8925.04]]; _marker25 = createMarker ["wp25",[5980.63,7979.54]]; _marker26 = createMarker ["wp26",[5938.36,7393.25]]; _marker27 = createMarker ["wp27",[6762.17,7333.62]]; _marker28 = createMarker ["wp28",[6730.54,6052.08]]; _marker29 = createMarker ["wp29",[8340.01,5481.34]]; _marker30 = createMarker ["wp30",[8910.6,5322.77]]; _marker31 = createMarker ["wp31",[8977.98,5799.68]]; _marker32 = createMarker ["wp32",[9177.67,6126.36]]; _marker33 = createMarker ["wp33",[9126.86,6756.43]]; _marker34 = createMarker ["wp34",[9308.72,6608.08]]; _marker35 = createMarker ["wp35",[10446.9,6317.56]]; //execute norrin convoy script [["wp1","wp2","wp3","wp4","wp5","wp6","wp7","wp8","wp9","wp10","wp11","wp12","wp13","wp14","wp15","wp16","wp17","wp18","wp19","wp20","wp21","wp22","wp23","wp24","wp25","wp26","wp27","wp28","wp29","wp30","wp31","wp32","wp33","wp34","wp35"],[highjackescortveh2,highjackveh,highjackescortveh1],false] execVM "convoyDefend\convoyDefend_init.sqf"; //create task [west, "release_prisoners", ["Find and release hostages from insurgents convoy. Avoid civilian casualties.", "Capture I.C.C", "Find and release hostages"], objNull, true] spawn BIS_fnc_taskCreate; ["release_prisoners", "CREATED",true] call BIS_fnc_taskSetState; //create truck mobile marker _markerhighjackveh = createMarker ["ICCVeh", getPos highjackveh]; _markerhighjackveh setMarkerType "c_car"; _markerhighjackveh setMarkerColor "ColorGreen"; _markerhighjackveh setMarkerText "I.C.C"; _markerhighjackveh setMarkerSize [1,1]; _highjackvehpos = [] spawn { while {!isNull highjackveh} do { "ICCVeh" setMarkerPos getpos highjackveh; sleep 2; }; }; //check if any player is near . If not - wait waitUntil { sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0}; [[hq_logic_papa,"do_assault"],"sideRadio",WEST,false,false] call BIS_fnc_MP; //check if convoy is ambushed. Waiting until driver is dead . Is that a nonsense? waitUntil { sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0 AND !(alive _unit14_driver)}; // create trigger if convoy is ambushed and dont moving trg = createTrigger ["EmptyDetector", getPos highjackveh]; trg setTriggerArea [400, 400, 0, false]; trg setTriggerActivation ["GUER", "NOT PRESENT", false]; trg setTriggerStatements ["this", "", ""]; // handle task failed/succeeded _script_handler = [] spawn { waitUntil { sleep 1; triggerActivated trg }; }; waitUntil {sleep 1; ({alive _x} count units _hostages) < 6 || scriptDone _script_handler}; if (({alive _x} count units _hostages) < 6 ) then { ["release_prisoners", "FAILED", true] call BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa,"task_failed"],"sideRadio",WEST,false,false] call BIS_fnc_MP; terminate _script_handler; } else { ["release_prisoners", "SUCCEEDED", true] call BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa,"good_job"],"sideRadio",WEST,false,false] call BIS_fnc_MP; {_x action ["getOut", highjackveh];} forEach units _hostages; _wp =_hostages addWaypoint [getMarkerPos "wp35", 0]; _wp setWaypointType "MOVE"; }; sleep 200; // cleanup {deleteVehicle _x; _x = nil;} forEach [highjackveh,highjackescortveh1,highjackescortveh2,trg]; {deleteVehicle _x;} forEach units _highjackgrp; {deleteVehicle _x;} forEach units _highjackgrp1; {deleteVehicle _x;} forEach units _highjackgrp2; {deleteVehicle _x;} forEach units defencegrp; {deleteVehicle _x;} forEach units _hostages; {deleteGroup _x; _x = nil;} forEach [_hostages,_highjackgrp,_highjackgrp1,_highjackgrp2,defencegrp]; terminate _handle_fuel; terminate _handle_damage; {deleteMarker _x;} forEach [_marker1_marker2,_marker3,_marker4,_marker5,_marker6,_marker7,_marker8,_marker9,_marker10,_marker11,_marker12,_marker13,_marker14,_marker15,_marker16,_marker17,_marker18,_marker19,_marker20,_marker21,_marker22,_marker23,_marker24,_marker25,_marker26,_marker27,_marker28,_marker29,_marker30,_marker31,_marker32,_marker33,_marker34,_marker35,_markerhighjackveh]; ["release_prisoners", west] call BIS_fnc_deleteTask; terminate _highjackvehpos; sleep 200; [] execVM "scripts\crash.sqf"; Unfortunately i have no idea how to define that the vehicle with civilians has no driver. The problem is that the script need to wait until the driver are not there ( killed or something). Then is trigger created and defense units spawned. I had used the condition : waitUntil { sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0 AND !(alive _unit14_driver)}; to define that the driver is dead but what if players not did that? How to find better way? Share this post Link to post Share on other sites
R3vo 2654 Posted September 11, 2015 isNull driver car; Perhaps that helps. Share this post Link to post Share on other sites
davidoss 552 Posted September 11, 2015 This is not changing anything i need there something like waitUntil { sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0 AND (!(alive _unit14_driver) OR !(alive _unit17) OR !(alive _unit19))}; Is that code alright? Share this post Link to post Share on other sites
R3vo 2654 Posted September 11, 2015 If it works, then it's probably alright ;) Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 11, 2015 To reduce code and max out performance: waitUntil { sleep 1; 1 == { if (_x distance highjackveh < 600) exitWith {1} } count allPlayers && //equivalent to "and", used in almost all programming languages 1 == { if (!alive _x) exitWith {1} } count [_unit14_driver, _unit17, _unit19]; }; Share this post Link to post Share on other sites
nimrod_z 8 Posted September 12, 2015 To reduce code and max out performance: waitUntil { sleep 1; 1 == { if (_x distance highjackveh < 600) exitWith {1} } count allPlayers && //equivalent to "and", used in almost all programming languages 1 == { if (!alive _x) exitWith {1} } count [_unit14_driver, _unit17, _unit19]; }; there isnt any reason to run a loop inside an event handler at all. if you want to make the vehicle not take damage or limit the damage use something like this. _veh addEventHandler ["HandleDamage", {if (_this select 4 isEqualTo "" && (side (_this select 0)) isEqualTo resistance) then {(_this select 2)/100;};}]; all this basically says is that if no projectile hit the vehicle and a unit that is side of resistance is driving it, divide the damage by 100. thats what i use in a mission of mine to keep the cars/trucks from being wrecked from the AI driving 30 seconds after mission starts...:) for your varaible you want to set when a player takes the vehicle you are better off using the getIn/getOut event handlers for that. Share this post Link to post Share on other sites
davidoss 552 Posted September 12, 2015 Thanks noticed that. The mission is done. If someone of you guys have any idea how to make it better please help. // side mission rescue hostages. private ["_startpos", "_highjackgrp", "_highjackgrp1", "_highjackgrp2", "_unit0", "_unit1", "_unit2", "_unit3", "_unit4", "_unit5", "_unit6", "_unit7", "_unit8", "_unit9", "_unit10", "_unit11", "_unit12", "_unit14_driver", "_unit15", "_spawnPos_highjackescortveh1", "_unit16_driver", "_unit17", "_spawnPos_highjackescortveh2", "_unit18_driver", "_unit19", "_handle_fuel", "_handle_damage", "_marker1", "_marker2", "_marker3", "_marker4", "_marker5", "_marker6", "_marker7", "_marker8", "_marker9", "_marker10", "_marker11", "_marker12", "_marker13", "_marker14", "_marker15", "_marker16", "_marker17", "_marker18", "_marker19", "_marker20", "_marker21", "_marker22", "_marker23", "_marker24", "_marker25", "_marker26", "_marker27", "_marker28", "_marker29", "_marker30", "_marker31", "_marker32", "_marker33", "_marker34", "_marker35", "_markerhighjackveh", "_highjackvehpos", "_script_handler", "_wp", "_hostages_behaviour"]; //define start position _startpos = [10256.5,6382.36,0]; // spawn truck highjackveh = "RHS_Civ_Truck_02_covered_F" createVehicle _startpos; highjackveh setdir 275; highjackveh allowDamage false; //spawn hostages hostages = createGroup Civilian; _unit0 = hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit1 = hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit2 = hostages createUnit ["LOP_Tak_Civ_Man_04", _startpos, [], 0, "FORM"]; _unit3 = hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit4 = hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit5 = hostages createUnit ["LOP_Tak_Civ_Man_04", _startpos, [], 0, "FORM"]; _unit6 = hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit7 = hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit8 = hostages createUnit ["LOP_Tak_Civ_Man_04", _startpos, [], 0, "FORM"]; _unit9 = hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit10 = hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; _unit11 = hostages createUnit ["LOP_Tak_Civ_Man_01", _startpos, [], 0, "FORM"]; _unit12 = hostages createUnit ["LOP_Tak_Civ_Man_02", _startpos, [], 0, "FORM"]; { _x assignAsCargo highjackveh; _x moveInCargo highjackveh } forEach units hostages; //spawn truck crew ans assign _highjackgrp = createGroup RESISTANCE; _unit14_driver = _highjackgrp createUnit ["LOP_AM_Infantry_AR", _startpos, [], 0, "FORM"]; _unit15 = _highjackgrp createUnit ["LOP_AM_Infantry_Rifleman", _startpos, [], 0, "FORM"]; _unit14_driver setUnitAbility 1; _highjackgrp addVehicle highjackveh; _unit14_driver moveInDriver highjackveh; _unit15 moveInCargo highjackveh; //spawn escort vehicles _spawnPos_highjackescortveh1 = highjackveh modelToWorld [0, -40, 0]; highjackescortveh1 = "LOP_AM_Offroad_M2" createVehicle _spawnPos_highjackescortveh1; highjackescortveh1 setdir 275; highjackescortveh1 allowDamage false; _highjackgrp1 = createGroup RESISTANCE; _unit16_driver = _highjackgrp1 createUnit ["LOP_AM_Infantry_AR", _spawnPos_highjackescortveh1, [], 0, "FORM"]; _unit17 = _highjackgrp1 createUnit ["LOP_AM_Infantry_Rifleman", _spawnPos_highjackescortveh1, [], 0, "FORM"]; _unit16_driver setUnitAbility 1; _highjackgrp1 addVehicle highjackescortveh1; _unit16_driver moveInDriver highjackescortveh1; _unit17 moveInGunner highjackescortveh1; _spawnPos_highjackescortveh2 = highjackveh modelToWorld [0, +40, 0]; highjackescortveh2 = "LOP_AM_Landrover_M2" createVehicle _spawnPos_highjackescortveh2; highjackescortveh2 setdir 283; highjackescortveh2 allowDamage false; _highjackgrp2 = createGroup RESISTANCE; _unit18_driver = _highjackgrp2 createUnit ["LOP_AM_Infantry_AR", _spawnPos_highjackescortveh2, [], 0, "FORM"]; _unit19 = _highjackgrp2 createUnit ["LOP_AM_Infantry_Rifleman", _spawnPos_highjackescortveh2, [], 0, "FORM"]; _unit18_driver setUnitAbility 1; _highjackgrp2 addVehicle highjackescortveh2; _unit18_driver moveInDriver highjackescortveh2; _unit19 moveInGunner highjackescortveh2; //adding eventhandler for each escort unit. It will fire only on one unit and when truck is not destroyed and truck is not moving { _x addEventHandler ["killed", " if (isNil {defencegrp} AND (speed highjackveh) < 1 AND (getDammage highjackveh) < 1) exitWith { private ['_spawnPos', '_spawnPos2', '_findroad', '_spawnonroad']; _spawnPos = highjackveh modelToWorld [0, -4, 0]; defencegrp = [_spawnPos, INDEPENDENT, (configfile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Infantry' >> 'LOP_AM_Rifle_squad')] call BIS_fnc_spawnGroup; [defencegrp,_spawnPos] call BIS_fnc_taskDefend; _spawnPos2 = highjackveh modelToWorld [0, -300, 0]; _findroad = _spawnPos2 nearRoads 100; if ((count _findroad) != 0) then { _spawnonroad = getpos (_findroad select 0); }else{ _spawnonroad = [_spawnPos2, 0, 100, 15, 0, 0, 0] call BIS_fnc_findSafePos; }; defencegrp2 = [_spawnonroad, INDEPENDENT, (configfile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Motorized' >> 'LOP_AM_Motor_squad_LR')] call BIS_fnc_spawnGroup; groupveh = vehicle leader defencegrp2; [defencegrp2,_spawnPos] call BIS_fnc_taskDefend; }; "]; } forEach [_unit14_driver,_unit15,_unit16_driver,_unit17,_unit18_driver,_unit19]; // handle with fuel _handle_fuel = [] spawn { while {!isNull highjackveh} do { { if ((getDammage _x) == 0 AND (fuel _x) < 0.5) then { _x setFuel 1; }; } forEach [highjackveh,highjackescortveh1,highjackescortveh2]; sleep 100; }; }; //handle with dammage. On start all vehicles are indestructible until player are near (handling with ai driving skill) _handle_damage = [] spawn { while {!isNull highjackveh} do { if (({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0) then { highjackveh allowDamage true; highjackescortveh1 allowDamage true; highjackescortveh2 allowDamage true; }; sleep 20; }; }; // create markers for route using Convoy by norrin http://www.armaholic.com/page.php?id=20265 _marker1 = createMarker ["wp1",[9313.21,6604.17]]; _marker2 = createMarker ["wp2",[8248.84,7784.32]]; _marker3 = createMarker ["wp3",[6858.49,8915.2]]; _marker4 = createMarker ["wp4",[5525.81,8913.52]]; _marker5 = createMarker ["wp5",[5610.42,9860.87]]; _marker6 = createMarker ["wp6",[4252.51,9487.58]]; _marker7 = createMarker ["wp7",[3748.94,8921.31]]; _marker8 = createMarker ["wp8",[3696.01,9277.4]]; _marker9 = createMarker ["wp9",[3282.91,9711.89]]; _marker10 = createMarker ["wp10",[3082.37,9952.91]]; _marker11 = createMarker ["wp11",[3862.27,10529.9]]; _marker12 = createMarker ["wp12",[4192.62,11127.4]]; _marker13 = createMarker ["wp13",[4132.38,11747]]; _marker14 = createMarker ["wp14",[4203.8,11765.8]]; _marker15 = createMarker ["wp15",[4234.51,11832]]; _marker16 = createMarker ["wp16",[4642.13,11984.1]]; _marker17 = createMarker ["wp17",[4664.61,11540.1]]; _marker18 = createMarker ["wp18",[5372.24,11299.7]]; _marker19 = createMarker ["wp19",[6103.61,11864.5]]; _marker20 = createMarker ["wp20",[6234.92,11714]]; _marker21 = createMarker ["wp21",[6030.51,11501.5]]; _marker22 = createMarker ["wp22",[6327.49,11292.8]]; _marker23 = createMarker ["wp23",[5611.29,9863.66]]; _marker24 = createMarker ["wp24",[5516.58,8925.04]]; _marker25 = createMarker ["wp25",[5980.63,7979.54]]; _marker26 = createMarker ["wp26",[5938.36,7393.25]]; _marker27 = createMarker ["wp27",[6762.17,7333.62]]; _marker28 = createMarker ["wp28",[6730.54,6052.08]]; _marker29 = createMarker ["wp29",[8340.01,5481.34]]; _marker30 = createMarker ["wp30",[8910.6,5322.77]]; _marker31 = createMarker ["wp31",[8977.98,5799.68]]; _marker32 = createMarker ["wp32",[9177.67,6126.36]]; _marker33 = createMarker ["wp33",[9126.86,6756.43]]; _marker34 = createMarker ["wp34",[9308.72,6608.08]]; _marker35 = createMarker ["wp35",[10446.9,6317.56]]; //execute norrin convoy script [["wp1","wp2","wp3","wp4","wp5","wp6","wp7","wp8","wp9","wp10","wp11","wp12","wp13","wp14","wp15","wp16","wp17","wp18","wp19","wp20","wp21","wp22","wp23","wp24","wp25","wp26","wp27","wp28","wp29","wp30","wp31","wp32","wp33","wp34","wp35"],[highjackescortveh2,highjackveh,highjackescortveh1],false] execVM "convoyDefend\convoyDefend_init.sqf"; //create task [west, "release_prisoners", ["Find and release hostages from insurgents convoy. Avoid civilian casualties.", "Capture I.C.C", "Find and release hostages"], objNull, true] spawn BIS_fnc_taskCreate; ["release_prisoners", "CREATED",true] call BIS_fnc_taskSetState; //create truck mobile marker _markerhighjackveh = createMarker ["ICCVeh", getPos highjackveh]; _markerhighjackveh setMarkerType "c_car"; _markerhighjackveh setMarkerColor "ColorGreen"; _markerhighjackveh setMarkerText "I.C.C"; _markerhighjackveh setMarkerSize [1,1]; _highjackvehpos = [] spawn { while {!isNull highjackveh} do { "ICCVeh" setMarkerPos getpos highjackveh; sleep 2; }; }; //check if any player is near . If not - wait waitUntil { sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0}; [[hq_logic_papa,"do_assault"],"sideRadio",WEST,false,false] call BIS_fnc_MP; //check if convoy is ambushed. waitUntil { sleep 1; (speed highjackveh) < 1 AND (!(alive _unit14_driver) OR !(alive _unit17) OR !(alive _unit19))}; _highjackgrp leaveVehicle highjackveh; [_highjackgrp,getpos highjackveh] call BIS_fnc_taskDefend; // create trigger if convoy is ambushed and dont moving trg = createTrigger ["EmptyDetector", getPos highjackveh]; trg setTriggerArea [400, 400, 0, false]; trg setTriggerActivation ["GUER", "NOT PRESENT", false]; trg setTriggerStatements ["this", "", ""]; // empty the truck _hostages_behaviour = [] spawn { { unassignVehicle _x } forEach crew highjackveh; waitUntil {sleep 1; (count (crew highjackveh) == 0)}; { _x switchMove "AmovPincMstpSnonWnonDnon"} forEach units hostages; }; // handle task failed/succeeded _script_handler = [] spawn { waitUntil { sleep 1; triggerActivated trg }; }; waitUntil {sleep 1; ({alive _x} count units hostages) < 6 || scriptDone _script_handler}; if (({alive _x} count units hostages) < 6 ) then { ["release_prisoners", "FAILED", true] call BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa,"task_failed"],"sideRadio",WEST,false,false] call BIS_fnc_MP; terminate _script_handler; {_x switchMove ""} forEach units hostages; _wp = hostages addWaypoint [getMarkerPos "wp35", 0]; _wp setWaypointType "MOVE"; } else { ["release_prisoners", "SUCCEEDED", true] call BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa,"good_job"],"sideRadio",WEST,false,false] call BIS_fnc_MP; {_x switchMove ""} forEach units hostages; _wp = hostages addWaypoint [getMarkerPos "wp35", 0]; _wp setWaypointType "MOVE"; }; sleep 200; // cleanup {deleteVehicle _x; _x = nil;} forEach [highjackveh,highjackescortveh1,highjackescortveh2,trg]; {deleteVehicle _x} forEach units _highjackgrp; {deleteVehicle _x} forEach units _highjackgrp1; {deleteVehicle _x} forEach units _highjackgrp2; {deleteVehicle _x} forEach crew groupveh + [groupveh]; {deleteVehicle _x} forEach units defencegrp2; {deleteVehicle _x} forEach units defencegrp; {deleteVehicle _x} forEach units hostages; {deleteGroup _x} forEach [hostages,_highjackgrp,_highjackgrp1,_highjackgrp2,defencegrp]; {_x = nil} forEach [hostages,defencegrp]; terminate _handle_fuel; terminate _handle_damage; {deleteMarker _x} forEach [_marker1,_marker2,_marker3,_marker4,_marker5,_marker6,_marker7,_marker8,_marker9,_marker10,_marker11,_marker12,_marker13,_marker14,_marker15,_marker16,_marker17,_marker18,_marker19,_marker20,_marker21,_marker22,_marker23,_marker24,_marker25,_marker26,_marker27,_marker28,_marker29,_marker30,_marker31,_marker32,_marker33,_marker34,_marker35,_markerhighjackveh]; ["release_prisoners", west] call BIS_fnc_deleteTask; terminate _highjackvehpos; terminate _hostages_behaviour; sleep 200; [] execVM "scripts\crash.sqf"; Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 12, 2015 Here's an updated version. I can still be optimized, especially regarding all the global variables, but my desire to sleep finally got bigger than my desire to script, so here it is: //side mission rescue hostages - updated by Heeeere's Johnny!. private ["_startPos", "_highjackgrp", "_highjackgrp1", "_highjackgrp2", "_unit14_driver", "_unit15", "_spawnPos_highjackescortveh1", "_unit16_driver", "_unit17", "_spawnPos_highjackescortveh2", "_unit18_driver", "_unit19", "_handle_fuel", "_handle_damage", "_markerhighjackveh", "_highjackvehpos", "_script_handler", "_wp", "_hostages_behaviour"]; //define start position _startPos = [10256.5,6382.36,0]; //spawn truck highjackveh = "RHS_Civ_Truck_02_covered_F" createVehicle _startPos; highjackveh setDir 275; highjackveh allowDamage false; //spawn hostages hostages = createGroup civilian; //create 13 units with random class name number _numbers = [1, 2, 4]; for "_i" from 0 to 12 do { _unit = hostages createUnit [format ["LOP_Tak_Civ_Man_0%1", _numbers select floor random 3], _startPos, [], 0, "FORM"]; _unit assignAsCargo highjackveh; _unit moveInCargo highjackveh; }; //spawn truck crew and assign _highjackgrp = createGroup resistance; _unit14_driver = _highjackgrp createUnit ["LOP_AM_Infantry_AR", _startPos, [], 0, "FORM"]; _unit15 = _highjackgrp createUnit ["LOP_AM_Infantry_Rifleman", _startPos, [], 0, "FORM"]; _unit14_driver setUnitAbility 1; _highjackgrp addVehicle highjackveh; _unit14_driver moveInDriver highjackveh; _unit15 moveInCargo highjackveh; //spawn escort vehicles _spawnPos_highjackescortveh1 = highjackveh modelToWorld [0, -40, 0]; highjackescortveh1 = "LOP_AM_Offroad_M2" createVehicle _spawnPos_highjackescortveh1; highjackescortveh1 setDir 275; highjackescortveh1 allowDamage false; _highjackgrp1 = createGroup resistance; _unit16_driver = _highjackgrp1 createUnit ["LOP_AM_Infantry_AR", _spawnPos_highjackescortveh1, [], 0, "FORM"]; _unit17 = _highjackgrp1 createUnit ["LOP_AM_Infantry_Rifleman", _spawnPos_highjackescortveh1, [], 0, "FORM"]; _unit16_driver setUnitAbility 1; _highjackgrp1 addVehicle highjackescortveh1; _unit16_driver moveInDriver highjackescortveh1; _unit17 moveInGunner highjackescortveh1; _spawnPos_highjackescortveh2 = highjackveh modelToWorld [0, +40, 0]; highjackescortveh2 = "LOP_AM_Landrover_M2" createVehicle _spawnPos_highjackescortveh2; highjackescortveh2 setDir 283; highjackescortveh2 allowDamage false; _highjackgrp2 = createGroup resistance; _unit18_driver = _highjackgrp2 createUnit ["LOP_AM_Infantry_AR", _spawnPos_highjackescortveh2, [], 0, "FORM"]; _unit19 = _highjackgrp2 createUnit ["LOP_AM_Infantry_Rifleman", _spawnPos_highjackescortveh2, [], 0, "FORM"]; _unit18_driver setUnitAbility 1; _highjackgrp2 addVehicle highjackescortveh2; _unit18_driver moveInDriver highjackescortveh2; _unit19 moveInGunner highjackescortveh2; //adding eventhandler for each escort unit. It will fire only on one unit and when truck is not destroyed and truck is not moving { _x addEventHandler ["killed", { if (isNil {defencegrp} and (speed highjackveh) < 1 and (damage highjackveh) < 1) exitWith { private ['_spawnPos', '_spawnPos2', '_findRoad', '_spawnOnRoad']; _spawnPos = highjackveh modelToWorld [0, -4, 0]; defencegrp = [_spawnPos, independent, (configFile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Infantry' >> 'LOP_AM_Rifle_squad')] call BIS_fnc_spawnGroup; [defencegrp, _spawnPos] call BIS_fnc_taskDefend; _spawnPos2 = highjackveh modelToWorld [0, -300, 0]; _findRoad = _spawnPos2 nearRoads 100; if (count _findRoad != 0) then { _spawnOnRoad = getPos (_findRoad select 0); } else { _spawnOnRoad = [_spawnPos2, 0, 100, 15, 0, 0, 0] call BIS_fnc_findSafePos; }; defencegrp2 = [_spawnOnRoad, independent, (configFile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Motorized' >> 'LOP_AM_Motor_squad_LR')] call BIS_fnc_spawnGroup; groupveh = vehicle leader defencegrp2; [defencegrp2, _spawnPos] call BIS_fnc_taskDefend; }; }]; } forEach [_unit14_driver,_unit15,_unit16_driver,_unit17,_unit18_driver,_unit19]; //handle fuel _handle_fuel = [] spawn { while {!isNull highjackveh} do { { if (damage _x == 0 and fuel _x < 0.5) then { _x setFuel 1; }; } forEach [highjackveh, highjackescortveh1, highjackescortveh2]; sleep 100; }; }; //handle damage. On start all vehicles are indestructible until player are near (handling ai driving skill) _handle_damage = [] spawn { while {!isNull highjackveh} do { // if (({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0) then { if ({if (_x distance highjackveh < 600) exitWith {1}} count allPlayers != 0) then { highjackveh allowDamage true; highjackescortveh1 allowDamage true; highjackescortveh2 allowDamage true; }; sleep 20; }; }; // create markers for route using Convoy by norrin http://www.armaholic.com/page.php?id=20265 _routePositions = [ [9313.21,6604.17], [8248.84,7784.32], [6858.49,8915.2], [5525.81,8913.52], [5610.42,9860.87], [4252.51,9487.58], [3748.94,8921.31], [3696.01,9277.4], [3282.91,9711.89], [3082.37,9952.91], [3862.27,10529.9], [4192.62,11127.4], [4132.38,11747], [4203.8,11765.8], [4234.51,11832], [4642.13,11984.1], [4664.61,11540.1], [5372.24,11299.7], [6103.61,11864.5], [6234.92,11714], [6030.51,11501.5], [6327.49,11292.8], [5611.29,9863.66], [5516.58,8925.04], [5980.63,7979.54], [5938.36,7393.25], [6762.17,7333.62], [6730.54,6052.08], [8340.01,5481.34], [8910.6,5322.77], [8977.98,5799.68], [9177.67,6126.36], [9126.86,6756.43], [9308.72,6608.08], [10446.9,6317.56] ]; _routeMarkers = []; _waypointNames = []; { _name = format ["wp%1", _forEachIndex + 1]; _waypointNames pushBack _name; _routeMarkers pushBack createMarker [_name, _x]; } forEach _routePositions; //execute norrin convoy script [_waypointNames, [highjackescortveh2, highjackveh, highjackescortveh1], false] execVM "convoyDefend\convoyDefend_init.sqf"; //create task [ west, "release_prisoners", [ "Find and release hostages from insurgents convoy. Avoid civilian casualties.", "Capture I.C.C", "Find and release hostages" ], objNull, true ] spawn BIS_fnc_taskCreate; ["release_prisoners", "CREATED", true] call BIS_fnc_taskSetState; //create truck mobile marker _markerhighjackveh = createMarker ["ICCVeh", getPos highjackveh]; _markerhighjackveh setMarkerType "c_car"; _markerhighjackveh setMarkerColor "ColorGreen"; _markerhighjackveh setMarkerText "I.C.C"; //_markerhighjackveh setMarkerSize [1,1]; //not needed for icons, only if you setMarkerType and/or setMarkerBrush _highjackvehpos = [] spawn { while {!isNull highjackveh} do { "ICCVeh" setMarkerPos getPos highjackveh; sleep 2; }; }; //check if any player is near . If not - wait // waitUntil {sleep 1;({isPlayer _x AND (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0}; waitUntil {sleep 1; {if (_x distance highjackveh < 600) exitWith {1}} count allPlayers != 0}; [[hq_logic_papa, "do_assault"], "sideRadio", west, false, false] call BIS_fnc_MP; //check if convoy is ambushed. //waitUntil {sleep 1; (speed highjackveh) < 1 AND (!(alive _unit14_driver) OR !(alive _unit17) OR !(alive _unit19))}; waitUntil {sleep 1; speed highjackveh < 1 and {if (!alive _x) exitWith {1}} count [_unit14_driver, _unit17, _unit19] != 0}; _highjackgrp leaveVehicle highjackveh; [_highjackgrp,getpos highjackveh] call BIS_fnc_taskDefend; //create trigger if convoy is ambushed and doesn't move trg = createTrigger ["EmptyDetector", getPos highjackveh]; trg setTriggerArea [400, 400, 0, false]; trg setTriggerActivation ["GUER", "NOT PRESENT", false]; trg setTriggerStatements ["this", "", ""]; //empty the truck _hostages_behaviour = [] spawn { { unassignVehicle _x } forEach crew highjackveh; waitUntil {sleep 1; count crew highjackveh == 0}; {_x switchMove "AmovPincMstpSnonWnonDnon"} forEach units hostages; }; //handle task failed/succeeded waitUntil {sleep 1; ({alive _x} count units hostages) < 6 || triggerActivated trg}; if (({alive _x} count units hostages) < 6 ) then { ["release_prisoners", "FAILED", true] call BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa, "task_failed"], "sideRadio", west, false, false] call BIS_fnc_MP; terminate _script_handler; {_x switchMove ""} forEach units hostages; _wp = hostages addWaypoint [getMarkerPos "wp35", 0]; _wp setWaypointType "MOVE"; } else { ["release_prisoners", "SUCCEEDED", true] call BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa, "good_job"], "sideRadio", west, false, false] call BIS_fnc_MP; {_x switchMove ""} forEach units hostages; _wp = hostages addWaypoint [getMarkerPos "wp35", 0]; _wp setWaypointType "MOVE"; }; sleep 200; // cleanup {deleteVehicle _x} forEach [highjackveh, highjackescortveh1, highjackescortveh2, trg]; {deleteVehicle _x} forEach units _highjackgrp; {deleteVehicle _x} forEach units _highjackgrp1; {deleteVehicle _x} forEach units _highjackgrp2; {deleteVehicle _x} forEach crew groupveh; //What should (crew groupveh + [groupveh]) be doing? {deleteVehicle _x} forEach units defencegrp2; {deleteVehicle _x} forEach units defencegrp; {deleteVehicle _x} forEach units hostages; {deleteGroup _x} forEach [hostages, _highjackgrp, _highjackgrp1, _highjackgrp2, defencegrp]; {_x = nil} forEach [hostages, defencegrp]; terminate _handle_fuel; terminate _handle_damage; {deleteMarker _x} forEach (_routeMarkers + [_markerhighjackveh]); ["release_prisoners", west] call BIS_fnc_deleteTask; terminate _highjackvehpos; terminate _hostages_behaviour; sleep 200; [] execVM "scripts\crash.sqf"; Just a few hints, please don't take it as smartass-dom. :) Get a little more consistent with camelCase, not only on long words, but everywhere where it's reasonable, like in "setDir" or "configFile" or "_spawnOnRoad" ... For reasons of distinction, use CAPITAL_LETTERS only for #define'ed values. addEventHandler also takes code as second array member, so I'd very much recommend using that instead of a string. getDammage is a very old and incorrectly spelled command which only exists for legacy reasons. Use damage instead, which does the exact same. Don't be careless with indention. Indention should make the code more readable, but it won't if you indent arbitrarily as you did in some lines in that script. Avoid unnecessary brackets. Logical commands (&&, ||, ==, !=, >, >=, <, <=, ...) always evaluate last, so "if ((damage _x) == 0)" is the same as "if (damage _x == 0)" Make spaces between commas and words, because this: [highjackveh,highjackescortveh1,highjackescortveh2] just looks like a long snake of letters, while this: [highjackveh, highjackescortveh1, highjackescortveh2] at least gives you a chance. Use line breaks if the line becomes too long. 200 characters in a single line is too long and has the potential to be worse readable than if you made line breaks where reasonable. I don't recommend the way I did it with your "... spawn BIS_fnc_taskCreate" line, but it's how I do it. setMarkerSize is not needed for markers with icons, only if you setMarkerType and/or setMarkerBrush or you need the size for other reasons. {_x = nil} forEach [hostages, defencegrp]; The above doesn't do what you'd expect, because _x is not the element itself, but rather a copy, just as if you'd copy a variable with: "_copy = +_someVar". And finally, keep things simple and reduce redundance where reasonable. Putting 35 "createMarker" statements, which do the exact same, means that you've got to change 35 lines if you wanted to change something about the markers. Keep it simple and let a loop do the redundant work. 2 Share this post Link to post Share on other sites
davidoss 552 Posted September 13, 2015 Thank you very much Heeeere's johnny!.Awesome knowledge. PS. {deleteVehicle _x} forEach crew groupveh; //What should (crew groupveh + [groupveh]) be doing? In this way i got delete the group vehicle too. Deleting group units and crew left behind the ofroad. Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 13, 2015 Thank you very much Heeeere's johnny!. Awesome knowledge. Things you learns over time. ;) I hope the script still works though. Not that I've disimproved it. :D Share this post Link to post Share on other sites
davidoss 552 Posted September 13, 2015 Tested and is working perfect. 2 more for improvement. :) Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 13, 2015 Thank you very much Heeeere's johnny!. Awesome knowledge. PS. {deleteVehicle _x} forEach crew groupveh; //What should (crew groupveh + [groupveh]) be doing? In this way i got delete the group vehicle too. Deleting group units and crew left behind the ofroad. Oh, I see. Clever. ;) Share this post Link to post Share on other sites
Larrow 2822 Posted September 13, 2015 Could turn those spawned damage and fuel threads into eventHandlers. (This was my attempt at cleaning up your code last night) private[ "_fnc_vehEHs", "_fnc_crewEH", "_drivers", "_vehicles", "_groups", "_startPos", "_hostages", "_civs", "_highjackveh", "_type", "_unit", "_highjackgrp", "_driver", "_markers", "_markerhighjackveh", "_trg", "_result", "_wp" ]; _fnc_vehEHs = { //handle with dammage. _this setVariable [ "damagedEH", _this addEventHandler [ "HandleDamage", { if ( isNil "attackGO" ) then { 0 }else{ _veh = _this select 0; _veh removeEventHandler [ "HandleDamage", _veh getVariable "damageEH" ]; _veh removeEventHandler [ "Fuel", _veh getVariable "fuelEH" ]; _this select 2 }; }] ]; // handle with fuel _this setVariable [ "fuelEH", _this addEventHandler [ "Fuel", { ( _this select 0 ) setFuel 1; }] ]; }; _fnc_crewEH = { _this addEventHandler ["killed", format[ " if (isNil {defencegrp} AND (speed %1) < 1 AND (damage %1) < 1) exitWith { _spawnPos = %1 modelToWorld [0, -4, 0]; defencegrp = [_spawnPos, INDEPENDENT, (configfile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Infantry' >> 'LOP_AM_Rifle_squad')] call BIS_fnc_spawnGroup; [defencegrp,_spawnPos] call BIS_fnc_taskDefend; _spawnPos2 = %1 modelToWorld [0, -300, 0]; _findroad = _spawnPos2 nearRoads 100; _spawnonroad = [ [_spawnPos2, 0, 100, 15, 0, 0, 0] call BIS_fnc_findSafePos, getpos (_findroad select 0) ] select ((count _findroad) > 0); defencegrp2 = [_spawnonroad, INDEPENDENT, (configfile >> 'CfgGroups' >> 'Indep' >> 'LOP_AM' >> 'Motorized' >> 'LOP_AM_Motor_squad_LR')] call BIS_fnc_spawnGroup; groupveh = vehicle leader defencegrp2; [defencegrp2,_spawnPos] call BIS_fnc_taskDefend; };", ( _vehicles select 0 ) call BIS_fnc_objectVar] ]; }; _drivers = []; _vehicles = []; _groups = []; //define start position _startpos = [10256.5,6382.36,0]; //spawn escort vehicles { //private[ "_spawnPos", "_veh", "_group", "_gunner" ]; _spawnPos = [ _startPos, ( _x select 1 ), 275 ] call BIS_fnc_relPos; _veh = createVehicle [ _x select 0, _spawnPos, [], 0, "NONE" ]; _veh setDir 275; _vehicles pushBack _veh; _veh call _fnc_vehEHs; _group = createGroup resistance; _group addVehicle _veh; _groups pushBack _group; _driver = _group createUnit ["LOP_AM_Infantry_AR", _spawnPos, [], 0, "FORM"]; _driver setUnitAbility 1; _driver moveInDriver _veh; _drivers pushBack _driver; _gunner = _group createUnit ["LOP_AM_Infantry_Rifleman", _spawnPos, [], 0, "FORM"]; if ( _forEachIndex isEqualTo 0 ) then { _gunner moveInCargo _veh; }else{ _gunner moveInGunner _veh; }; { _x call _fnc_crewEH; } forEach [ _driver, _gunner ]; }forEach [ [ "RHS_Civ_Truck_02_covered_F", 0 ], [ "LOP_AM_Landrover_M2", +40 ], [ "LOP_AM_Offroad_M2", -40 ] ]; _highjackveh = _vehicles select 0; _highjackgrp = _groups select 0; //spawn hostages _hostages = createGroup civilian; _groups pushBack _hostages; _civs = [ "LOP_Tak_Civ_Man_01", "LOP_Tak_Civ_Man_02", "LOP_Tak_Civ_Man_04" ]; for "_i" from 0 to 12 do { _type = _civs select ( _i % count _civs ); _unit = _hostages createUnit [_type, _startpos, [], 0, "FORM"]; _unit assignAsCargo _highjackveh; _unit moveInCargo _highjackveh; }; // create markers for route using Convoy by norrin http://www.armaholic.com/page.php?id=20265 _markers = []; { _markers pushBack ( createMarker [ format[ "wp%1", _forEachIndex ], _x ] ); }forEach [ [9313.21,6604.17], [8248.84,7784.32], [6858.49,8915.2], [5525.81,8913.52], [5610.42,9860.87], [4252.51,9487.58], [3748.94,8921.31], [3696.01,9277.4], [3282.91,9711.89], [3082.37,9952.91], [3862.27,10529.9], [4192.62,11127.4], [4132.38,11747], [4203.8,11765.8], [4234.51,11832], [4642.13,11984.1], [4664.61,11540.1], [5372.24,11299.7], [6103.61,11864.5], [6234.92,11714], [6030.51,11501.5], [6327.49,11292.8], [5611.29,9863.66], [5516.58,8925.04], [5980.63,7979.54], [5938.36,7393.25], [6762.17,7333.62], [6730.54,6052.08], [8340.01,5481.34], [8910.6,5322.77], [8977.98,5799.68], [9177.67,6126.36], [9126.86,6756.43], [9308.72,6608.08], [10446.9,6317.56] ]; //execute norrin convoy script [_markers,_vehicles, false] execVM "convoyDefend\convoyDefend_init.sqf"; //create task [ west, "release_prisoners", [ "Find and release hostages from insurgents convoy. Avoid civilian casualties.", "Capture I.C.C", "Find and release hostages" ], objNull, true ] spawn BIS_fnc_taskCreate; ["release_prisoners", "CREATED", true] call BIS_fnc_taskSetState; //create truck mobile marker _markerhighjackveh = createMarker ["ICCVeh", getPos _highjackveh]; _markerhighjackveh setMarkerType "c_car"; _markerhighjackveh setMarkerColor "ColorGreen"; _markerhighjackveh setMarkerText "I.C.C"; _highjackveh spawn { while {!isNull _this} do { "ICCVeh" setMarkerPos getPos _this; sleep 2; }; }; //check if any player is near . If not - wait waitUntil { sleep 1; ({isPlayer _x && (_x distance highjackveh) < 600} count (playableUnits + switchableUnits)) != 0 }; [[hq_logic_papa,"do_assault"],"sideRadio",west,false,false] call BIS_fnc_MP; //Disable vehicles damageEH and fuelEH next time they get hit attackGO = true; //check if convoy is ambushed. waitUntil { sleep 1; (speed _highjackveh) < 1 && { !alive _x }count _drivers > 0 }; _highjackgrp leaveVehicle _highjackveh; [_highjackgrp, getPos _highjackveh] call BIS_fnc_taskDefend; // create trigger if convoy is ambushed and not moving _trg = createTrigger ["EmptyDetector", getPos _highjackveh]; _trg setTriggerArea [400, 400, 0, false]; _trg setTriggerActivation ["GUER", "NOT PRESENT", false]; _trg setTriggerStatements ["this", "", ""]; // empty the truck [ _highjackveh, _hostages ] spawn { _veh = _this select 0; _hostages = _this select 1; { unassignVehicle _x } forEach crew _veh; waitUntil {sleep 1; (count (crew _veh) isEqualTo 0)}; { _x switchMove "AmovPincMstpSnonWnonDnon"} forEach units _hostages; }; //Wait for end conditions waitUntil {sleep 1; ({alive _x} count units _hostages) < 6 || triggerActivated _trg }; //Win/Fail _result = [ [ "SUCCEEDED", "good_job" ], [ "FAILED", "task_failed" ] ] select !triggerActivated _trg; ["release_prisoners", _result select 0, true] call BIS_fnc_taskSetState; sleep 5; [[hq_logic_papa,_result select 1],"sideRadio",west,false,false] call BIS_fnc_MP; {_x switchMove ""} forEach units _hostages; _wp = _hostages addWaypoint [getMarkerPos "wp34", 0]; _wp setWaypointType "MOVE"; sleep 200; // cleanup { deleteVehicle _x } forEach _vehicles + crew groupveh + [groupveh]; { { deleteVehicle _x; }forEach units _x; deleteGroup _x; }forEach _groups + [defencegrp, defencegrp2]; { missionNamespace setVariable [ _x, nil ]; }forEach [ "defencegrp", "defencegrp2", "groupveh", "attackGO" ]; { deleteMarker _x; } forEach _markers + [ _markerhighjackveh ]; ["release_prisoners", west] call BIS_fnc_deleteTask; sleep 200; [] execVM "scripts\crash.sqf";Got rid of alot of your global variables. Like johnny i reworked your marker creation. Moved vehicle and unit creation into a loop to save repeated code.Maybe able to pick up a few ideas from it. Whether it works straight off i dont know, totally untested. Share this post Link to post Share on other sites
davidoss 552 Posted September 13, 2015 Holy shit . You guys want to blew up my mind. I do not understand my script anymore. :blink: Larrow your script works but there is a main problem because the truck goes after spawn ahead escort vehicles, he should be between them. I have no idea now how to organize it. :D There are also some EH errors : Error in expression < { 0 }else{ _veh = _this select 0; _veh removeEventHandler [ "HandleDamage", _ve> 16:14:10 Error position: <removeEventHandler [ "HandleDamage", _ve> 16:14:10 Error Type Any, needed Numeric Anyway I do not knew how to thanks you .I had to use global variables because i have no idea how to passing local variables into EH. One more time - big thanks. Share this post Link to post Share on other sites
Larrow 2822 Posted September 13, 2015 Larrow your script works but there is a main problem because the truck goes after spawn ahead escort vehicles, he should be between them. Ah thats likely just the order they are sent to norrin's script in. They do actually spawn position wise escort, truck, escort. change.. }forEach [ [ "O_Truck_03_transport_F", 0 ], [ "B_MRAP_01_F", +40 ], [ "B_MRAP_01_F", -40 ] ]; to look like }forEach [ [ "B_MRAP_01_F", +40 ], [ "O_Truck_03_transport_F", 0 ], [ "B_MRAP_01_F", -40 ] ]; As this is the order they are placed in the _vehicles array which is passed to norrin's script. Also change, just above that if ( _forEachIndex isEqualTo 0 ) then { to if ( _forEachIndex isEqualTo 1 ) then { To make sure the transport gets its extra man added as cargo and not to a non existent gunner position. There are also some EH errors : There is a spelling error in my code _veh removeEventHandler [ "HandleDamage", _veh getVariable "damageEH" ]; Should be.. _veh removeEventHandler [ "HandleDamage", _veh getVariable "damagedEH" ]; Notice the d in getvariable "damagedEH" to match the name of the setvariable above it. Holy shit . You guys want to blew up my mind. I do not understand my script anymore. :blink: If your uncomfortable with any of the stuff shown do not use it, as it makes little sense using something you would be unable to fix. Instead use the scripts to learn from and experiment with pieces until you get familiar with how/why they work. Its always nice to have some examples to work/learn from, scripts do not necessarily need to be excessively optimised, if they work and you feel comfortable with what you have then all is good. The only bits that i would recommend changing from your original are the spawned loops, the server has enough to cope with without throwing more scheduled code for it to look after every frame and eventHandlers are a better way to look after the fuel and damage. Most of all have fun :D Share this post Link to post Share on other sites
davidoss 552 Posted September 13, 2015 My code is a garbage. Spending a week to create it and test. I am shock how in different way you can get the same scenario. I am also full of admiration to your knowledge. Indeed i have lot to learn but not from bohemia wiki. Share this post Link to post Share on other sites
inlesco 233 Posted September 13, 2015 Gosh, I look at length of the script and it stirs my hair up. If .sqf ever was a line / expression efficient language, all of this could be done in < 50 lines. Now, it's way over 200. Not looking to insult anybody, just sayin' for the 1k-th time - SQF is da shit :D. tl;dr Just bitchin' things. Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 13, 2015 SQF is at some point probably not the best thing when you come from programming languages like, C++ or Java. But compared to other scripting languages, I see the aim to make it intuitive, so even people without programming knowledge can learn it. Just take the command "in" which you use to check if something is in an array, a vehicle or location. "in" also exists in JavaScript, but not to use on arrays, not even to use in if-checks, but rather to iterate over objects (sparing the details here). And SQF is hell of a lot more intuitive than PHP, if you ask me. Or could any PHP developer reading this tell by heart what the difference between the PHP functions strpos, strrpos, stripos and strripos is? Some probably even can, but all of which I asked couldn't. Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 13, 2015 scripts do not necessarily need to be excessively optimised, if they work and you feel comfortable with what you have then all is good. I absolutely respect your knowledge, capabilities and effort you put into this forum, Larrow. So please excuse me that I dare to question the latter part of the above statement. I've seen some scripts already and they all worked (more or less). But many of them used a lot of global variables, which of course made things a lot easier. But when I see global variables named "box" or "tks1", "tsk2"..., I begin to lose my hair. I would even bet that a lot of addons are in conflict or do not work properly because of such "bad smells". So to sum it up (TL;DR): Global variables are a very easy way to make a script work and a lot of people feel comfortable with it. But they are certainly not the best solution if you can avoid them with just a little bit of patience and dedication for the sake of integrity and stability. Share this post Link to post Share on other sites
davidoss 552 Posted September 13, 2015 Heeeere's johnny! Most likely everyone can put some commands together and make a script. But if you think about MP environment arma you need different point of view. You cant easy test your script you need MP environment and more players. Stuff that working in SP in MP can not working at all. Saying nothing about JIP. Global variables making coding easy for beginners i think. I have changed global variables to local and marker position is not updated for players. //create truck mobile marker _markerhighjackveh = createMarker ["ICCVeh", getPos _highjackveh]; _markerhighjackveh setMarkerType "c_car"; _markerhighjackveh setMarkerColor "ColorGreen"; _markerhighjackveh setMarkerText "I.C.C"; _highjackvehpos = [_highjackveh] spawn { _highjackveh = _this select 0; while {!isNull _highjackveh} do { "ICCVeh" setMarkerPos getPos _highjackveh; sleep 2; }; }; I just don't understand why. Share this post Link to post Share on other sites
Heeeere's johnny! 51 Posted September 14, 2015 Wouh, don't get me wrong. I'm not saying, you should immediately change all your globals to locals, who knows what's gonna happen, plus I'm also a fan of "Never touch a running system". You're right, globals are an easy way for starters and yes, thinking about "publicVariable", they are sometimes even needed and I'd be lying if I said I don't use them too, especially for testing purposes, because it's not always handy or even possible to setVariable on something to avoid a global variable. But if I use them, I'd rather have proper names and prefixes to minimize the risk of getting in conflict with any other script or addon. But to your snippet, I tested it in the editor and everything works fine for me. Does it not work in MP? Share this post Link to post Share on other sites