RoryRothon 8 Posted July 26, 2018 Hi, i am trying to get this working but keep getting a undefined variable error for _crew. Below is the function i am creating, i wonder if someone would be kind enough to point out something i may have overlooked? Error line has been marked at ( waitUntil ) Kind regards Rory RAZ_fnc_spawnHuntingVehicle = { waitUntil { time > 0 }; params [ "_unit" ]; _pos = getPosATL _unit; _huntingVehicles = _unit getVariable [ "RAZ_fnc_isBeingHuntedByVehicle", 0 ]; _huntingVehicles = _huntingVehicles + 1; _unit setVariable [ "RAZ_fnc_isBeingHuntedByVehicle", _huntingVehicles, true ]; _spawnPos = _pos getPos [ 3000, random 360 ]; _spawnPos = [ _spawnPos, 1, 50, 1, 0, 35, 0 ] call BIS_fnc_findSafePos; _randomArray = selectRandom[0,2]; if ( _randomArray == 0 ) then { _faction = east } else { _faction = independent }; _patrolVehicle = [ _spawnPos, 180, ( selectRandom (RAZ_fnc_vehicleConfigs select _randomArray) ), _faction ] call Bis_fnc_spawnvehicle; _veh = _patrolVehicle select 0; _crew = _patrolVehicle select 2; { gm addCuratorEditableObjects [ [_x], true ]; } forEach units _crew; gm addCuratorEditableObjects [ [ _veh ], true ]; { _x setSkill 0.25; } forEach units _crew; while { ( { alive _x } count units _crew ) >= 1 AND alive _veh } do { if ( !alive _unit ) then { _unit setVariable [ "RAZ_fnc_isBeingHuntedByVehicle", _huntingVehicles, false ]; _unit = selectRandom ( allPlayers select { alive _x } ); }; _searchWp = [ getPos _unit, random 1000, random 360 ] call BIS_fnc_relPos; _wp = _crew addWaypoint [_searchWp, 0]; [_crew, 1] setWaypointType "SAD"; [_crew, 1] setWaypointSpeed "NORMAL"; _timer = time + 60; waitUntil { time > _timer OR ({alive _x} count units _crew) isEqualTo 0 OR !alive _veh }; deleteWaypoint [_crew, 1]; }; waitUntil { ( { alive _x } count units _crew ) isEqualTo 0 OR !alive _veh }; <<<<<< ERROR! _huntingVehicles = _unit getVariable ["RAZ_fnc_isBeingHuntedByVehicle",0]; _huntingVehicles = _huntingVehicles - 1; _unit setVariable ["RAZ_fnc_isBeingHuntedByVehicle",_huntingVehicles,true]; _waitTime = time + 10; waitUntil { time > _waitTime }; }; _spawningEnemies = [] spawn { _players = []; _vehiclePlayers = []; _spawnHunters = true; waitUntil {time > 0}; while { _spawnHunters } do { waitUntil { sleep 3; (count (allplayers - switchableUnits) > 0) }; _players = (allplayers - switchableUnits) select {(_x getVariable ["RAZ_fnc_isBeingHunted",0]) isEqualTo 0}; _vehiclePlayers = (allplayers - switchableUnits) select {(_x getVariable ["RAZ_fnc_isBeingHuntedByVehicle",0]) isEqualTo 0}; _players apply { _hunt = [_x,east] spawn RAZ_fnc_spawnHuntingInfantry; _hunt = [_x,independent] spawn RAZ_fnc_spawnHuntingInfantry; }; _vehiclePlayers apply { _hunt = [_x] spawn RAZ_fnc_spawnHuntingVehicle; }; }; }; Share this post Link to post Share on other sites
pierremgi 4906 Posted July 26, 2018 _randomArray = selectRandom[0,2]; private _faction = if ( _randomArray == 0 ) then [{east }, { independent }]; _patrolVehicle = [ _spawnPos, 180, ( selectRandom (RAZ_fnc_vehicleConfigs select _randomArray) ), _faction ] call Bis_fnc_spawnvehicle; then verify you spawn a vehicle, depending on RAZ_fnc_vehicleConfigs. I can't test for you. Share this post Link to post Share on other sites
whiztler 137 Posted July 26, 2018 Or _faction = east if (random 100 > 50) then { _faction = independent }; 1 Share this post Link to post Share on other sites
RoryRothon 8 Posted July 27, 2018 All fixed! Still some little tweaks to make though. My script spawns (per player) 1 chopper, 1 vehicle and 2 fire teams to hunt down the player whilst also fighting eachother. Thanks for your help! Just need to ties it all together now with my loot and end game scripts :) #include "scripts\hunting\huntingArrays.sqf"; mapCenter = [ worldSize / 2, worldSize / 2, 0 ]; RAZ_fnc_spawnHuntingInfantry = { params [ "_unit", [ "_side", EAST ] ]; _sideID = _side call BIS_fnc_sideID; _faction = East; if ( _sideID == 0 ) then { _faction = _faction }; if ( _sideID == 1 ) then { _faction = West }; if ( _sideID == 2 ) then { _faction = Independent }; _pos = getPosATL _unit; _huntingGroups = _unit getVariable [ "RAZ_fnc_isBeingHunted", 0 ]; _huntingGroups = _huntingGroups + 1; _unit setVariable [ "RAZ_fnc_isBeingHunted", _huntingGroups, true ]; _spawnPos = _pos getPos [ 600, random 360 ]; _spawnPos = [ _spawnPos, 1, 10, 1, 0, 45, 0 ] call BIS_fnc_findSafePos; _grp = [ _spawnPos, _faction, ( selectRandom (RAZ_fnc_infantryConfigs select _sideID) ) ] call BIS_fnc_spawnGroup; { _x setUnitAbility 0.1; _x setskill ["aimingAccuracy",0.05]; _x setskill ["aimingShake",0.9]; _x setskill ["aimingSpeed",0.1]; _x setskill ["Endurance",0.1]; _x setskill ["spotDistance",0.5]; _x setskill ["spotTime",0.5]; _x setskill ["courage",0.1]; _x setskill ["reloadSpeed",0.1]; } forEach units _grp; { gm addCuratorEditableObjects [ [_x], true ]; } forEach units _grp; _searchWp = [ getPos _unit, random 500, random 360 ] call BIS_fnc_relPos; _wp = _grp addWaypoint [_searchWp, 0]; [_grp, 1] setWaypointType "SAD"; [_grp, 1] setWaypointSpeed "NORMAL"; _grp setFormation "LINE"; while { ( { alive _x } count units _grp ) >= 1 } do { _timer = time + 10; if ( alive _unit ) then { _unit = _unit }; if ( !alive _unit ) then { _unit setVariable [ "RAZ_fnc_isBeingHunted", _huntingGroups, false ]; sleep 2; _unit = selectRandom ( allPlayers select { alive _x } ); while { ( count ( waypoints _grp ) ) > 0 } do { deleteWaypoint ( ( waypoints _grp ) select 0 ); }; _searchWp = [ getPos _unit, random 500, random 360 ] call BIS_fnc_relPos; _wp = _grp addWaypoint [ _searchWp, 0 ]; [ _grp, 1 ] setWaypointType "SAD"; [ _grp, 1 ] setWaypointType "NORMAL"; _grp setFormation "LINE"; }; waitUntil { sleep 120; position _unit distance _spawnpos > 30 OR time > _timer OR ({alive _x} count units _grp) isEqualTo 0 }; deleteWaypoint [_grp, 1]; _searchWp = [ getPos _unit, random 300, random 360 ] call BIS_fnc_relPos; _wp = _grp addWaypoint [_searchWp, 1]; [_grp, 1] setWaypointType "SAD"; [_grp, 1] setWaypointSpeed "NORMAL"; _grp setFormation "LINE"; }; sleep 1; _huntingGroups = _unit getVariable ["RAZ_fnc_isBeingHunted",0]; _huntingGroups = _huntingGroups - 1; _unit setVariable ["RAZ_fnc_isBeingHunted",_huntingGroups,true]; }; RAZ_fnc_spawnHuntingVehicle = { params ["_unit"]; _huntingVehicles = _unit getVariable [ "RAZ_fnc_isBeingHuntedByVehicle", 0 ]; _huntingVehicles = _huntingVehicles + 1; _unit setVariable [ "RAZ_fnc_isBeingHuntedByVehicle", _huntingVehicles, true ]; _randomSide = selectRandom[0,2]; _faction = east; if ( _randomSide == 0 ) then { _faction = east } else { _faction = independent }; _pos = getPosATL _unit; _spawnPos = _pos getPos [ 1500, random 360 ]; _spawnPos = [ _spawnPos, 1, 50, 1, 0, 35, 0 ] call BIS_fnc_findSafePos; _patrolVehicle = [ _spawnPos, 180, ( selectRandom (RAZ_fnc_vehicleConfigs select _randomSide) ), _faction ] call bis_fnc_spawnvehicle; _veh = _patrolVehicle select 0; _crew = _patrolVehicle select 2; { gm addCuratorEditableObjects [ [_x], true ]; } forEach units _crew; gm addCuratorEditableObjects [ [ _veh ], true ]; while { ( { alive _x } count units _crew ) >= 1 AND alive _veh } do { if ( !alive _unit ) then { _unit setVariable [ "RAZ_fnc_isBeingHuntedByVehicle", _huntingVehicles, false ]; _unit = selectRandom ( allPlayers select { alive _x } ); while { ( count ( waypoints _grp ) ) > 0 } do { deleteWaypoint ( ( waypoints _grp ) select 0 ); }; _searchWp = [ getPos _unit, random 1000, random 360 ] call BIS_fnc_relPos; _wp = _grp addWaypoint [ _searchWp, 0 ]; [ _grp, 1 ] setWaypointType "SAD"; [ _grp, 1 ] setWaypointType "NORMAL"; }; waitUntil { (count (allplayers - switchableUnits) > 0) }; _unit = selectRandom ( allPlayers select { alive _x } ); _timer = time + 180; while { ( count ( waypoints _crew ) ) > 0 } do { deleteWaypoint ( ( waypoints _crew ) select 0 ); }; _searchWp = [ getPos _unit, random 1000, random 360 ] call BIS_fnc_relPos; _wp = _crew addWaypoint [_searchWp, 0]; [_crew, 0] setWaypointType "SAD"; [_crew, 0] setWaypointSpeed "NORMAL"; waituntil { time > _timer }; }; waitUntil { ( { alive _x } count units _crew ) isEqualTo 0 OR !alive _veh }; while { ( count ( waypoints _crew ) ) > 0 } do { deleteWaypoint ( ( waypoints _crew ) select 0 ); }; sleep 300; _huntingVehicles = _unit getVariable ["RAZ_fnc_isBeingHuntedByVehicle",0]; _huntingVehicles = _huntingVehicles - 1; _unit setVariable ["RAZ_fnc_isBeingHuntedByVehicle",_huntingVehicles,true]; }; RAZ_fnc_spawnHuntingAir = { params ["_unit"]; waitUntil { time > 60 }; _huntingAir = _unit getVariable [ "RAZ_fnc_isBeingHuntedByAir", 0 ]; _huntingAir = _huntingAir + 1; _unit setVariable [ "RAZ_fnc_isBeingHuntedByAir", _huntingAir, true ]; _randomSide = selectRandom[0,2]; _faction = east; if ( _randomSide == 0 ) then { _faction = east } else { _faction = independent }; _spawnPos = mapCenter getPos [ random worldSize / 2, random 360 ]; _spawnPos = [ _spawnPos, 1, random worldSize / 2, 10, 0, 35, 0 ] call BIS_fnc_findSafePos; _patrolVehicle = [ _spawnPos, 180, ( selectRandom (RAZ_fnc_airVehicleConfigs select _randomSide) ), _faction ] call bis_fnc_spawnvehicle; _veh = _patrolVehicle select 0; _crew = _patrolVehicle select 2; _searchLight = [_veh] execVM "AL_searchlight\al_search_light_ini.sqf"; { gm addCuratorEditableObjects [ [_x], true ]; } forEach units _crew; gm addCuratorEditableObjects [ [ _veh ], true ]; while { ( { alive _x } count units _crew ) >= 1 AND alive _veh } do { if ( !alive _unit ) then { _unit setVariable [ "RAZ_fnc_isBeingHuntedByAir", _huntingAir, false ]; _unit = selectRandom ( allPlayers select { alive _x } ); while { ( count ( waypoints _grp ) ) > 0 } do { deleteWaypoint ( ( waypoints _grp ) select 0 ); }; _searchWp = [ getPos _unit, random 1000, random 360 ] call BIS_fnc_relPos; _wp = _grp addWaypoint [ _searchWp, 0 ]; [ _grp, 1 ] setWaypointType "SAD"; [ _grp, 1 ] setWaypointType "NORMAL"; }; waitUntil { (count (allplayers - switchableUnits) > 0) }; _unit = selectRandom ( allPlayers select { alive _x } ); _timer = time + 60; while { ( count ( waypoints _crew ) ) > 0 } do { deleteWaypoint ( ( waypoints _crew ) select 0 ); }; _searchWp = [ getPos _unit, random 1000, random 360 ] call BIS_fnc_relPos; _wp = _crew addWaypoint [_searchWp, 0]; [_crew, 0] setWaypointType "SAD"; [_crew, 0] setWaypointSpeed "NORMAL"; waituntil { time > _timer }; }; waitUntil { ( { alive _x } count units _crew ) isEqualTo 0 OR !alive _veh }; while { ( count ( waypoints _crew ) ) > 0 } do { deleteWaypoint ( ( waypoints _crew ) select 0 ); }; sleep 300; _huntingAir = _unit getVariable ["RAZ_fnc_isBeingHuntedByAir",0]; _huntingAir = _huntingAir - 1; _unit setVariable ["RAZ_fnc_isBeingHuntedByAir",_huntingAir,true]; }; _spawningEnemies = [] spawn { _players = []; _vehiclePlayers = []; _spawnHunters = true; if ( debugScript ) then { format [ "Operation Missdrop System Initialized" ] remoteExec ["systemChat"]; }; waitUntil {time > 0}; while { _spawnHunters } do { waitUntil { sleep 3; (count (allplayers - switchableUnits) > 0) }; _players = (allplayers - switchableUnits) select {(_x getVariable ["RAZ_fnc_isBeingHunted",0]) isEqualTo 0}; _vehiclePlayers = (allplayers - switchableUnits) select {(_x getVariable ["RAZ_fnc_isBeingHuntedByVehicle",0]) isEqualTo 0}; _airPlayers = (allplayers - switchableUnits) select {(_x getVariable ["RAZ_fnc_isBeingHuntedByAir",0]) isEqualTo 0}; _players apply { _hunt = [_x,east] spawn RAZ_fnc_spawnHuntingInfantry; _hunt = [_x,independent] spawn RAZ_fnc_spawnHuntingInfantry; }; _vehiclePlayers apply { _hunt = [_x] spawn RAZ_fnc_spawnHuntingVehicle; }; _vehiclePlayers apply { _hunt = [_x] spawn RAZ_fnc_spawnHuntingAir; }; }; }; ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// // END GAME SCRIPTING --------------------------------------------------------------- ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// _endGameTimer = 600; waitUntil { time > _endGameTimer && count (allPlayers select {group _x isEqualTo group (allPlayers select 0)}) isEqualTo count allPlayers; }; format ["All soldiers found. Receiving intel on extraction point, ETA 10 mins!"] remoteExec ["hint"]; sleep 600; Share this post Link to post Share on other sites
HazJ 1289 Posted July 28, 2018 _faction = East; if ( _sideID == 0 ) then { _faction = _faction }; if ( _sideID == 1 ) then { _faction = West }; if ( _sideID == 2 ) then { _faction = Independent }; You can make this into a switch block as well. @whiztler - Why that when you can do as @pierremgi said. _faction = east if (random 100 > 50) then { _faction = independent }; // There is also private _faction = if (_randomArray isEqualTo 0) then {opfor} else {independent}; switch (side player) do { case blufor : { }; case opfor : { }; case independent : { }; // None of the above... default { }; }; Share this post Link to post Share on other sites
Larrow 2822 Posted July 28, 2018 RAZ_fnc_airVehicleConfigs = [ //East [ "O_Heli_Light_02_F" ], //West [ //Empty ], //Independent [ "I_Heli_light_03_F" ] ]; private _side = selectRandom [ east, independent ]; _patrolVehicle = [ _spawnPos, 180, ( selectRandom (RAZ_fnc_airVehicleConfigs select ( _side call BIS_fnc_sideID ))), _side ] call BIS_fnc_spawnVehicle; Share this post Link to post Share on other sites