Jump to content

[RELEASE] Remove All Vehicle Ammo


Recommended Posts

Soooo, after quite a while of being away (poorly, blah blah) I've finally been able to come back to ArmA scripting about a month ago, woo.
And to kick things off I decided to make a solution for a problem I used to see very often and is probably still fairly common now, getting non DZ/DZE suffixed vehicles to spawn without ammo on server restarts or after being bought. (I actually created this as a feature of CSAT!)
I've seen solutions where people do something along the lines of-

if (_this isKindOf 'BLAAAAAAAAAH') then {
    _this removeWeapon 'cannon';
    _this removeWeapon 'something';
    .......
    ..... and so on.
};

if (_this isKindOf 'MEHHHHHHHH') then {
    blah blah blah;
};



It's a fine solution, if you're only planning on having a few non standard vehicles on your server but it's a gigantic pain in the arse when you want as many vehicles as you can get. This is where my solution comes into play, it's a single function that is run on every vehicle on server start or on being bought or whatever and will remove every magazine from the vehicle with the exception of the pilot's flares and horn.
 

Installation is fairly straight forward too, which is always nice :)

 

Step 1:

At the very top of your server_functions.sqf file add this little nugget (And create the corresponding file, serverside):

[] ExecVM "whatever/file/path/you/like.sqf"; // Please, for the love of all that is holy, don't use this file path.

Step 2:

Wherever the file is you chose to create, add this into it:

removeVehicleAmmo = {
    private ['_getTurretPaths','_removalPath'];

    _getTurretPaths = { // Find every turret path on the vehicle with exception of [-1], driver.
        private ['_return','_tracker'];
        _return = [];

        _tracker = {
            private ['_config','_path','_path2','_class'];
            _config = (_this select 0);
            _path = +(_this select 1);
            for '_i' from 0 to ((count _config) - 1) do {
                _class = (_config select _i);
                if (isClass _class) then {
                    _path2 = (_path + [_i]);
                    _return set [(count _return),_path2];
                    _class = (_class >> 'turrets');
                    if (isClass _class) then {
                        [_class,_path2] call _tracker;
                    };
                };
            };
        };
        [(configFile >> 'cfgVehicles' >> (typeOf _this) >> 'turrets'),[]] call _tracker;
        _return
    };

    { // Remove turret magazines. (All but pilot)
        _removalPath = _x;
        {
            if (!(['flare',_x] call fnc_inString) && !(['horn',_x] call fnc_inString) ) then {
                _this removeMagazinesTurret [_x,_removalPath];
            };
            true
        } count (_this magazinesTurret _removalPath);
        true
    } count (_this call _getTurretPaths);

    { // Remove pilot magazines.
        {
            if (!(['flare',_x] call fnc_inString) && !(['horn',_x] call fnc_inString) ) then {
                _this removeMagazinesTurret [_x,[-1]];
            };
            true
        } count (getArray (configFile >> 'cfgWeapons' >> _x >> 'magazines'));
        true
    } count getArray(configFile >> 'cfgVehicles' >> (typeOf _this) >> 'weapons');
};


waitUntil {!isNil 'fnc_veh_ResetEH'};
new_fnc_veh_ResetEH = fnc_veh_ResetEH;
fnc_veh_ResetEH = {
    _this call new_fnc_veh_ResetEH;
    if (isServer) then {
        _this call removeVehicleAmmo;
    };
};

 

This works by over-writing your default fnc_veh_ResetEH, but only serverside so clients don't need to download extra mission data to get a new version of it. fnc_veh_ResetEH is called on every vehicle that is bought or spawned naturally in the world so it will affect every single vehicle. It's also important that you ExecVM your new file from the very top of server_functions.sqf because it needs to catch and replace the default fnc_veh_ResetEH before any vehicles start being made.

 

I can't be sure how it'll affect server start times on servers with hundreds of vehicles but on my dev server with a whopping 16 vehicles it made no difference.

Credit where it's due: Thanks to DenVdmj for the post found here, if I didn't find that I'd be still banging my head against my keyboard trying to figure out how to get turret paths correctly.

 

I've not tried it, but if you wanted to also apply this to vehicles that spawn at missions you could put this-

_this call fnc_veh_ResetEH;

 

inside wherever it is your mission system spawns it's vehicles and just replace _this with whatever variable references the mission vehicle. (No promises)

 

Enjoy! It's nice to be back :)

Link to comment
Share on other sites

That deals with the problem in the same way as in my first spolier tag, a-la

if (_this isKindOf 'BLAAAAAAAAAH') then {
    _this removeWeapon 'cannon';
    _this removeWeapon 'something';
    .......
    ..... and so on.
};

if (_this isKindOf 'MEHHHHHHHH') then {
    blah blah blah;
};

Which is what I wanted to avoid :)

Link to comment
Share on other sites

Yeah, I've done that myself too but I really wanted to be able to keep the flares in vehicles. The idea behind this was to be able to make every vehicle seem just like a vanilla DayZ/Epoch vehicle, no gun ammo but flares all round.

 

i think it would be easier to load some flares after than to remove magazines for each weapon instead, also if you remove a weapon from a vehicle there is really no need to remove the ammo also as it needs to be scripted to remove or use it after.

Link to comment
Share on other sites

  • 3 weeks later...
			if (_object isKindOf "AllVehicles") then {
				{
					_selection = _x select 0;
					_dam = _x select 1;
					if (_selection in dayZ_explosiveParts && _dam > 0.8) then {_dam = 0.8};
					[_object,_selection,_dam] call object_setFixServer;
				} count _hitpoints;

				_object setFuel _fuel;
				_object setVehicleAmmo 0;

				if (!((typeOf _object) in dayz_allowedObjects)) then {
					
					//_object setvelocity [0,0,1];
					_object call fnc_veh_ResetEH;		
					
					if(_ownerID != "0" && !(_object isKindOf "Bicycle")) then {
						_object setvehiclelock "locked";
					};
					
					_totalvehicles = _totalvehicles + 1;

					// total each vehicle
					serverVehicleCounter set [count serverVehicleCounter,_type];
				};
				
			};
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
  • Discord

×
×
  • Create New...