Jump to content

Call Car


Kimarik

Recommended Posts

Hi

 This Script is from jahangir13

Origina Script:

 

I don´t know if the script for using with masterkey works, i didn´t test it.

 but without masterkey it works fine

.

Script CallCar.sqf v0.1:

Spoiler

/////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////

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 ["keyCode: %1", _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"], _scanRadius] );
//---------------------------------------------------------------------------------------------------------    
    
// if vehicle has been found
if (_vehFoundInRange) then {
    _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];    
    
    // 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"];
    _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; };
        };
        
        // 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.";};
    // Nobody there to drive anymore
    if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit.";};
    
    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.";};    
    
    // 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)),"%","%"];
    
    
// 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];
 
};

ui_selectSlot.sqf:

Spoiler

///// jahan - begin CallCar
        // key colors
        _colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
        if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _item)) in _colors) then {
            // characterID of the key (car character number)
            _keyOwner = getNumber(configFile >> "CfgWeapons" >> _item >> "keyid");
            // key name (like: e3f2)
            _keyName = getText(configFile >> "CfgWeapons" >> _item >> "displayName");
            
            //Menu entry Key CallCar
            _control =  _parent displayCtrl (1600 + _numActions);
            _control ctrlShow true;
            _height = _height + (0.025 * safezoneH);
            // this needs to point the place where the script is in your mission (CallCar.sqf)
            _script =  "custom\jtools\CallCar.sqf";
            _exescript = format["_id = ['%2','%3'] execVM '%1';closeDialog 0;",_script,_keyOwner,_keyName];
            uiNamespace setVariable ['uiControl', _control];
            // sets the text in the right button menu
            _control ctrlSetText "Kitt, come here!";
            _control ctrlSetTextColor [0.3,0.4,1,1];
            _control ctrlSetTooltip "Call your car";
            _control ctrlSetTooltipColorBox [0.3,0.4,1,1];
            _control ctrlSetTooltipColorShade [0, 0, 0, 1];
            _control ctrlSetTooltipColorText [0.3,0.4,1,1];
            _control ctrlSetEventHandler ["ButtonClick",_exescript];
            _numActions = _numActions + 1; // if there are other item action after that (other mods) add 1 to _numactions
        };
///// jahan - end CallCar

Copy that below the for loop or any right click options.

I don´t know if the Battle Eye Filter are the same for Epoch 1.0.6.1 because i don´t use any BE filters.

Link to comment
Share on other sites

  • 3 months later...

Hello i use your call car script. And my Player love this. But my Players have found a Bug/Dupe. You can call your car and can shoot the Driver inside the Vehicle. The Driver fall out and its dead. Now you can take the weapon from the Driver. You can do this again and again and again. Can anywhere fix this? Remove the gear from the druver or remove the body ???  Sorry for my bad english and thanks

Link to comment
Share on other sites

8 hours ago, Tweety060286 said:

Hello i use your call car script. And my Player love this. But my Players have found a Bug/Dupe. You can call your car and can shoot the Driver inside the Vehicle. The Driver fall out and its dead. Now you can take the weapon from the Driver. You can do this again and again and again. Can anywhere fix this? Remove the gear from the druver or remove the body ???  Sorry for my bad english and thanks

Find this line

_vehDriver = _vehGroup createUnit [_driverModel, _vehTarget, [], 0,"LIEUTENANT"];

Place these lines below it

removeAllWeapons _vehDriver;
removeAllItems _vehDriver;

Let me know if that works.

Link to comment
Share on other sites

Ok, got this working but I have a couple of issues.

  1. This can be run on multiple vehicles from the same player at the same time. For example, if someone wanted to be malicious, they could buy a bunch of cheap vehicles, go to the opposite side of the map and call each car one right after the other.
  2. This can be run multiple times on the same vehicle which create a bunch of instances of it running that can bog down a server.

What do we have to do to limit these actions.

 

Link to comment
Share on other sites

  • 2 months later...

I'm trying to add vehicle selection menu for masterkey.
This is the callcar.sqf working in progress. I'll edit this when I found error I think it's ok now

Spoiler

/////////////////////////////////////////////////////////////////////
//
// Script: Call Car v0.1+ (11/2017)
// Created by: jahangir13 
// Modified by Schalldampfer, to allow vehicle selection for masterkey
// 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.
//
/////////////////////////////////////////////////////////////////////

private [
"_scanRadius", "_debrisArray", "_minFuelLevel", "_wpSpeed", "_wpCombatMode", "_behaviour", "_targetRadius", "_debrisRemoveRadius", "_zedKillRadius", "_camHeight", "_driverModel",
"_loopLimiter", "_keyCode", "_inventoryItems", "_keyOwner", "_keyName", "_vehTarget", "_vehList", "_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","Wreck_Base","Rubbish1","Rubbish2","Rubbish3","Rubbish4","Rubbish5","Land_Misc_Rubble_EP1","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 = "Functionary1_EP1_DZ";
// 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 ["keyCode: %1", _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;
        };
    };
};
//###############################################################################################################################################

if(!(isNull findDisplay 106)) then {findDisplay 106 closeDisplay 0}; // close gear menu

// Exit if player has no watch in inventory
_inventoryItems = [player] call BIS_fnc_invString;
if ( !("ItemRadio" in _inventoryItems) ) exitWith {systemChat "JCC: You don't have a radio. You can't call.";};

// Get key Owner, key name from ui_selectSlot.sqf
_keyOwner = _this select 0;
_keyName = _this select 1;

// The target vehicle which belongs to the key
_vehTarget = objNull;
_vehList = [];

//---------------------------------------------------------------------------------------------------------    
// Compare with vehicles on map (allow only land vehicles)
{
    _ownerID = _x getVariable ["CharacterID", "0"];
    if ( _keyOwner == _ownerID ) then {
        _vehList set [count _vehList,_x];//Add vehicle to list
    };

} count ( player nearEntities [["Car","Motorcycle","Tank"], _scanRadius] );
CC_vehID = count _vehList;
if (count _vehList == 0) exitWith {
    systemChat format ["JCC: Car not found in range or key %1 does not belong to a car", _keyName];
};
if (count _vehList == 1) then {
    CC_vehID = 0;
};

//---------------------------------------------------------------------------------------------------------    

//Selection menu
SelectKitt = [
    [format["Kitt, come! %1",_keyName],true],
    ["Select car to call", [0], "", -2, [["expression", ""]], "1", "0"]
];
{
    SelectKitt set[count SelectKitt, [ format["%1@%2", getText (configFile >> "CfgVehicles" >> (typeOf _x) >> "displayName"), mapGridPosition (getpos _x)], [0], "", -5, [ ["expression",format["CC_vehID=%1;CC_vehFoundInRange=true;",_forEachIndex]] ], "1", "1"] ];
} forEach _vehList;
SelectKitt set [count SelectKitt, ["Exit", [1], "", -3, [["expression", "CC_vehFoundInRange = false;"]], "1", "1"] ];
showCommandingMenu "#USER:SelectKitt";

//Wait for selection
waitUntil {(CC_vehID != count _vehList)||(commandingMenu == "")};
if (isNil 'CC_vehFoundInRange') then {CC_vehFoundInRange=false;};// Variable to remember if vehicle has been found in range

// if vehicle has been found
if (CC_vehFoundInRange) then {
    //Set selected Vehicle
    _vehTarget = _vehList select CC_vehID;

    // Get crew out
    if (alive driver _vehTarget) then {
        (driver _vehTarget) vehicleChat "The owner called this car. Let's eject!";
        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];

    // 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"];
    _vehDriver assignAsDriver _vehTarget;
    _vehDriver moveInDriver _vehTarget;
    _vehDriver setSkill 1;
    _vehGroup setBehaviour _behaviour;
    removeAllWeapons _vehDriver;
    removeAllItems _vehDriver;

    // 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; };
        };

        // 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.";deleteVehicle _vehDriver;deleteGroup _vehGroup;};
    // Nobody there to drive anymore
    if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit.";deleteVehicle _vehDriver;deleteGroup _vehGroup;};

    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.";};

    // 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)),"%","%"];


// If vehicle has not been found in range
} else {
    systemChat "JCC: None was selected";
};
 

I also added  crew ejection before AI drive

Edited by Schalldampfer
completed
Link to comment
Share on other sites

Did anyone figure out a way to fix:

Quote

Ok, got this working but I have a couple of issues.

  1. This can be run on multiple vehicles from the same player at the same time. For example, if someone wanted to be malicious, they could buy a bunch of cheap vehicles, go to the opposite side of the map and call each car one right after the other.
  2. This can be run multiple times on the same vehicle which create a bunch of instances of it running that can bog down a server.

What do we have to do to limit these actions.

?

 

Also, I tested this inside a base and it was not moving but the script didn't end.

( !canMove _vehTarget )

this doesn't seem to be stopping the script

Link to comment
Share on other sites

 

7 hours ago, looter809 said:

Did anyone figure out a way to fix:

?

 

Also, I tested this inside a base and it was not moving but the script didn't end.


( !canMove _vehTarget )

this doesn't seem to be stopping the script

This has always been an issue even in 1051. If there are player built walls up the AI will not be able to find a path very well. Ive suggested to all my players to make sure there is an open space for them. The two best ways to clear this issue out is to lobby log, or get in the vehicle urself and drive it to the location u called it to. Once you pull up to that spot it will stop the vehicle and kick you out of it as if it was delivered properly and the AI will despawn. 

Link to comment
Share on other sites

@Runewulv So maybe to fix that issue I'll test some ideas later when I'm home that use something like if speed = 0 for more than 10 seconds then end script. I have a few ideas how that would look so I'll mess around with it and see if I can fix that. I also have an idea how to fix the problem with being able to call the script more than once at a time. Both problems sound easy to fix in my head, so it'll be a fun test to see if I have enough C++ knowledge to fix it.

Link to comment
Share on other sites

@Runewulv Okay! I got the problem that @Schalldampfer posted above. Problem: Player can call the script as many times as they want with the same vehicle or a bunch of vehicles causing the server to bog down. When testing the fact that multiple people can call the car at the same time if they both have the key, I found that the script actually works just fine and whoever calls it last will have the vehicle go to them and the AI the first person called gets ejected and will delete after a minute or two.

You can figure out what I added by just searching "carRunning". https://pastebin.com/p0UW1uBh  (Note that if you copy the whole script, I did enable tanks to be driven by the AI. So if you don't want that option valid, go to "count ( player nearEntities" and remove "tank".

I'll work on the stuck car problem next.

Link to comment
Share on other sites

@Runewulv & @Schalldampfer https://pastebin.com/xBttdSU7 This has the fix for vehicle being stuck in a base. I didn't see if the variable "canMove" is defined anywhere, I imagine it's a true variable for the AI system, so I left it alone. But you can see what I fixed in this version in my comments near the added code. I will next be making the script cost coins to call since I find it sort of OP of a script, if you guys want the edits I make for that as well let me know and I can post it too. Or I could add to the script so it asks for briefcases if you don't use coins.

And I know my C++ writing could be improved, so if you see something I added to this script that could be improved feel free to teach me a lesson and show me what I did wrong. Thanks :)

 

Edit: Coins are now working on the script. If anyone wants my finished (at least for now) version of this awesome script let me know.

Link to comment
Share on other sites

2 hours ago, looter809 said:

@Runewulv Okay! I got the problem that @Schalldampfer posted above. Problem: Player can call the script as many times as they want with the same vehicle or a bunch of vehicles causing the server to bog down. When testing the fact that multiple people can call the car at the same time if they both have the key, I found that the script actually works just fine and whoever calls it last will have the vehicle go to them and the AI the first person called gets ejected and will delete after a minute or two.

You can figure out what I added by just searching "carRunning". https://pastebin.com/p0UW1uBh  (Note that if you copy the whole script, I did enable tanks to be driven by the AI. So if you don't want that option valid, go to "count ( player nearEntities" and remove "tank".

I'll work on the stuck car problem next.

 

1 hour ago, looter809 said:

@Runewulv & @Schalldampfer https://pastebin.com/xBttdSU7 This has the fix for vehicle being stuck in a base. I didn't see if the variable "canMove" is defined anywhere, I imagine it's a true variable for the AI system, so I left it alone. But you can see what I fixed in this version in my comments near the added code. I will next be making the script cost coins to call since I find it sort of OP of a script, if you guys want the edits I make for that as well let me know and I can post it too. Or I could add to the script so it asks for briefcases if you don't use coins.

And I know my C++ writing could be improved, so if you see something I added to this script that could be improved feel free to teach me a lesson and show me what I did wrong. Thanks :)

Thanks. I will check them and fix those issue, maybe in this weekend

Link to comment
Share on other sites

15 hours ago, looter809 said:

@Runewulv & @Schalldampfer https://pastebin.com/xBttdSU7 This has the fix for vehicle being stuck in a base. I didn't see if the variable "canMove" is defined anywhere, I imagine it's a true variable for the AI system, so I left it alone. But you can see what I fixed in this version in my comments near the added code. I will next be making the script cost coins to call since I find it sort of OP of a script, if you guys want the edits I make for that as well let me know and I can post it too. Or I could add to the script so it asks for briefcases if you don't use coins.

And I know my C++ writing could be improved, so if you see something I added to this script that could be improved feel free to teach me a lesson and show me what I did wrong. Thanks :)

 

Edit: Coins are now working on the script. If anyone wants my finished (at least for now) version of this awesome script let me know.

well done looter, in your pastebin does this also have  @Schalldampfer masterkey compatible menu added in?

Link to comment
Share on other sites

On 11/8/2017 at 1:37 AM, Runewulv said:

well done looter, in your pastebin does this also have  @Schalldampfer masterkey compatible menu added in?

 

On 11/8/2017 at 3:43 AM, looter809 said:

@Runewulv No sorry, I don't use masterkey so I didn't think about adding it. I'm sure you could take a look at my changes and his and figure out how to make both work. I also changed it so if there is a player/AI already in the driver seat the script exits before doing anything...

 

I added changes in those fix, hope this works:  (sorry, long spoiler again)

Spoiler

/////////////////////////////////////////////////////////////////////
//
// Script: Call Car v0.1 (12/2014)
// Created by: jahangir13 
// 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).
//Script Modified by Schalldampfer, to allow vehicle selection for masterkey (11/2017)
/////////////////////////////////////////////////////////////////////

private [
"_scanRadius", "_debrisArray", "_minFuelLevel", "_wpSpeed", "_wpCombatMode", "_behaviour", "_targetRadius", "_debrisRemoveRadius", "_zedKillRadius", "_camHeight", "_driverModel",
"_loopLimiter", "_keyCode", "_inventoryItems", "_keyOwner", "_keyName", "_vehTarget", "_vehList", "_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","Wreck_Base","Rubbish1","Rubbish2","Rubbish3","Rubbish4","Rubbish5","Land_Misc_Rubble_EP1","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 = "Functionary1_EP1_DZ";
// 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 ["keyCode: %1", _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;
        };
    };
};
//###############################################################################################################################################

if(!(isNull findDisplay 106)) then {findDisplay 106 closeDisplay 0}; // close gear menu

// Exit if player has no watch in inventory
_inventoryItems = [player] call BIS_fnc_invString;
if ( !("ItemRadio" in _inventoryItems) ) exitWith {systemChat "JCC: You don't have a radio. You can't call.";};

// Get key Owner, key name from ui_selectSlot.sqf
_keyOwner = _this select 0;
_keyName = _this select 1;

// The target vehicle which belongs to the key
_vehTarget = objNull;
_vehList = [];
CC_vehFoundInRange=false;// Variable to remember if vehicle has been found in range
if (isNil "carRunning") then {carRunning = false;};
//---------------------------------------------------------------------------------------------------------    
// Compare with vehicles on map (allow only land vehicles)
{
    _ownerID = _x getVariable ["CharacterID", "0"];
    if ( (!((typeOf _x) isKindOf "StaticWeapon") && !((typeOf _x) isKindOf "Air")) && (player distance _x < _scanRadius) && (_keyOwner == _ownerID) ) then {
        _vehList set [count _vehList,_x];//Add vehicle to list
    };
} count vehicles;
CC_vehID = count _vehList;
if (count _vehList == 0) exitWith {
    systemChat format ["JCC: Car not found in range or key %1 does not belong to a car", _keyName];
};
//---------------------------------------------------------------------------------------------------------    

//Selection menu
SelectKitt = [
    [format["Kitt, come! %1",_keyName],true],
    ["Select car to call", [0], "", -2, [["expression", ""]], "1", "0"]
];
{
    SelectKitt set[count SelectKitt, [ format["%1@%2", getText (configFile >> "CfgVehicles" >> (typeOf _x) >> "displayName"), mapGridPosition (getpos _x)], [0], "", -5, [ ["expression",format["CC_vehID=%1;CC_vehFoundInRange=true;",_forEachIndex]] ], "1", "1"] ];
} forEach _vehList;
SelectKitt set [count SelectKitt, ["Exit", [1], "", -3, [["expression", "CC_vehFoundInRange = false;"]], "1", "1"] ];

if (count _vehList == 1) then {
    CC_vehID = 0;
    CC_vehFoundInRange = true;
} else {
    showCommandingMenu "#USER:SelectKitt";
    //Wait for selection
    waitUntil {(CC_vehID != count _vehList)||(commandingMenu == "")};
};

// if vehicle has been found
if (CC_vehFoundInRange) then {
    //Set selected Vehicle
    _vehTarget = _vehList select CC_vehID;

    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 "The owner called this car. Let's eject!";
        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];

    // 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"];
    _vehDriver assignAsDriver _vehTarget;
    _vehDriver moveInDriver _vehTarget;
    _vehDriver setSkill 1;
    _vehGroup setBehaviour _behaviour;
    removeAllWeapons _vehDriver;
    removeAllItems _vehDriver;

    // 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;deleteVehicle _vehDriver;deleteGroup _vehGroup;};
    // Nobody there to drive anymore
    if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit."; carRunning = false;deleteVehicle _vehDriver;deleteGroup _vehGroup;};

    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 "JCC: None was selected";
};
 

 

Link to comment
Share on other sites

I've tested the fixes done by Looter809 with the additions added by Schalldampfer. It seems to be working well. My only issue is, the AI seems a bit too ready to abandon the vehicle. Depending on distance, I have to keep re-calling the vehicle because it will drive a random distance and then abandon the vehicle. So it's not bugging you to where you can't use it, but the abandon option is just a little too aggressive.

Link to comment
Share on other sites

1 hour ago, Runewulv said:

I've tested the fixes done by Looter809 with the additions added by Schalldampfer. It seems to be working well. My only issue is, the AI seems a bit too ready to abandon the vehicle. Depending on distance, I have to keep re-calling the vehicle because it will drive a random distance and then abandon the vehicle. So it's not bugging you to where you can't use it, but the abandon option is just a little too aggressive.

Hmmm. It works well for me, but this is on a test server with no lag on it. Are you watching the vehicle while it drives? Is it getting stuck on something?

Link to comment
Share on other sites

And this is to use with remoteVehicle script and its selection menu:

1. install remoteVehicle script

2. in overwrites\click_actions\config.sqf, add this

Spoiler

DZE_CLICK_ACTIONS = DZE_CLICK_ACTIONS + [["ItemKey","Call vehicle","execVM 'overwrites\click_actions\examples\callcar.sqf';","true",7]];

3. and make overwrites\click_actions\examples\callcar.sqf

Spoiler

/////////////////////////////////////////////////////////////////////
//
// Script: Call Car v0.1 (12/2014)
// Created by: jahangir13 
// 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).
//Script Modified by Schalldampfer, to allow vehicle selection for masterkey (11/2017)

//Selection menu from remoteVehicle script by @Salival (https://github.com/oiad/remoteVehicle)
/////////////////////////////////////////////////////////////////////

private [
"_scanRadius", "_debrisArray", "_minFuelLevel", "_wpSpeed", "_wpCombatMode", "_behaviour", "_targetRadius", "_debrisRemoveRadius", "_zedKillRadius", "_camHeight", "_driverModel",
"_loopLimiter", "_keyCode", "_keyID", "_keyName", "_vehTarget", "_characterID", "_vehDisplayName", "_vehicle", "_minFuelLimit",
"_timeBegin", "_timeEnd", "_doLoop", "_count", "_startPos", "_destPos", "_vehGroup", "_vehDriver", "_wayPoint", "_camera", "_countZombies", "_countDebris","_i",
"_exit","_foundPos","_vehicleFound"];

//###############################################################################################################################################
////////// 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","Wreck_Base","Rubbish1","Rubbish2","Rubbish3","Rubbish4","Rubbish5","Land_Misc_Rubble_EP1","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 = "Functionary1_EP1_DZ";
// 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 //////////
//###############################################################################################################################################

if (isNil "rv_init") then {
    if (getText (configFile >> "CfgMods" >> "DayZ" >> "version") == "DayZ Epoch 1.0.6.1") then {epoch_tempKeys = compile preprocessFileLineNumbers "scripts\remoteVehicle\epoch_tempKeys.sqf";}; // This can be removed when 1.0.6.2 comes out.
    rv_vehicleInfo = compile preprocessFileLineNumbers "scripts\remoteVehicle\vehicleInfo.sqf";
    rv_init = true;
};

disableSerialization;

// Keydown function
fnc_key = {
    private ["_keyCode"];
    _keyCode = _this select 0;
    //diag_log format ["keyCode: %1", _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 = {
    dayz_actionInProgress = false;
    rv_vehicleList = nil;
    rv_selected = nil;
};

//###############################################################################################################################################

if(!(isNull findDisplay 106)) then {findDisplay 106 closeDisplay 0}; // close gear menu

// Exit if player has no watch in inventory
if ( !("ItemRadio" in ([player] call BIS_fnc_invString)) ) exitWith {"You don't have a radio. You can't call." call dayz_rollingMessages;};

if (dayz_actionInProgress) exitWith {localize "str_player_actionslimit" call dayz_rollingMessages;};
dayz_actionInProgress = true;

// Get key Owner, key name from ui_selectSlot.sqf
_keyList = call epoch_tempKeys;
_keyID = 0;

_keyID = (_keyList select 0) select ((_keyList select 2) find (_this select 0));//characterID for key
_foundPos = (_keyList select 0) find _keyID;

if (_foundPos >= 0) then {
    _keyName = (_keyList select 1) select _foundPos;//display name
};

if (_foundPos == -1) exitWith {"No valid keys in your toolbelt." call dayz_rollingMessages; call _exit;};

if (isNil "carRunning") then {carRunning = false;};
//---------------------------------------------------------------------------------------------------------    
// Compare with vehicles on map (allow only land vehicles)
rv_vehicleList = [];
_vehicleFound = false;
{
    _characterID = _x getVariable ["CharacterID", "0"];
    if ( ( ((typeOf _x) isKindOf "LandVehicle") && !((typeOf _x) isKindOf "StaticWeapon") ) && (_characterID == _keyID) && (player distance _x < _scanRadius) ) then {
        _vehicleFound = true;
        rv_vehicleList set [count rv_vehicleList,_x];//Add vehicle to list
    };
} count vehicles;
if (!_vehicleFound) exitWith {"Unable to find a valid vehicle for this key." call dayz_rollingMessages; call _exit;};
//---------------------------------------------------------------------------------------------------------    

//Selection menu
rv_selected = nil;
if (count rv_vehicleList > 1) then {
    rv_isOk = false;

    createDialog "remoteVehicle";

    _display = uiNamespace getVariable["rv_dialog", displayNull];
    _display displayCtrl 8801 ctrlSetText(format ["Kitt, come! - Vehicles for %1",_keyDisplay]);

    _control = ((findDisplay 8800) displayCtrl 8802);
    lbClear _control;
    {
        _control lbAdd getText(configFile >> "CfgVehicles" >> typeOf _x >> "displayName");
        if (!isNull DZE_myVehicle && {local DZE_myVehicle} && {alive DZE_myVehicle} && {DZE_myVehicle == _x}) then {
            _control lbSetColor [(lbSize _control)-1,[0, 1, 0, 1]];
        };
    } count rv_vehicleList;
    _control lbSetCurSel 0;

    waitUntil {!dialog};

} else {
    rv_selected = rv_vehicleList select 0;
    rv_isOk = true;
};

if (!alive rv_selected) exitWith {"The vehicle has been destroyed." call dayz_rollingMessages; call _exit;};

//reset
_vehTarget = objNull;
dayz_actionInProgress = false;
rv_vehicleList = nil;

// if vehicle has been found
if (rv_isOk) then {
    //Set selected Vehicle
    _vehTarget = rv_selected;rv_selected = nil;

    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 "The owner called this car. Let's eject!";
        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];

    // 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"];
    _vehDriver assignAsDriver _vehTarget;
    _vehDriver moveInDriver _vehTarget;
    _vehDriver setSkill 1;
    _vehGroup setBehaviour _behaviour;
    removeAllWeapons _vehDriver;
    removeAllItems _vehDriver;

    // 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;deleteVehicle _vehDriver;deleteGroup _vehGroup;};
    // Nobody there to drive anymore
    if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit."; carRunning = false;deleteVehicle _vehDriver;deleteGroup _vehGroup;};

    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 "JCC: None was selected";
    call _exit;
};
 

The menu is created by @salival . Thank you!

Edited by Schalldampfer
Credit for menu
Link to comment
Share on other sites

Spoiler

/////////////////////////////////////////////////////////////////////
//
// Script: Call Car v0.1 (12/2014)
// Created by: jahangir13 
// 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).
//Script Modified by Schalldampfer, to allow vehicle selection for masterkey (11/2017)
// Credit to salival for remote key script
/////////////////////////////////////////////////////////////////////

private [
"_scanRadius", "_debrisArray", "_minFuelLevel", "_wpSpeed", "_wpCombatMode", "_behaviour", "_targetRadius", "_debrisRemoveRadius", "_zedKillRadius", "_camHeight", "_driverModel",
"_loopLimiter", "_keyCode", "_keyID", "_keyName", "_vehTarget", "_characterID", "_vehDisplayName", "_vehicle", "_minFuelLimit",
"_timeBegin", "_timeEnd", "_doLoop", "_count", "_startPos", "_destPos", "_vehGroup", "_vehDriver", "_wayPoint", "_camera", "_countZombies", "_countDebris","_i",
"_exit","_foundPos","_vehicleFound","_timesCarGotStuck"];

//###############################################################################################################################################
////////// 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","Wreck_Base","Rubbish1","Rubbish2","Rubbish3","Rubbish4","Rubbish5","Land_Misc_Rubble_EP1","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 = "Functionary1_EP1_DZ";
// 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 //////////
//###############################################################################################################################################

if (isNil "rv_init") then {
    if (getText (configFile >> "CfgMods" >> "DayZ" >> "version") == "DayZ Epoch 1.0.6.1") then {epoch_tempKeys = compile preprocessFileLineNumbers "scripts\remoteVehicle\epoch_tempKeys.sqf";}; // This can be removed when 1.0.6.2 comes out.
    rv_vehicleInfo = compile preprocessFileLineNumbers "scripts\remoteVehicle\vehicleInfo.sqf";
    rv_init = true;
};

disableSerialization;

// Keydown function
fnc_key = {
    private ["_keyCode"];
    _keyCode = _this select 0;
    //diag_log format ["keyCode: %1", _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 = {
    dayz_actionInProgress = false;
    rv_vehicleList = nil;
    rv_selected = nil;
};

//###############################################################################################################################################

if(!(isNull findDisplay 106)) then {findDisplay 106 closeDisplay 0}; // close gear menu

// Exit if player has no watch in inventory
if ( !("ItemRadio" in ([player] call BIS_fnc_invString)) ) exitWith {"You don't have a radio. You can't call." call dayz_rollingMessages;};

if (dayz_actionInProgress) exitWith {localize "str_player_actionslimit" call dayz_rollingMessages;};
dayz_actionInProgress = true;

// Get key Owner, key name from ui_selectSlot.sqf
_keyList = call epoch_tempKeys;
_keyID = 0;

_keyID = (_keyList select 0) select ((_keyList select 2) find (_this select 0));//characterID for key
_foundPos = (_keyList select 0) find _keyID;

if (_foundPos >= 0) then {
    _keyName = (_keyList select 1) select _foundPos;//display name
};

if (_foundPos == -1) exitWith {"No valid keys in your toolbelt." call dayz_rollingMessages; call _exit;};

if (isNil "carRunning") then {carRunning = false;};
//---------------------------------------------------------------------------------------------------------    
// Compare with vehicles on map (allow only land vehicles)
rv_vehicleList = [];
_vehicleFound = false;
{
    _characterID = _x getVariable ["CharacterID", "0"];
    if ( ( ((typeOf _x) isKindOf "LandVehicle") && !((typeOf _x) isKindOf "StaticWeapon") ) && (_characterID == _keyID) && (player distance _x < _scanRadius) ) then {
        _vehicleFound = true;
        rv_vehicleList set [count rv_vehicleList,_x];//Add vehicle to list
    };
} count vehicles;
if (!_vehicleFound) exitWith {"Unable to find a valid vehicle for this key." call dayz_rollingMessages; call _exit;};
//---------------------------------------------------------------------------------------------------------    

//Selection menu
rv_selected = nil;
if (count rv_vehicleList > 1) then {
    rv_isOk = false;

    createDialog "remoteVehicle";

    _display = uiNamespace getVariable["rv_dialog", displayNull];
    _display displayCtrl 8801 ctrlSetText(format ["Kitt, come! - Vehicles for %1",_keyDisplay]);

    _control = ((findDisplay 8800) displayCtrl 8802);
    lbClear _control;
    {
        _control lbAdd getText(configFile >> "CfgVehicles" >> typeOf _x >> "displayName");
        if (!isNull DZE_myVehicle && {local DZE_myVehicle} && {alive DZE_myVehicle} && {DZE_myVehicle == _x}) then {
            _control lbSetColor [(lbSize _control)-1,[0, 1, 0, 1]];
        };
    } count rv_vehicleList;
    _control lbSetCurSel 0;

    waitUntil {!dialog};

} else {
    rv_selected = rv_vehicleList select 0;
    rv_isOk = true;
};

if (!alive rv_selected) exitWith {"The vehicle has been destroyed." call dayz_rollingMessages; call _exit;};

//reset
_vehTarget = objNull;
dayz_actionInProgress = false;
rv_vehicleList = nil;

// if vehicle has been found
if (rv_isOk) then {
    //Set selected Vehicle
    _vehTarget = rv_selected;rv_selected = nil;

    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 "The owner called this car. Let's eject!";
        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];

    // Variable init
    _timeBegin = 0;
    _timeEnd = 0;
    showCam = false;
    showNV = false;
    _doLoop = true;
    _count = 0;
    _timesCarGotStuck = 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"];
    _vehDriver assignAsDriver _vehTarget;
    _vehDriver moveInDriver _vehTarget;
    _vehDriver setSkill 1;
    _vehGroup setBehaviour _behaviour;
    removeAllWeapons _vehDriver;
    removeAllItems _vehDriver;

    // 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 {_timesCarGotStuck = _timesCarGotStuck + 1;};
            if ( _timesCarGotStuck > 20) exitWith { systemChat "Uh oh! Your car seems stuck!";};
        };

        // 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;deleteVehicle _vehDriver;deleteGroup _vehGroup;};
    // Nobody there to drive anymore
    if ( {alive _x} count crew _vehTarget == 0 ) exitWith {systemChat "JCC: Nobody in the car anymore. Exit."; carRunning = false;deleteVehicle _vehDriver;deleteGroup _vehGroup;};

    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.*/
    if (_timesCarGotStuck > 20) 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 "JCC: None was selected";
    call _exit;
};

Here's the fixed version of what I last posted with @Schalldampfer's remote script as well. I don't personally use the remote vehicle script (thought about it, still kind of on the fence), but I have added a couple more options on my personal file. One addition I have added is coins as I stated before. The other addition is adding a small part of the knight rider theme song which plays on repeat on the server side (took me forever to get the repeat to work lol, I kind of wonder if there was an easier way, but I tried multiple methods...) If anyone wants the coins and knight rider theme additions just let me know.

(the fix i did from last time to this time fixes the problem @Runewulv said with the new method of checking if the car is stuck. I have it at 20 checks atm but it may do better with more/less)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...