UltimateBawb 1 Posted April 10, 2013 I'm making a script for a side mission in which you kill a VIP which goes to certain waypoints. How can I make the script notice at any time when the VIP is dead and do something? I've tried a while loop spawn with assert, but it hasn't worked. Thanks! Share this post Link to post Share on other sites
KevsNoTrev 44 Posted April 10, 2013 if !(alive VIPNAMEHERE) then { hint "Do something here"; } else { hint "do something else"; }; make sure you name your VIP in game and update the name above Share this post Link to post Share on other sites
UltimateBawb 1 Posted April 11, 2013 The basic problem with that is that it only runs once, and the script is much more complex. What I currently have: _vipHeliSpawn = ""; _vipSpawn = ""; carWayDone = false; heliWayDone = false; if (isServer) then { _vipGroup = createGroup east; _rand = (floor 100); if (_rand < 33) then {_vipSpawn = getMarkerPos "vipCarSpawn";}; if ((_rand > 33) and (_rand < 66)) then {_vipSpawn = getMarkerPos "vipCarSpawn_1";} else {_vipSpawn = getMarkerPos "vipCarSpawn_2";}; unitK = _vipGroup createUnit ["O_Soldier_SL_F", _vipSpawn, [], 6, "NONE"]; vipMan = _vipGroup createUnit ["C_man_polo_1_F", _vipSpawn, [], 6, "NONE"]; _unit1 = _vipGroup createUnit ["O_Soldier_lite_F", _vipSpawn, [], 6, "NONE"]; _unit2 = _vipGroup createUnit ["O_Soldier_lite_F", _vipSpawn, [], 6, "NONE"]; _unit3 = _vipGroup createUnit ["O_Soldier_AR_F", _vipSpawn, [], 6, "NONE"]; _unit4 = _vipGroup createUnit ["O_medic_F", _vipSpawn, [], 6, "NONE"]; removeAllWeapons vipMan; vipMan addWeapon "hgun_Rook40_F"; vipMan addMagazine "30Rnd_9x21_Mag"; vipMan addMagazine "30Rnd_9x21_Mag"; _rand = (floor 100); if (_rand < 50) then {_vipHeliSpawn = "northHelipad";} else {_vipHeliSpawn = "southHelipad";}; _vipHeli = createVehicle ["O_Ka60_Unarmed_F", getMarkerPos _vipHeliSpawn, [], 0, "NONE"]; _vipHeliGroup = createGroup east; _unitPilot1 = _vipHeliGroup createUnit ["O_helipilot_F", getMarkerPos _vipHeliSpawn, [], 4, "NONE"]; _unitPilot2 = _vipHeliGroup createUnit ["O_helipilot_F", getMarkerPos _vipHeliSpawn, [], 4, "NONE"]; _unitPilot1 assignAsDriver _vipHeli; _unitPilot2 assignAsCargo _vipHeli; _vipCar = createVehicle ["O_Ifrit_MG_F", _vipSpawn, [], 10, "NONE"]; _vipEscort = createVehicle ["O_Ifrit_MG_F", _vipSpawn, [], 10, "NONE"]; _vipCar setDir 240; _vipEscort setDir 250; unitK assignAsDriver _vipCar; vipMan assignAsCargo _vipCar; _unit1 assignAsGunner _vipCar; _unit4 assignAsCargo _vipCar; _unit3 assignAsDriver _vipEscort; _unit2 assignAsGunner _vipEscort; _vipGroup addVehicle _vipCar; _vipGroup addVehicle _vipEscort; {[_x] orderGetIn true} foreach units _vipHeliGroup + [vipman]; null = [] spawn { while {(sideMissionOn) and (alive vipMan)} do { if (! (_followMarker == objNull)) then { deleteMarker "followVIPMarker"; deleteVehicle "_followMarker"; }; _followMarker = createMarker ["followVIPMarker", getPosATL vipMan]; "followVIPMarker" setMarkerType "mil_dot"; "followVIPMarker" setMarkerColor "ColorRed"; "followVIPMarker" setMarkerText "VIP"; sleep 1; }; }; null = [] spawn { while {sideMissionOn} do { assert (alive vipMan); }; }; _carWay = _vipGroup addWaypoint [getMarkerPos _vipHeliSpawn, 15]; _carWay setWaypointType "MOVE"; _carWay setWaypointStatements ["true", "carWayDone = true;"]; while {! carWayDone} do {sleep 5;}; while {(! unitReady unitK) and (alive vipMan)} do {sleep 5}; unitK action ["eject", vehicle unitK]; vipMan action ["eject", vehicle vipMan]; _unit1 action ["eject", vehicle _unit1]; _unit4 action ["eject", vehicle _unit4]; _unit3 action ["eject", vehicle _unit3]; unassignVehicle vipMan; vipMan assignAsCargo _vipHeli; [vipMan] joinSilent _vipHeliGroup; _heliWay = _vipHeliGroup addWaypoint [getMarkerPos "outOfMapMarker", 30]; _heliWay setWaypointType "MOVE"; _heliWay setWaypointStatements ["true", "heliWayDone = true;"]; while {! heliWayDone} do {sleep 5;}; while {(! unitReady _unitPilot1) and (alive vipMan)} do {sleep 5}; }; if (alive vipMan) then {sideWin = false;} else {sideWin = true;}; if (sideWin) then { ["win", "VIP"] execVM "sideMissions\endSideMission.sqf"; } else { ["lose", "VIP"] execVM "sideMissions\endSideMission.sqf"; }; deleteMarker "followVIPMarker"; deleteVehicle "_vipHeli"; deleteVehicle "vipMan"; deleteVehicle "unitPilot1"; deleteVehicle "unitPilot2"; deleteVehicle "unitK"; deleteVehicle "_unit1"; deleteVehicle "_unit2"; deleteVehicle "_unit3"; deleteVehicle "_unit4"; deleteVehicle "_vipCar"; deleteVehicle "_vipEscort"; Share this post Link to post Share on other sites
Waffle_SS 11 Posted April 11, 2013 You could try something like: _VIPcheck = true; while {_VIPcheck} do { if(CONDITION) then { >insert shit here< } else { >insert other shit here< } }; If you want to stop the loop put something like "_VIPcheck = false", and the loop should stop running. Share this post Link to post Share on other sites
UltimateBawb 1 Posted April 11, 2013 I was thinking about that, but I'm pretty sure 'while' loops work by first checking the condition once, running the code, then checking the condition again and running the code again. I don't believe that a false condition at any time will end the loop immediately, I think it will only prevent the loop from being done twice, but I'll have to test that possibility. Anyway, what I want done should only be run once, so a 'while' loop would only work with some kind of check to make sure it doesn't spawn infinite troops. Thanks for the advice, though, I'll have to try that later. Share this post Link to post Share on other sites
clydefrog 3 Posted April 11, 2013 bawb a little bit off topic but I had a look at that other script you did similar to this one and you have a problem (looks the same in this script too) with the helicopter not always waiting for the vipman unit to get in before it flys off. Share this post Link to post Share on other sites
Larrow 2823 Posted April 11, 2013 thisscript = [] spawn { vipMan addEventHandler ["killed",{terminate thisscript;}]; while {sideMissionOn} do { //blah }; }; Should pretty much do what the assert is doing Share this post Link to post Share on other sites
KevsNoTrev 44 Posted April 11, 2013 could you put the !(alive VIP) in a trigger with a 0 for both a & b axes? this way if affects the whole map, then (on death) when he's not alive run a _nul= execvm" dostuff.sqf"; in the activation Share this post Link to post Share on other sites
killzone_kid 1333 Posted April 11, 2013 thisscript = [] spawn { vipMan addEventHandler ["killed",{terminate thisscript;}]; while {sideMissionOn} do { //blah }; }; Should pretty much do what the assert is doing Trying to terminate spawned script from inside said script froze and crashed my Arma 2 quite few times for it to be an accident. Maybe Arma 3 is different. Share this post Link to post Share on other sites
Larrow 2823 Posted April 11, 2013 (edited) I have used similar to this example a couple of times in ARMA2 and IF and never run into any problems. I have just been back and tested it straight in a units init, assigning itself the event in Arma2 with no problems. All dependent on how the RV engine actually handles events but in general as this is an event it should not matter where its initiated from, it has no relationship to where its set, only that this piece of code is set for when the event is fired. You could also move the addEventHandler out side of the script it does not need to be where it is to accomplish the task. Edited April 11, 2013 by Larrow Share this post Link to post Share on other sites