Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /////////////////////////////////////////////////////////////////////
- //
- // Script: Call Car v0.1 (12/2014)
- // Created by: jahangir13 ([email protected]<script cf-hash='f9e31' type="text/javascript"> /* */</script>)
- // Calls the car belonging to the key this script was executed by
- //
- // Player needs the key of the car (right click option) and a watch in the inventory.
- // Car needs enough fuel to be called (config value). For now only cars/motorcycles are allowed.
- // When car is moving, press F7 to toggle Cam mode (F8 in Cam mode to toggle night vision).
- // Car is locked during movement and after arrival.
- //
- //Script slightly edited by ZzBombardierzZ/looter809/Jeremiah to not allow more than one vehicle being called at a time per player
- //Script edited again by ZzBombardierzZ/looter809/Jeremiah to stop the loop if vehicle is stuck (like in a base).
- /////////////////////////////////////////////////////////////////////
- private [
- "_scanRadius", "_debrisArray", "_minFuelLevel", "_wpSpeed", "_wpCombatMode", "_behaviour", "_targetRadius", "_debrisRemoveRadius", "_zedKillRadius", "_camHeight", "_driverModel",
- "_loopLimiter", "_keyCode", "_inventoryItems", "_keyOwner", "_keyName", "_vehFoundInRange", "_vehTarget", "_ownerID", "_vehDisplayName", "_vehicle", "_minFuelLimit",
- "_timeBegin", "_timeEnd", "_doLoop", "_count", "_startPos", "_destPos", "_vehGroup", "_vehDriver", "_wayPoint", "_camera", "_countZombies", "_countDebris","_i"
- ];
- //###############################################################################################################################################
- ////////// Configuration Begin //////////
- // Radius around player to scan for the car belonging to the key
- _scanRadius = 25000;
- // Debris array (all objects of classnames listed here are removed if car is too near)
- _debrisArray = [
- "Fort_Barricade_EP1","LADAWreck","Rubbish1","Rubbish2","Rubbish3","Rubbish4","Rubbish5","Land_Misc_Rubble_EP1","UralWreck",
- "SKODAWreck","HMMWVWreck","datsun02Wreck","hiluxWreck","UAZWreck","datsun01Wreck","Land_Misc_Garb_Heap_EP1"
- ];
- // Minimum fuel level the car needs to have (0.1 = 10%)
- _minFuelLevel = 0.1;
- // Waypoint speed (Possible values: "UNCHANGED","LIMITED","NORMAL","FULL")
- _wpSpeed = "FULL";
- // Waypoint combat mode ( https://community.bistudio.com/wiki/setWaypointCombatMode )
- _wpCombatMode = "GREEN";
- // Driving behaviour of the vehicle group ( https://community.bistudio.com/wiki/setWaypointBehaviour )
- _behaviour = "CARELESS";
- // Target radius: if the car reaches this radius around the destination position, it is near enough and stops (destination zone)
- _targetRadius = 20;
- // Radius around the car in which debris/junk will be deleted (otherwise car stops or tries to get around somehow)
- _debrisRemoveRadius = 10;
- // Radius around the car in which Zombies will be killed (otherwise car stops or tries to get around somehow)
- _zedKillRadius = 15;
- // Height of the camera above target vehicle
- _camHeight = 60;
- // Classname/model of the driver
- _driverModel = "USMC_Soldier_Medic";
- // 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))
- _loopLimiter = 20;
- ////////// Configuration End //////////
- //###############################################################################################################################################
- // Keydown function
- fnc_key = {
- private ["_keyCode"];
- _keyCode = _this select 0;
- //diag_log format ["Player %1 (%2) has called their vehicle to them at %3. keyCode: %4",dayz_playerName,dayz_playerUID,(mapGridPosition getPos player), _keyCode];
- // F7 pressed (Cam mode)
- if ( (_keyCode == 65) ) then {
- if ( showCam ) then {
- showCam = false;
- } else {
- showCam = true;
- };
- };
- // F8 pressed (NV mode)
- if ( (_keyCode == 66) ) then {
- if ( showNV ) then {
- showNV = false;
- camUseNVG false;
- } else {
- showNV = true;
- camUseNVG true;
- };
- };
- };
- //###############################################################################################################################################
- // Exit if player has no watch in inventory
- _inventoryItems = [player] call BIS_fnc_invString;
- if ( !("ItemWatch" in _inventoryItems) ) exitWith {systemChat "JCC: You don't wear your watch. Calling not possible.";};
- // Get key Owner, key name from ui_selectSlot.sqf
- _keyOwner = _this select 0;
- _keyName = _this select 1;
- // Variable to remember if vehicle has been found in range
- _vehFoundInRange = false;
- // The target vehicle which belongs to the key
- _vehTarget = objNull;
- //---------------------------------------------------------------------------------------------------------
- // Compare with vehicles on map (allow only land vehicles)
- {
- _ownerID = _x getVariable ["CharacterID", "0"];
- if ( _keyOwner == _ownerID ) exitWith {
- _vehFoundInRange = true;
- _vehTarget = _x;
- };
- } count ( player nearEntities [["Car","Motorcycle","Tank"], _scanRadius] );
- //---------------------------------------------------------------------------------------------------------
- if (isNil "carRunning") then {carRunning = false;};
- // if vehicle has been found
- if (_vehFoundInRange) then {
- if (carRunning) exitWith {systemChat "JCC: You already have a vehicle on it's way to you!";};
- carRunning = true;
- // Get crew out
- if (alive driver _vehTarget) then {
- (driver _vehTarget) vehicleChat "I've got a job to do! Get out!!";
- sleep 0.5;
- (driver _vehTarget) action ["Eject", _vehTarget];
- sleep 2;
- };
- _vehDisplayName = gettext (configFile >> "CfgVehicles" >> (typeof _vehTarget) >> "displayName");
- //Fuel check
- if ( (fuel _vehTarget) < _minFuelLimit) exitWith { systemChat "JCC: Not enough fuel for the ride. Exit."; };
- systemChat format["JCC: (%1) KITT, come here... I need you buddy.",_vehDisplayName];
- //diag_log format ["Player %1 (%2) has called their vehicle to them at %3. keyCode: %4",dayz_playerName,dayz_playerUID,(mapGridPosition getPos player), _keyCode];
- // Variable init
- _timeBegin = 0;
- _timeEnd = 0;
- showCam = false;
- showNV = false;
- _doLoop = true;
- _count = 0;
- _destPos = player modelToWorld [0, 8, 0];
- // Start counter
- _timeBegin = time;
- // Create a unit group
- _vehGroup = createGroup WEST;
- _vehDriver = _vehGroup createUnit [_driverModel, _vehTarget, [], 0,"LIEUTENANT"];
- removeAllWeapons _vehDriver;
- removeAllItems _vehDriver;
- _vehDriver assignAsDriver _vehTarget;
- _vehDriver moveInDriver _vehTarget;
- _vehDriver setSkill 1;
- _vehGroup setBehaviour _behaviour;
- // Waypoint at destination where car should drive to
- _wayPoint = _vehGroup addwaypoint [_destPos, 0];
- _wayPoint setwaypointtype "MOVE";
- _wayPoint setWaypointSpeed _wpSpeed;
- _wayPoint setWaypointCombatMode _wpCombatMode;
- // Lock the vehicle
- _vehTarget setVehicleLock "LOCKED";
- // Add keydown Event Handler
- jccKeyDown = (findDisplay 46) displayAddEventHandler ["KeyDown","[_this select 1] call fnc_key; false;"];
- // Camera init
- cameraEffectEnableHUD true;
- showCinemaBorder true;
- _camera = "camera" camCreate [0,0,0];
- systemChat "JCC: Toggle CAM (F7) ... Toggle NV (F8)";
- // Loop until destination is reached, driver died or left car or car cannot move anymore
- for "_i" from 0 to 1 step 0 do {
- _count = _count + 1;
- _camera camSetTarget _vehTarget;
- _camera camSetRelPos [0, -20, _camHeight];
- _camera setVectorDirAndUp [[0,0.5,0.5],[0,-0.5,0.5]];
- _camera camCommitPrepared 0;
- _camera camCommit 0;
- // Do not execute the commands within the if condition too often (each _loopLimiter time only)
- if ( (_count mod _loopLimiter) == 0 ) then {
- if ( showCam ) then {
- _camera cameraeffect ["internal", "back"];
- } else {
- _camera cameraeffect ["terminate", "back"];
- };
- // Get rid of zombies
- _countZombies = _vehTarget nearEntities ["zZombie_Base", _zedKillRadius];
- if ( count _countZombies > 0 ) then {
- {
- _x setDamage 1;
- } count _countZombies;
- };
- // take the current time
- _timeEnd = time;
- // Show debug info
- hintSilent parseText format ["
- <t size='1.2' font='Bitstream' align='right' color='#5882FA'>JCC Autodrive Monitor</t><br/>
- <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/>
- <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Duration:</t><t size='1.0' font='Bitstream' align='right'>%4(s)</t><br/>
- <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/>
- <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Fuel:</t><t size='1.0' font='Bitstream' align='right'>%5(%6)</t><br/>
- <t size='1.0' font='Bitstream' align='left' color='#FFBF00'>Damage:</t><t size='1.0' font='Bitstream' align='right'>%3(%7)</t><br/>",
- (round ( _vehTarget distance _destPos)),
- (round (speed _vehTarget)),
- (round(100*(damage _vehTarget))),
- (round( _timeEnd - _timeBegin)),
- (round(100*(fuel _vehTarget))),
- "%","%"
- ];
- // Leave the loop if condition is true
- if ( (_vehTarget distance _destPos < _targetRadius ) OR ( !canMove _vehTarget ) OR ( {alive _x} count crew _vehTarget == 0 ) OR !( alive _vehDriver) ) exitWith { _doLoop = false;};
- //below is added by bomb/looter809 to fix issue with vehicle stuck in base
- 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;};};
- };
- // Get rid of debris/junk
- _countDebris = nearestObjects [(getPosATL _vehTarget), _debrisArray, _debrisRemoveRadius];
- if ( count _countDebris > 0 ) then {
- {
- deleteVehicle _x;
- } count _countDebris;
- };
- if ( !_doLoop ) exitWith { true };
- sleep 0.01;
- }; // end of loop
- sleep 1;
- // Destroy camera not needed anymore
- _camera cameraeffect ["terminate", "back"];
- camdestroy _camera;
- // Remove keydown Event Handler
- (findDisplay 46) displayRemoveEventHandler ["KeyDown", jccKeyDown];
- // Exit if driver is not alive (to send player right error message)
- if ( !(alive _vehDriver) ) exitWith {systemChat "JCC: Driver was killed. Exit."; carRunning = false;};
- // Nobody there to drive anymore
- if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit."; carRunning = false;};
- sleep 1;
- // Get crew out and delete members
- {
- moveOut _x;
- deleteVehicle _x;
- } forEach (crew _vehTarget);
- // Delete crew that got out before arrival / delete vehicle group
- {deleteVehicle _x} forEach units _vehGroup;
- deleteGroup _vehGroup;
- // Lock the vehicle again
- _vehTarget setVehicleLock "LOCKED";
- // Exit if vehicle cannot move (to send player right error message)
- if ( !canMove _vehTarget ) exitWith {systemChat "JCC: Vehicle cannot move anymore. Exit."; carRunning = false;};
- /*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.
- the 3rd makes it so it doesn't say fail when the driver gets to the player and stops*/
- 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;};};
- // Success message if car arrived in the destination zone
- 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)),"%","%"];
- carRunning = false;
- // If vehicle has not been found in range
- } else {
- systemChat format ["JCC: Car not found in range or key %1 does not belong to a car", _keyName];
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement