[Release] Prevent Repetitive Vehicle Actions

BDC

Well-Known Member
Howdy folks,

Am I the only one having problem with custom-made, vehicle-specific AddActions multiplying themselves every time a player exits and re-enters a vehicle? Well, I've found a way to solve it. It will prevent duplication of actions plus stop any actions, that are meant to be in_vehicle only, from popping up while outside of said vehicle. The way this mod works is by keeping track of when a client player mounts and dismounts from any vehicle by keeping a global boolean flag "s_player_inVehicle" up-to-date on said client's load. When exiting a vehicle, when the flag is still set to true, the flag is reset back to false and a routine is run to clear all actions.

This one's been bugging me for a while on my own server but finally hit it hard a few days ago to solve it. Thumper and OiFriendlyFire from offgaming.us helped point me in the right direction. An hour or two later, I had this annoying problem solved.

On to the solution. It's very simple. As far as I know, this will work on any DayZ server type.

Step 1) Gain access to variables.SQF and fn_selfActions.SQF

Variables.SQF must be modified. It can be found within \dayz_code\init folder and must be extracted out and used. There's a zillion threads on this on how to do it. The new Variables.SQF is to be called from either init.SQF or init2.SQF depending upon the server type you run.

fn_selfActions.SQF is found in \dayz_code\compile folder.

For those unfamiliar with getting access to these core-level functions, have a search here on the forum. They are both referenced in most of the addons posted on here.

Step 2) Modify variables.SQF

In variables.SQF, on or around line 230, look for the section commented with "//actions blockers".

Below that section, add this:

Code:
// Multiple (ever-duplicating) action removal flags by ^bdc
s_player_inVehicle = false; // fn_selfActions.sqf
s_player_inVehicleObj = nil;

Step 3) Modify fn_selfActions.SQF

In fn_selfActions.sqf, look for this chunk of code towards the very top of the file:

Code:
_vehicle = vehicle player;
_inVehicle = (_vehicle != player);
_cursorTarget = cursorTarget;
_primaryWeapon = primaryWeapon player;
_currentWeapon = currentWeapon player;
_onLadder = (getNumber (configFile >> "CfgMovesMaleSdr" >> "States" >> (animationState player) >> "onLadder")) == 1;

Directly below it, add this nice chunk:

Code:
// In Vehicle/Out of vehicle duplicate/multiple action clearing - ^bdc (thanks, Thumper)
if ((!s_player_inVehicle) and (_inVehicle)) then {
    s_player_inVehicle = true; // flag until player leaves
    s_player_inVehicleObj = _vehicle;
};

if ((s_player_inVehicle) and (!_inVehicle)) then {
    s_player_inVehicle = false;
    _tmpaction = s_player_inVehicleObj addAction["junk", "junk.sqf"];
    while {_tmpaction >= 0} do {
        s_player_inVehicleObj removeAction _tmpaction;
        _tmpaction = _tmpaction - 1;
    };
    diag_log format["fn_selfActions.SQF: Player dismounted from vehicle object %1. Clearing all actions.",s_player_inVehicleObj];
    s_player_inVehicleObj = nil;
};
// End In Vehicle/Out of vehicle

Make sure the new variables.SQF and fn_selfActions.SQF files are referenced properly instead of the original dayz_code.pbo ones.

Pretty simple.

B
 
Back
Top