Advertisement
looter809

A2 Epoch call car modified again

Nov 6th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.82 KB | None | 0 0
  1. /////////////////////////////////////////////////////////////////////
  2. //
  3. // Script: Call Car v0.1 (12/2014)
  4. // Created by: jahangir13 ([email protected]<script cf-hash='f9e31' type="text/javascript"> /* */</script>)
  5. // Calls the car belonging to the key this script was executed by
  6. //
  7. // Player needs the key of the car (right click option) and a watch in the inventory.
  8. // Car needs enough fuel to be called (config value). For now only cars/motorcycles are allowed.
  9. // When car is moving, press F7 to toggle Cam mode (F8 in Cam mode to toggle night vision).
  10. // Car is locked during movement and after arrival.
  11. //
  12. //Script slightly edited by ZzBombardierzZ/looter809/Jeremiah to not allow more than one vehicle being called at a time per player
  13. //Script edited again by ZzBombardierzZ/looter809/Jeremiah to stop the loop if vehicle is stuck (like in a base).
  14. /////////////////////////////////////////////////////////////////////
  15.  
  16. private [
  17. "_scanRadius", "_debrisArray", "_minFuelLevel", "_wpSpeed", "_wpCombatMode", "_behaviour", "_targetRadius", "_debrisRemoveRadius", "_zedKillRadius", "_camHeight", "_driverModel",
  18. "_loopLimiter", "_keyCode", "_inventoryItems", "_keyOwner", "_keyName", "_vehFoundInRange", "_vehTarget", "_ownerID", "_vehDisplayName", "_vehicle", "_minFuelLimit",
  19. "_timeBegin", "_timeEnd", "_doLoop", "_count", "_startPos", "_destPos", "_vehGroup", "_vehDriver", "_wayPoint", "_camera", "_countZombies", "_countDebris","_i"
  20. ];
  21.  
  22. //###############################################################################################################################################
  23. ////////// Configuration Begin //////////
  24. // Radius around player to scan for the car belonging to the key
  25. _scanRadius = 25000;
  26. // Debris array (all objects of classnames listed here are removed if car is too near)
  27. _debrisArray = [
  28.     "Fort_Barricade_EP1","LADAWreck","Rubbish1","Rubbish2","Rubbish3","Rubbish4","Rubbish5","Land_Misc_Rubble_EP1","UralWreck",
  29.     "SKODAWreck","HMMWVWreck","datsun02Wreck","hiluxWreck","UAZWreck","datsun01Wreck","Land_Misc_Garb_Heap_EP1"
  30. ];
  31. // Minimum fuel level the car needs to have (0.1 = 10%)
  32. _minFuelLevel = 0.1;
  33. // Waypoint speed (Possible values: "UNCHANGED","LIMITED","NORMAL","FULL")
  34. _wpSpeed = "FULL";
  35. // Waypoint combat mode ( https://community.bistudio.com/wiki/setWaypointCombatMode )
  36. _wpCombatMode = "GREEN";
  37. // Driving behaviour of the vehicle group ( https://community.bistudio.com/wiki/setWaypointBehaviour )
  38. _behaviour = "CARELESS";
  39. // Target radius: if the car reaches this radius around the destination position, it is near enough and stops (destination zone)
  40. _targetRadius = 20;
  41. // Radius around the car in which debris/junk will be deleted (otherwise car stops or tries to get around somehow)
  42. _debrisRemoveRadius = 10;
  43. // Radius around the car in which Zombies will be killed (otherwise car stops or tries to get around somehow)
  44. _zedKillRadius = 15;
  45. // Height of the camera above target vehicle
  46. _camHeight = 60;
  47. // Classname/model of the driver
  48. _driverModel = "USMC_Soldier_Medic";
  49. // Inner loop limiter ( Execute the code in this if only each n-th execution of the loop (debug monitor update, looking for Zeds, check cam on/off))
  50. _loopLimiter = 20;
  51. ////////// Configuration End //////////
  52. //###############################################################################################################################################
  53.  
  54. // Keydown function
  55. fnc_key = {
  56.     private ["_keyCode"];
  57.     _keyCode = _this select 0;
  58.     //diag_log format ["Player %1 (%2) has called their vehicle to them at %3. keyCode: %4",dayz_playerName,dayz_playerUID,(mapGridPosition getPos player), _keyCode];
  59.     // F7 pressed (Cam mode)
  60.     if ( (_keyCode == 65) ) then {
  61.         if ( showCam ) then {
  62.             showCam = false;
  63.         } else {
  64.             showCam = true;
  65.         };
  66.     };
  67.     // F8 pressed (NV mode)
  68.     if ( (_keyCode == 66) ) then {
  69.         if ( showNV ) then {
  70.             showNV = false;
  71.             camUseNVG false;
  72.         } else {
  73.             showNV = true;
  74.             camUseNVG true;
  75.         };
  76.     };
  77. };
  78. //###############################################################################################################################################
  79.  
  80. // Exit if player has no watch in inventory
  81. _inventoryItems = [player] call BIS_fnc_invString;
  82. if ( !("ItemWatch" in _inventoryItems) ) exitWith {systemChat "JCC: You don't wear your watch. Calling not possible.";};
  83.  
  84. // Get key Owner, key name from ui_selectSlot.sqf
  85. _keyOwner = _this select 0;
  86. _keyName = _this select 1;
  87.  
  88. // Variable to remember if vehicle has been found in range
  89. _vehFoundInRange = false;
  90. // The target vehicle which belongs to the key
  91. _vehTarget = objNull;
  92.  
  93. //---------------------------------------------------------------------------------------------------------    
  94. // Compare with vehicles on map (allow only land vehicles)
  95. {
  96.     _ownerID = _x getVariable ["CharacterID", "0"];
  97.     if ( _keyOwner == _ownerID ) exitWith {
  98.         _vehFoundInRange = true;
  99.         _vehTarget = _x;
  100.     };
  101. } count ( player nearEntities [["Car","Motorcycle","Tank"], _scanRadius] );
  102. //---------------------------------------------------------------------------------------------------------    
  103.  
  104. if (isNil "carRunning") then {carRunning = false;};
  105.    
  106. // if vehicle has been found
  107. if (_vehFoundInRange) then {
  108.  
  109.     if (carRunning) exitWith {systemChat "JCC: You already have a vehicle on it's way to you!";};
  110.    
  111.     carRunning = true;
  112.    
  113.     // Get crew out
  114.     if (alive driver _vehTarget) then {
  115.         (driver _vehTarget) vehicleChat "I've got a job to do! Get out!!";
  116.         sleep 0.5;
  117.         (driver _vehTarget) action ["Eject", _vehTarget];
  118.         sleep 2;
  119.     };
  120.    
  121.     _vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
  122.  
  123.     //Fuel check
  124.     if ( (fuel _vehTarget) < _minFuelLimit) exitWith { systemChat "JCC: Not enough fuel for the ride. Exit."; };
  125.    
  126.     systemChat format["JCC: (%1) KITT, come here... I need you buddy.",_vehDisplayName];
  127.     //diag_log format ["Player %1 (%2) has called their vehicle to them at %3. keyCode: %4",dayz_playerName,dayz_playerUID,(mapGridPosition getPos player), _keyCode]; 
  128.    
  129.     // Variable init
  130.     _timeBegin = 0;
  131.     _timeEnd = 0;
  132.     showCam = false;
  133.     showNV = false;
  134.     _doLoop = true;
  135.     _count = 0;
  136.    
  137.     _destPos = player modelToWorld [0, 8, 0];
  138.    
  139.     // Start counter
  140.     _timeBegin = time;
  141.    
  142.     // Create a unit group
  143.     _vehGroup = createGroup WEST;
  144.     _vehDriver = _vehGroup createUnit [_driverModel, _vehTarget, [], 0,"LIEUTENANT"];
  145.     removeAllWeapons _vehDriver;
  146.     removeAllItems _vehDriver;
  147.     _vehDriver assignAsDriver _vehTarget;
  148.     _vehDriver moveInDriver _vehTarget;
  149.     _vehDriver setSkill 1;
  150.     _vehGroup setBehaviour _behaviour;
  151.    
  152.     // Waypoint at destination where car should drive to
  153.     _wayPoint = _vehGroup addwaypoint [_destPos, 0];
  154.     _wayPoint setwaypointtype "MOVE";
  155.     _wayPoint setWaypointSpeed _wpSpeed;
  156.     _wayPoint setWaypointCombatMode _wpCombatMode;
  157.    
  158.     // Lock the vehicle
  159.     _vehTarget setVehicleLock "LOCKED";
  160.    
  161.    // Add keydown Event Handler
  162.     jccKeyDown = (findDisplay 46) displayAddEventHandler ["KeyDown","[_this select 1] call fnc_key; false;"];
  163.    
  164.     // Camera init
  165.     cameraEffectEnableHUD true;
  166.     showCinemaBorder true;
  167.     _camera = "camera" camCreate [0,0,0];
  168.    
  169.     systemChat "JCC: Toggle CAM (F7) ... Toggle NV (F8)";
  170.    
  171.     // Loop until destination is reached, driver died or left car or car cannot move anymore
  172.     for "_i" from 0 to 1 step 0 do {
  173.         _count = _count + 1;
  174.         _camera camSetTarget _vehTarget;
  175.         _camera camSetRelPos [0, -20, _camHeight];
  176.         _camera setVectorDirAndUp [[0,0.5,0.5],[0,-0.5,0.5]];
  177.  
  178.         _camera camCommitPrepared 0;
  179.         _camera camCommit 0;
  180.        
  181.         // Do not execute the commands within the if condition too often (each _loopLimiter time only)
  182.         if ( (_count mod _loopLimiter) == 0 ) then {
  183.        
  184.             if ( showCam ) then {
  185.                 _camera cameraeffect ["internal", "back"];
  186.             } else {
  187.                 _camera cameraeffect ["terminate", "back"];
  188.             };
  189.            
  190.             // Get rid of zombies
  191.             _countZombies = _vehTarget nearEntities ["zZombie_Base", _zedKillRadius];
  192.             if ( count _countZombies > 0 ) then {
  193.                 {
  194.                     _x setDamage 1;            
  195.                 } count _countZombies;
  196.             };
  197.            
  198.             // take the current time
  199.             _timeEnd = time;
  200.    
  201.             // Show debug info
  202.             hintSilent parseText format ["
  203.            <t size='1.2' font='Bitstream' align='right' color='#5882FA'>JCC Autodrive Monitor</t><br/>
  204.            <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Distance Target:</t><t size='1.0' font='Bitstream' align='right'>%1(m)</t><br/>
  205.            <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Duration:</t><t size='1.0' font='Bitstream' align='right'>%4(s)</t><br/>
  206.            <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Velocity:</t><t size='1.0' font='Bitstream' align='right'>%2(km/h)</t><br/>
  207.            <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Fuel:</t><t size='1.0' font='Bitstream' align='right'>%5(%6)</t><br/>
  208.            <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Damage:</t><t size='1.0' font='Bitstream' align='right'>%3(%7)</t><br/>",
  209.             (round ( _vehTarget distance _destPos)),
  210.             (round (speed _vehTarget)),
  211.             (round(100*(damage _vehTarget))),
  212.             (round( _timeEnd - _timeBegin)),
  213.             (round(100*(fuel _vehTarget))),
  214.             "%","%"
  215.             ];
  216.  
  217.            // Leave the loop if condition is true
  218.             if ( (_vehTarget distance _destPos < _targetRadius ) OR ( !canMove _vehTarget ) OR ( {alive _x} count crew _vehTarget == 0 ) OR !( alive _vehDriver) ) exitWith { _doLoop = false;};
  219.             //below is added by bomb/looter809 to fix issue with vehicle stuck in base
  220.             if ((speed _vehTarget < 1) && (_timeEnd - _timeBegin > 15) && ( _vehTarget distance _destPos > _targetRadius + 10)) then { sleep 10; if (speed _vehTarget < 1) exitWith {systemChat "JCC: Car seems stuck. . ."; _doLoop = false;};};
  221.         };
  222.        
  223.         // Get rid of debris/junk
  224.         _countDebris = nearestObjects [(getPosATL _vehTarget), _debrisArray, _debrisRemoveRadius];
  225.         if ( count _countDebris > 0 ) then {
  226.             {
  227.                 deleteVehicle _x;
  228.             } count _countDebris;
  229.         };
  230.        
  231.         if ( !_doLoop ) exitWith { true };
  232.            
  233.         sleep 0.01;
  234.     }; // end of loop
  235.    
  236.     sleep 1;
  237.    
  238.     // Destroy camera not needed anymore
  239.     _camera cameraeffect ["terminate", "back"];
  240.     camdestroy _camera;
  241.    
  242.     // Remove keydown Event Handler
  243.     (findDisplay 46) displayRemoveEventHandler ["KeyDown", jccKeyDown];
  244.  
  245.     // Exit if driver is not alive (to send player right error message)
  246.     if ( !(alive _vehDriver) ) exitWith {systemChat "JCC: Driver was killed. Exit."; carRunning = false;};
  247.     // Nobody there to drive anymore
  248.     if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit."; carRunning = false;};
  249.    
  250.     sleep 1;
  251.    
  252.     // Get crew out and delete members
  253.     {
  254.         moveOut _x;
  255.         deleteVehicle _x;
  256.     } forEach (crew _vehTarget);
  257.    
  258.     // Delete crew that got out before arrival / delete vehicle group
  259.     {deleteVehicle _x} forEach units _vehGroup;
  260.     deleteGroup _vehGroup;
  261.    
  262.     // Lock the vehicle again
  263.     _vehTarget setVehicleLock "LOCKED";
  264.    
  265.     // Exit if vehicle cannot move (to send player right error message)
  266.     if ( !canMove _vehTarget ) exitWith {systemChat "JCC: Vehicle cannot move anymore. Exit."; carRunning = false;};
  267.    
  268.     /*below is added by bomb/looter809 to fix issue with vehicle stuck in base. first "if" check is for is the vehicle stopped. the 2nd is so that it won't automatically quit as soon as the driver gets in.
  269.     the 3rd makes it so it doesn't say fail when the driver gets to the player and stops*/
  270.     if ((speed _vehTarget < 1) && (_timeEnd - _timeBegin > 15) && ( _vehTarget distance _destPos > _targetRadius + 10)) then { sleep 3; if (speed _vehTarget < 1) exitWith {systemChat "JCC: Sir, the car seems stuck. I'm sorry to fail you."; carRunning = false;};};    
  271.    
  272.     // Success message if car arrived in the destination zone
  273.     systemChat format ["JCC: %1 arrived. Damage: %2%5 Fuel: %3%6 Time: %4s", _vehDisplayName, (round(100*(damage _vehTarget))), (round(100*(fuel _vehTarget))),(round( _timeEnd - _timeBegin)),"%","%"];
  274.    
  275.     carRunning = false;
  276.    
  277. // If vehicle has not been found in range
  278. } else {
  279.     systemChat format ["JCC: Car not found in range or key %1 does not belong to a car", _keyName];
  280.  
  281. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement