Jump to content

Call Car


Kimarik

Recommended Posts

2 hours ago, looter809 said:
  Reveal hidden contents

/////////////////////////////////////////////////////////////////////
//
// 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", "_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)

Awesome Looter I will update my server now and take a look see. Thanks for tweaking! Have you ever tried working on Just Another Evac Mod? 

Link to comment
Share on other sites

6 hours ago, looter809 said:
  Reveal hidden contents

/////////////////////////////////////////////////////////////////////
//
// 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", "_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)

nice update!
Please add a line like "credit salival for remoteVehicle script", the selection menu itself comes from his remoteVehicle script.
(I have updated my post for missing credit. Sorry, salival!)

Link to comment
Share on other sites

Hey is anyone else getting kicked from Battleye? On my test server it works fine, but on my main server I get this kick message in my waypointstatements.log 

Spoiler

25.11.2017 15:24:02: ZzBombardierzZ (My IP) My GUID - Condition Restriction #0 ["true", ""] [7:237 group, 1]
25.11.2017 15:24:02: ZzBombardierzZ (My IP) My GUID - Condition RemoteExec Restriction #0 ["true", ""] [7:237 group, 1]

 

In waypointcondition.txt and waypointstatement.txt I have both as

Spoiler

//new
1 ""

and it still is kicking... ?

 

oops, i was missing the remoteexec.txt modifications. Nvm...

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