Skip to content

Commit

Permalink
Nil checks for unit creation at events
Browse files Browse the repository at this point in the history
  • Loading branch information
theace0296 committed Dec 30, 2021
1 parent feee2cb commit 306fe62
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 193 deletions.
207 changes: 107 additions & 100 deletions RandFramework/Server/objectives/fn_setDownConvoyEvent.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -124,115 +124,122 @@ while {_iteration <= 3} do {
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
};
_downedCiv setDamage 0.8;
[_downedCiv, "Acts_CivilInjuredGeneral_1"] remoteExec ["switchMove", 0];

_downedCiv disableAI "anim";
private _downedCivDirection = (floor(random 360));
_downedCiv setDir (_downedCivDirection);
_downedCiv addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_civKilled;}];
private _bloodPool1 = createVehicle [selectRandom _bloodPools, ([_downedCiv] call TRGM_GLOBAL_fnc_getRealPos), [], 0, "CAN_COLLIDE"];
_bloodPool1 setDir (floor(random 360));

private _trialDir = (floor(random 360));
private _trialPos = (getPos _bloodPool1) getPos [3,_trialDir];
private _bloodTrail1 = createVehicle ["BloodTrail_01_New_F", _trialPos, [], 0, "CAN_COLLIDE"];
_bloodTrail1 setDir _trialDir;

[_downedCiv] spawn {
private _downedCiv = _this select 0;
if (isNil "_downedCiv") exitWith {};
while{!(isNil "_downedCiv") && (alive _downedCiv)} do {
_downedCiv say3D selectRandom WoundedSounds;
sleep selectRandom [2,2.5,3];
}

};

private _downedCivMedic = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],0,"CAN_COLLIDE"] call TRGM_GLOBAL_fnc_createUnit;
_iterations = 0;
while {isNil "_downedCivMedic" || {isNull _downedCivMedic}} do {
_downedCivMedic = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],0,"CAN_COLLIDE"] call TRGM_GLOBAL_fnc_createUnit;
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
};
_downedCivMedic playmove "Acts_TreatingWounded02";
_downedCivMedic disableAI "anim";
_downedCivMedic attachTo [_downedCiv, [0.5,-0.3,-0.1]];
_downedCivMedic setDir 270;
_downedCivMedic addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_paramedicKilled;}]; //ParamedicKilled

[_downedCiv,[localize "STR_TRGM2_fnpostinit_Carry",{
private _civ = _this select 0;
private _player = _this select 1;
[_civ, _player] spawn TRGM_GLOBAL_fnc_carryAndJoinWounded;
}]] remoteExecCall ["addAction", 0];

[_downedCiv] spawn {
private _downedCiv = _this select 0;
if (isNil "_downedCiv") exitWith {};
private _doLoop = true;
while {_doLoop} do
{
if ((isNil "_downedCiv") || !alive(_downedCiv)) then {
_doLoop = false;
};
if (_downedCiv distance (getMarkerPos "mrkHQ") < 500) then {
_doLoop = false;
[localize "STR_TRGM2_DownedConvoy_Hint"] call TRGM_GLOBAL_fnc_notifyGlobal;
[0.1, format[localize "STR_TRGM2_DownedConvoy_Message",name _downedCiv]] spawn TRGM_GLOBAL_fnc_adjustMaxBadPoints;
[_downedCiv] join grpNull;
deleteVehicle _downedCiv;
};
sleep 10;

if !(isNil "_downedCiv") then {
_downedCiv setDamage 0.8;
[_downedCiv, "Acts_CivilInjuredGeneral_1"] remoteExec ["switchMove", 0];

_downedCiv disableAI "anim";
private _downedCivDirection = (floor(random 360));
_downedCiv setDir (_downedCivDirection);
_downedCiv addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_civKilled;}];
private _bloodPool1 = createVehicle [selectRandom _bloodPools, ([_downedCiv] call TRGM_GLOBAL_fnc_getRealPos), [], 0, "CAN_COLLIDE"];
_bloodPool1 setDir (floor(random 360));

private _trialDir = (floor(random 360));
private _trialPos = (getPos _bloodPool1) getPos [3,_trialDir];
private _bloodTrail1 = createVehicle ["BloodTrail_01_New_F", _trialPos, [], 0, "CAN_COLLIDE"];
_bloodTrail1 setDir _trialDir;

[_downedCiv] spawn {
private _downedCiv = _this select 0;
if (isNil "_downedCiv") exitWith {};
while{!(isNil "_downedCiv") && (alive _downedCiv)} do {
_downedCiv say3D selectRandom WoundedSounds;
sleep selectRandom [2,2.5,3];
}
};
};

[_downedCivMedic] remoteExec ["fncMedicalParamedicLight", 0, true];

private _Crater = createVehicle ["Crater", _backOfVehArea, [], 20, "CAN_COLLIDE"];

if (_iteration isEqualTo 1) then {
private _downedCivMedic2 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],8,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
private _downedCivMedic = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],0,"CAN_COLLIDE"] call TRGM_GLOBAL_fnc_createUnit;
_iterations = 0;
while {isNil "_downedCivMedic2" || {isNull _downedCivMedic2}} do {
_downedCivMedic2 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],8,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
while {isNil "_downedCivMedic" || {isNull _downedCivMedic}} do {
_downedCivMedic = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],0,"CAN_COLLIDE"] call TRGM_GLOBAL_fnc_createUnit;
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
};
_downedCivMedic2 playmove "Acts_CivilListening_2";
_downedCivMedic2 disableAI "anim";
_downedCivMedic2 addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_paramedicKilled;}]; //ParamedicKilled
if !(isNil "_downedCivMedic") then {
_downedCivMedic playmove "Acts_TreatingWounded02";
_downedCivMedic disableAI "anim";
_downedCivMedic attachTo [_downedCiv, [0.5,-0.3,-0.1]];
_downedCivMedic setDir 270;
_downedCivMedic addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_paramedicKilled;}]; //ParamedicKilled
[_downedCivMedic] remoteExec ["fncMedicalParamedicLight", 0, true];
};

private _downedCiv2 = [_group, selectRandom (call FriendlyCheckpointUnits),([_downedCivMedic2] call TRGM_GLOBAL_fnc_getRealPos),[],2,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
_iterations = 0;
while {isNil "_downedCiv2" || {isNull _downedCiv2}} do {
_downedCiv2 = [_group, selectRandom (call FriendlyCheckpointUnits),([_downedCivMedic2] call TRGM_GLOBAL_fnc_getRealPos),[],2,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
[_downedCiv,[localize "STR_TRGM2_fnpostinit_Carry",{
private _civ = _this select 0;
private _player = _this select 1;
[_civ, _player] spawn TRGM_GLOBAL_fnc_carryAndJoinWounded;
}]] remoteExecCall ["addAction", 0];

[_downedCiv] spawn {
private _downedCiv = _this select 0;
if (isNil "_downedCiv") exitWith {};
private _doLoop = true;
while {_doLoop} do
{
if ((isNil "_downedCiv") || !alive(_downedCiv)) then {
_doLoop = false;
};
if (_downedCiv distance (getMarkerPos "mrkHQ") < 500) then {
_doLoop = false;
[localize "STR_TRGM2_DownedConvoy_Hint"] call TRGM_GLOBAL_fnc_notifyGlobal;
[0.1, format[localize "STR_TRGM2_DownedConvoy_Message",name _downedCiv]] spawn TRGM_GLOBAL_fnc_adjustMaxBadPoints;
[_downedCiv] join grpNull;
deleteVehicle _downedCiv;
};
sleep 10;

};
};
_downedCiv2 playmove "Acts_CivilTalking_2";
_downedCiv2 disableAI "anim";
_downedCiv2 addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_civKilled;}]; //ParamedicKilled
[_downedCiv2, [localize "STR_TRGM2_AskNeedsAssistanceAction",{[localize "STR_TRGM2_DownedConvoy_Speach"] call TRGM_GLOBAL_fnc_notify;},[_downedCiv2]]] remoteExec ["addAction", 0, true];
private _directionFromMed2ToCiv2 = [_downedCivMedic2, _downedCiv2] call BIS_fnc_DirTo;
_downedCivMedic2 setDir _directionFromMed2ToCiv2;
private _directionFromCiv2ToMed2 = [_downedCiv2, _downedCivMedic2] call BIS_fnc_DirTo;
_downedCiv2 setDir _directionFromCiv2ToMed2;
};
if (_iteration isEqualTo 2) then {
private _downedCiv3 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],25,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
_iterations = 0;
while {isNil "_downedCiv3" || {isNull _downedCiv3}} do {
_downedCiv3 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],25,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;

private _Crater = createVehicle ["Crater", _backOfVehArea, [], 20, "CAN_COLLIDE"];

if (_iteration isEqualTo 1) then {
private _downedCivMedic2 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],8,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
_iterations = 0;
while {isNil "_downedCivMedic2" || {isNull _downedCivMedic2}} do {
_downedCivMedic2 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],8,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
};
if !(isNil "_downedCivMedic2") then {
_downedCivMedic2 playmove "Acts_CivilListening_2";
_downedCivMedic2 disableAI "anim";
_downedCivMedic2 addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_paramedicKilled;}]; //ParamedicKilled
private _downedCiv2 = [_group, selectRandom (call FriendlyCheckpointUnits),([_downedCivMedic2] call TRGM_GLOBAL_fnc_getRealPos),[],2,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
_iterations = 0;
while {isNil "_downedCiv2" || {isNull _downedCiv2}} do {
_downedCiv2 = [_group, selectRandom (call FriendlyCheckpointUnits),([_downedCivMedic2] call TRGM_GLOBAL_fnc_getRealPos),[],2,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
};
if !(isNil "_downedCiv2") then {
_downedCiv2 playmove "Acts_CivilTalking_2";
_downedCiv2 disableAI "anim";
_downedCiv2 addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_civKilled;}]; //ParamedicKilled
[_downedCiv2, [localize "STR_TRGM2_AskNeedsAssistanceAction",{[localize "STR_TRGM2_DownedConvoy_Speach"] call TRGM_GLOBAL_fnc_notify;},[_downedCiv2]]] remoteExec ["addAction", 0, true];
private _directionFromMed2ToCiv2 = [_downedCivMedic2, _downedCiv2] call BIS_fnc_DirTo;
_downedCivMedic2 setDir _directionFromMed2ToCiv2;
private _directionFromCiv2ToMed2 = [_downedCiv2, _downedCivMedic2] call BIS_fnc_DirTo;
_downedCiv2 setDir _directionFromCiv2ToMed2;
};
};
};
if (_iteration isEqualTo 2) then {
private _downedCiv3 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],25,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
_iterations = 0;
while {isNil "_downedCiv3" || {isNull _downedCiv3}} do {
_downedCiv3 = [_group, selectRandom (call FriendlyCheckpointUnits),_backOfVehArea,[],25,"NONE"] call TRGM_GLOBAL_fnc_createUnit;
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
};
if !(isNil "_downedCiv3") then {
_downedCiv3 playmove "Acts_CivilShocked_1";
_downedCiv3 disableAI "anim";
_downedCiv3 setDir (floor(random 360));
_downedCiv3 addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_civKilled;}]; //ParamedicKilled
};
};
_downedCiv3 playmove "Acts_CivilShocked_1";
_downedCiv3 disableAI "anim";
_downedCiv3 setDir (floor(random 360));
_downedCiv3 addEventHandler ["killed", {_this spawn TRGM_SERVER_fnc_civKilled;}]; //ParamedicKilled
};

private _rubbish1 = createVehicle [selectRandom TRGM_VAR_MedicalMessItems, ([_downedCiv] call TRGM_GLOBAL_fnc_getRealPos), [], 1.5, "CAN_COLLIDE"];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ while {isNil "_downedCiv" || {isNull _downedCiv}} do {
if (_iterations > 5) exitWith {};
_iterations = _iterations + 1;
};
if (isNil "_downedCiv") exitWith {};

[_downedCiv,[localize "STR_TRGM2_fnpostinit_JoinGroup",{
private _civ = _this select 0;
Expand Down
Loading

0 comments on commit 306fe62

Please sign in to comment.