Advertisement
secondcoming

occupationTransport.sqf

Jun 22nd, 2016
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 9.86 KB | None | 0 0
  1. if (!isServer) exitWith {};
  2.  
  3. while {true} do
  4. {
  5.     _logDetail = format ["[OCCUPATION:transport]:: Starting @ %1",time];
  6.     [_logDetail] call SC_fnc_log;
  7.  
  8.     private["_spawnLocation","_transport","_transportSpeed","_transportType","_wp","_transportBehaviour","_transportWaitingTime","_transportGunner"];
  9.  
  10.     if( count SC_occupyTransportStartPos   == 0) then
  11.     {
  12.         _middle             = worldSize/2;         
  13.         _spawnCenter        = [_middle,_middle,0];        
  14.         SC_occupyTransportStartPos  = _spawnCenter;
  15.     };
  16.  
  17.     SC_occupyTransportClassToUse = SC_occupyTransportClass call BIS_fnc_selectRandom;
  18.  
  19.     if!(SC_occupyTransportClassToUse isKindOf "LandVehicle" OR SC_occupyTransportClassToUse isKindOf "Air") exitWith
  20.     {  
  21.         _logDetail = format ["[OCCUPATION:transport]:: Only land vehicles or helicopters can be used as public transport"];
  22.         [_logDetail] call SC_fnc_log;    
  23.     };
  24.  
  25.     if(SC_occupyTransportClassToUse isKindOf "LandVehicle") then
  26.     {
  27.         _transportType = "land";
  28.         _logDetail = format ["[OCCUPATION:transport]:: Spawning near map centre %1 @ %2",SC_occupyTransportStartPos,time];
  29.         [_logDetail] call SC_fnc_log;
  30.  
  31.         _positionOftransport = [SC_occupyTransportStartPos,0,500,25,0,10,0] call BIS_fnc_findSafePos;
  32.  
  33.         // Get position of nearest roads
  34.         _nearRoads = _positionOftransport nearRoads 2000;
  35.         _nearestRoad = _nearRoads select 0;
  36.         _nearestRoadPos = position (_nearRoads select 0);
  37.         _spawnLocation = [_nearestRoadPos select 0, _nearestRoadPos select 1, 0];    
  38.         _transportSpeed = "LIMITED";
  39.         _transportBehaviour = "SAFE";
  40.         _transportWaitingTime = 10;
  41.     }
  42.     else
  43.     {
  44.         _transportType = "heli";
  45.         _spawnLocation = [SC_occupyTransportStartPos select 0, SC_occupyTransportStartPos select 1, 200];
  46.         _transportSpeed = "NORMAL";
  47.         _transportBehaviour = "CARELESS";
  48.         _transportWaitingTime = 60;
  49.     };  
  50.  
  51.  
  52.     // Check there are enough waypoints to use  
  53.     _markerCount = 0;  
  54.     {
  55.         _markerName = _x;
  56.         _markerPos = getMarkerPos _markerName;
  57.         if (markerType _markerName == "ExileTraderZone" OR markerType _markerName == "o_unknown") then
  58.         {
  59.             _markerCount = _markerCount + 1;
  60.         };
  61.  
  62.     } forEach allMapMarkers;
  63.  
  64.     if(_markerCount < 2) then
  65.     {  
  66.         _logDetail = format ["[OCCUPATION:transport]:: failed to find more than 1 ExileTraderZone or o_unknown map markers @ %1",time];
  67.         [_logDetail] call SC_fnc_log;
  68.     }
  69.     else
  70.     {
  71.         // Create the driver/pilot and ensure he doest react to gunfire or being shot at.
  72.         _group = createGroup resistance;
  73.         _group setCombatMode "BLUE";
  74.         _group setVariable ["DMS_AllowFreezing",false,true];
  75.  
  76.         // Spawn Vehicle
  77.  
  78.         if(_transportType == "heli") then
  79.         {
  80.             _transport = createVehicle [SC_occupyTransportClassToUse, _spawnLocation, [], 0, "NONE"];
  81.             _transport setVehiclePosition [_spawnLocation, [], 0, "FLY"];
  82.             _transport setVariable ["vehicleID", _spawnLocation, true];  
  83.             _transport setFuel 1;
  84.             _transport setDamage 0;
  85.             _transport engineOn true;
  86.             _transport flyInHeight 100;    
  87.         }
  88.         else
  89.         {
  90.             _transport = createVehicle [SC_occupyTransportClassToUse, _spawnLocation, [], 0, "CAN_COLLIDE"];    
  91.         };
  92.  
  93.         sleep 0.2;
  94.  
  95.         if(isNull _transport) exitWith
  96.         {  
  97.             _logDetail = format ["[OCCUPATION:transport]:: %1 failed to spawn, check it is a valid vehicle class name",SC_occupyTransportClassToUse];
  98.             [_logDetail] call SC_fnc_log;
  99.         };
  100.  
  101.         if(SC_secureTransport) then
  102.         {
  103.             _transport addEventHandler ["handleDamage", { false }];
  104.             _transport allowdamage false;
  105.         };
  106.  
  107.  
  108.         if( _transportType == "land" && SC_colourTransport) then
  109.         {
  110.             //_transport setObjectTextureGlobal [0,"#(argb,8,8,3)color(0.518,0.519,0.7,0.2)"];    
  111.         }
  112.         else
  113.         {
  114.             _transport setObjectTextureGlobal [0,"#(argb,8,8,3)color(0.518,0.519,0.7,0.2)"];
  115.             _transport setObjectTextureGlobal [1,"#(argb,8,8,3)color(0.518,0.519,0.7,0.2)"];
  116.             _transport setObjectTextureGlobal [2,"#(argb,8,8,3)color(0.518,0.519,0.7,0.2)"];    
  117.         };
  118.  
  119.  
  120.         _group addVehicle _transport;
  121.            
  122.         _transport enableCopilot false;
  123.  
  124.         _transportDriver = _group createUnit [DMS_AI_Classname, _spawnLocation, [], 0,"FORM"];
  125.         removeGoggles _transportDriver;
  126.         _transportDriver forceAddUniform "U_IG_Guerilla3_1";
  127.         _transportDriver addVest "V_TacVest_blk_POLICE";
  128.         _transportDriver addHeadgear "H_Cap_blk";
  129.         removeBackpackGlobal _transportDriver;
  130.         _transportDriver addBackpackGlobal "B_Parachute";
  131.         _transportDriver disableAI 'AUTOTARGET';
  132.         _transportDriver disableAI 'TARGET';
  133.         _transportDriver disableAI 'SUPPRESSION';
  134.         _transportDriver setCaptive true;  
  135.         _transportDriver assignasdriver _transport;
  136.         _transportDriver moveInDriver _transport;
  137.         [_transportDriver] orderGetin true;
  138.         _transport lockDriver true;
  139.         _transport lockTurret [[0],true];
  140.  
  141.         if(SC_secureTransport) then
  142.         {
  143.             _transportDriver allowDamage false;
  144.         };
  145.  
  146.         SC_transportArray = SC_transportArray + [_transport];
  147.         _transport setVariable ["SC_assignedDriver", _transportDriver,true];
  148.         _transport setVariable ["SC_transport", true,true];
  149.         _transport setVariable ["SC_vehicleSpawnLocation", _spawnLocation,true];
  150.         _transportDriver setVariable ["DMS_AssignedVeh",_transport];
  151.         _transportDriver setVariable ["SC_lastSpoke", time, true];
  152.         _transport addEventHandler ["getin", "_this call SC_fnc_getOnBus;"];
  153.         _transport addEventHandler ["getout", "_this call SC_fnc_getOffBus;"];
  154.  
  155.         clearBackpackCargoGlobal _transport;
  156.         clearItemCargoGlobal _transport;
  157.         clearMagazineCargoGlobal _transport;
  158.         clearWeaponCargoGlobal _transport;
  159.         _transport setVariable ["ExileIsPersistent", false];
  160.         _transport setVariable["vehPos",_spawnLocation,true];
  161.         _transport setFuel 1;
  162.  
  163.         _logDetail = format['[OCCUPATION:transport] Vehicle %1 spawned @ %2',SC_occupyTransportClassToUse,_spawnLocation];
  164.         [_logDetail] call SC_fnc_log;
  165.  
  166.         _logDetail = format ["[OCCUPATION:transport]:: Found %1 markers to use as pickup points @ %2",_markerCount,time];
  167.         [_logDetail] call SC_fnc_log;
  168.  
  169.         _textures = getObjectTextures _transport;
  170.  
  171.         _logDetail = format ["[OCCUPATION:transport]:: textures for vehicle are: %1",_textures];
  172.         [_logDetail] call SC_fnc_log;
  173.  
  174.  
  175.  
  176.         _markerCount = 0;  
  177.         {
  178.             _markerName = _x;
  179.             _markerPos = getMarkerPos _markerName;
  180.             if (markerType _markerName == "ExileTraderZone" OR markerType _markerName == "o_unknown") then
  181.             {
  182.                 _wp = _group addWaypoint [_markerPos, 100];
  183.                 _wp setWaypointType "MOVE";
  184.                 _wp setWaypointBehaviour _transportBehaviour;
  185.                 _wp setWaypointspeed _transportSpeed;
  186.                
  187.                 _wp = _group addWaypoint [_markerPos, 25];
  188.                 _wp setWaypointType "TR UNLOAD";
  189.                 _wp setWaypointBehaviour "SAFE";
  190.                 _wp setWaypointspeed "LIMITED";
  191.                 _wp setWaypointTimeout [_transportWaitingTime,_transportWaitingTime,_transportWaitingTime];
  192.                 _markerCount = _markerCount + 1;
  193.             };
  194.        
  195.         } forEach allMapMarkers;
  196.  
  197.  
  198.  
  199.         // Add a final CYCLE
  200.         _wp = _group addWaypoint [_spawnLocation, 20];
  201.         _wp setWaypointType "CYCLE";
  202.         _wp setWaypointBehaviour _transportBehaviour;
  203.         _wp setWaypointspeed _transportSpeed;
  204.         _wp setWaypointTimeout [_transportWaitingTime,_transportWaitingTime,_transportWaitingTime];
  205.  
  206.         _transportPos = position _transport;
  207.         _mk = createMarker ["transportLocation",_transportPos];
  208.  
  209.         if(_transportType == "land") then
  210.         {
  211.             "transportLocation" setMarkerType "loc_BusStop";
  212.             "transportLocation" setMarkerText "Occupation Public Bus";    
  213.         }
  214.         else
  215.         {
  216.             "transportLocation" setMarkerType "c_air";
  217.             "transportLocation" setMarkerText "Occupation Airlines";
  218.             "transportLocation" setMarkerColor "ColorBLUFOR";      
  219.         };
  220.  
  221.  
  222.         diag_log format['[OCCUPATION:transport] Running'];
  223.         _transportDriver = _transport getVariable "SC_assignedDriver";
  224.  
  225.         // Make _transportDriver stop when players near him.
  226.         while {alive _transportDriver} do
  227.         {
  228.            
  229.             _pos = position _transport;
  230.             _mk setMarkerPos _pos;
  231.             _nearPlayers = (count (_pos nearEntities [['Exile_Unit_Player'],25]));
  232.  
  233.             if (_nearPlayers >= 1 && _transportType == "land") then
  234.             {
  235.                 uiSleep 0.5;
  236.                 _transport setFuel 1;
  237.                 _transport setVehicleAmmo 1;
  238.                 _transportDriver disableAI "MOVE";
  239.                 uiSleep 3;
  240.             }
  241.             else
  242.             {  
  243.                 _transport setFuel 1;
  244.                 _transport setVehicleAmmo 1;
  245.                 uiSleep 3;
  246.                 _transportDriver enableAI "MOVE";    
  247.             };
  248.             if(!Alive _transportDriver) exitWith {};
  249.             uiSleep 5;  
  250.         };     
  251.         deleteMarker _mk;
  252.         _transport setDamage 1;
  253.     };
  254.     _logDetail = format ["[OCCUPATION:transport]:: Transport destroyed @ %1 (%2)",_pos,time];
  255.     [_logDetail] call SC_fnc_log;
  256.  
  257.     // Spawn another heli
  258.     uiSleep 15; // delay the start
  259. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement