Advertisement
looter809

A2 Epoch call car modified

Nov 6th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.90 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. //
  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; carRunning = false;};
  219.         };
  220.        
  221.         // Get rid of debris/junk
  222.         _countDebris = nearestObjects [(getPosATL _vehTarget), _debrisArray, _debrisRemoveRadius];
  223.         if ( count _countDebris > 0 ) then {
  224.             {
  225.                 deleteVehicle _x;
  226.             } count _countDebris;
  227.         };
  228.        
  229.         if ( !_doLoop ) exitWith { true };
  230.            
  231.         sleep 0.01;
  232.     }; // end of loop
  233.    
  234.     sleep 1;
  235.    
  236.     // Destroy camera not needed anymore
  237.     _camera cameraeffect ["terminate", "back"];
  238.     camdestroy _camera;
  239.    
  240.     // Remove keydown Event Handler
  241.     (findDisplay 46) displayRemoveEventHandler ["KeyDown", jccKeyDown];
  242.  
  243.     // Exit if driver is not alive (to send player right error message)
  244.     if ( !(alive _vehDriver) ) exitWith {systemChat "JCC: Driver was killed. Exit."; carRunning = false;};
  245.     // Nobody there to drive anymore
  246.     if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit."; carRunning = false;};
  247.    
  248.     sleep 1;
  249.    
  250.     // Get crew out and delete members
  251.     {
  252.         moveOut _x;
  253.         deleteVehicle _x;
  254.     } forEach (crew _vehTarget);
  255.    
  256.     // Delete crew that got out before arrival / delete vehicle group
  257.     {deleteVehicle _x} forEach units _vehGroup;
  258.     deleteGroup _vehGroup;
  259.    
  260.     // Lock the vehicle again
  261.     _vehTarget setVehicleLock "LOCKED";
  262.    
  263.     // Exit if vehicle cannot move (to send player right error message)
  264.     if ( !canMove _vehTarget ) exitWith {systemChat "JCC: Vehicle cannot move anymore. Exit."; carRunning = false;};    
  265.    
  266.     // Success message if car arrived in the destination zone
  267.     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)),"%","%"];
  268.    
  269.     carRunning = false;
  270.    
  271. // If vehicle has not been found in range
  272. } else {
  273.     systemChat format ["JCC: Car not found in range or key %1 does not belong to a car", _keyName];
  274.  
  275. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement