Jump to content
  • 0
striker

[Semi - Completed] Crash Loot Script - Arma 3

Question

Hello Epoch Community,

 

It's me again with another idea worked out, ishh...

 

I have always had this idea in my head for a while, just a little promo before I explain

 

https://www.youtube.com/watch?v=DSWkntxddhE&feature=youtu.be

 

Well, a while back while playing dayz, I had a vehicle with items in that got destroyed. Not that anything really important was destroyed, but the idea of having the loot spawn around the destroyed vehicle like the heli crashes crossed my mind. Since then, it was always on my mind until today, when I finally decided to create it, for arma 3, or course.

 

The Gist:

When the vehicle is destroyed, it takes the inventory of the vehicle and scatters it on the ground

 

Features:

Check if locked - for obvious reasons, we don't want to incline people to destroy every vehicle

Update every 4 seconds - from the server side, the vehicles are updated with their latest information

Happens for every vehicle - every vehicle that is in Arma 3 can have this attached automatically

 

This script would just reside on the server side.

 

Once again, if any devs want it, let me know.

 

Thanks!  :)

 

 

 

EDIT: I have finished my crash loot script to some extent. I have not added destroyed chance for the item as I don't know how the dev's would want to handle it. I have the basic handle when killed and 10 second refresh on the gear variables. Works like a charm and I have not seen it fail yet. If the dev's would like the scripts, just message me. For some reason if(locked _unit) does not work in arma 3, I have no idea why. So you might have to handle lock in a variable. Just stick the script files in the mission folder and you are all set to go!

Share this post


Link to post
Share on other sites

25 answers to this question

Recommended Posts

  • 0

Gaza, that was next on my list of things to do. I just set up a dev server so I can truly test it in a dedicated server environment. Once that is settled, I'll start adding all of the good stuff. :)

Lacost, as so as everything is settled server/client wise for arma 3, it should be as simple as dropping the file into a mission folder for arma 2.

Share this post


Link to post
Share on other sites
  • 0

I re-created the script which I have moved most of it off the server. It also barely uses any set variables, however some are used under certain scenarios. There is no update required other then adding the eventHandlers. It is pretty much done if you would like it and improve it more.

Share this post


Link to post
Share on other sites
  • 0

Hmm Think this just breaks some of the RP in epoch, now I Can just use the machine gun on every thing, I will get the loot any way. before I had to head shoot people or shoot out the wheels,

This here is noob mod on

Share this post


Link to post
Share on other sites
  • 0

Wow this idea Is amazing.. This should be In basic Epoch, But yeah there has to be a %chance% some stuff should get destroyed so the player still loses some items or if there is a camper down the road and blows up the passing car they will not gain as much stuff as they could have if they just shot the driver :) Really nice idea tho and I would love to see it implemented Into standard Epoch :)

Share this post


Link to post
Share on other sites
  • 0
Really like this concept. kudos on implementing it. I'd love to get it on GG's servers and play around with the idea as well. Perhaps see if i can get probability working.  if you are still sharing it that is. =) 
Your inbox is full btw. tried msging ya.
 
cheers,
-produkt

Share this post


Link to post
Share on other sites
  • 0

Hmm Think this just breaks some of the RP in epoch, now I Can just use the machine gun on every thing, I will get the loot any way. before I had to head shoot people or shoot out the wheels,

This here is noob mod on

 

Talking about RP ? Destroying a vehicle doesnt destroy all the items in that vehicle.

 

This scripts  drops all of that out. and Ofc with some tweaking, some items would be damaged, deleted and etc

Share this post


Link to post
Share on other sites
  • 0

So I've made a partial solution for this ghost code

1. To save vehicle data, in epoch_server\init\server_init.sqf add:

Spoiler


//Loop
[] spawn {
    private ["_vehicles","_veh","_target","_dist"];
    //CrashLoot - save once
    {
        _x setVariable ["InventoryData",_x call EPOCH_server_CargoSave,false];
    } forEach EPOCH_allVehicles;
    _vehicles = [];
    
    //Main Loop
    while {true} do {
        {
            if (alive _x) then {
                _veh = vehicle _x;
                //Add vehicles in array
                if (_veh != _x) then {
                    _vehicles pushBackUnique _veh;
                };
            };
        } forEach allPlayers;
        //CrashLoot - vehicles
        {
            _x setVariable ["InventoryData",_x call EPOCH_server_CargoSave,false];
        } forEach _vehicles;
        sleep 5;
    };
};

at the bottom.

2. In epoch_server\compile\epoch_vehicle\EPOCH_load_vehicles.sqf add:

Spoiler

EPOCH_allVehicles = _allVehicles;

at just before the last line "true", to save allVehicles array.

3. Finally, To spawn crashLoot on destruction, in epoch_server/compile/epoch_vehicle/EPOCH_server_save_killedVehicle.sqf, add

Spoiler

        //crashLoot
        _pos = getPos _vehicle;
        [("groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0]), (_vehicle getVariable ["InventoryData",[]])] call EPOCH_server_CargoFill;

at the bottom of "if (_vehSlot != "ABORT") then {" block. It will be

Spoiler

/*
    Author: Aaron Clark - EpochMod.com

    Contributors:

    Description:
    Killed building handler

    Licence:
    Arma Public License Share Alike (APL-SA) - https://www.bistudio.com/community/licenses/arma-public-license-share-alike

    Github:
    https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_vehicle/EPOCH_server_save_killedVehicle.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_vehHiveKey","_vehSlot"];
//[[[end]]]
params ["_vehicle","_killer"];
if (!isNull _vehicle) then {
    _vehSlot = _vehicle getVariable ["VEHICLE_SLOT", "ABORT"];
    if (_vehSlot != "ABORT") then {
        _vehHiveKey = format ["%1:%2", (call EPOCH_fn_InstanceID), _vehSlot];
        ["Vehicle", _vehHiveKey] call EPOCH_fnc_server_hiveDEL;
        EPOCH_VehicleSlots pushBackUnique _vehSlot;

        missionNamespace setVariable ['EPOCH_VehicleSlotCount', count EPOCH_VehicleSlots, true];

        ['VehicleKilled', format["%1 was killed by %2 at %3", typeOf _vehicle, _killer, getPosATL _vehicle]] call EPOCH_fnc_server_hiveLog;

        //crashLoot
        _pos = getPos _vehicle;
        [("groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0]), (_vehicle getVariable ["InventoryData",[]])] call EPOCH_server_CargoFill;
    };
};
 

I dont know how to check vehicles which players just opened its inventory without getting in it, without checking all EPOCH_allVehicles array.


Is there any function that treats vehicle contents, when players opend&closed its inventory?  

Share this post


Link to post
Share on other sites
  • 0

@Schalldampfer

I think only this one addition should do the whole job (not tested):

Add to the end of this file: epoch_server\compile\epoch_vehicle\EPOCH_server_save_killedVehicle.sqf:

 //crashLoot
 if (!isnull _vehicle) then {
	_pos = getPos _vehicle;
	["groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0], [_vehicle] call EPOCH_server_CargoSave] call EPOCH_server_CargoFill;
};

 

You can read out the Inventory from already destroyed Vehicles. I also do it for some log.

Share this post


Link to post
Share on other sites
  • 0
5 hours ago, He-Man said:

@Schalldampfer

I think only this one addition should do the whole job (not tested):

Add to the end of this file: epoch_server\compile\epoch_vehicle\EPOCH_server_save_killedVehicle.sqf:

 //crashLoot
 if (!isnull _vehicle) then {
	_pos = getPos _vehicle;
	["groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0], [_vehicle] call EPOCH_server_CargoSave] call EPOCH_server_CargoFill;
};

 

You can read out the Inventory from already destroyed Vehicles. I also do it for some log.

thanks, I'll test it.

Share this post


Link to post
Share on other sites
  • 0

@Schalldampfer

I found out, that Epoch_server_cargosave will not 100% work on killed Vehicles.

It will not pushback backpacks and items, but weapons, magazines and subcontainers.

Maybe an issue in Arma, not sure.

But I have added a workaround to the experimental files, that Backpacks (and items within Backpacks) will also work now.
But Items are still an issue (this means ItemGPS, ItemCompass, ItemWatch, weapon attachments ..., but no Epoch Items like mortar, metal....)

So here is the needed change in the Epoch Files:
https://github.com/EpochModTeam/Epoch/commit/297b2c04734b872b8769c3f972cf29c4b80c000e

And I have another (in the case better code) you can simply run in your Init (without any other changes in any other files):

if (isserver) then {
	addMissionEventHandler ["EntityKilled",{
		params ["_killed", "_killer", "_instigator"];
		if (_killed isKindOf "Landvehicle" || _killed isKindOf "SHIP" || _killed isKindOf "AIR") then {
			if (!istouchingGround _killed) exitwith {
				_killed spawn {
					_start = diag_ticktime;
					waituntil {uisleep 2; (isTouchingGround _this && speed _this < 1) || diag_ticktime - _start > 10};
					if (!isnull _this && !(surfaceiswater (getpos _this))) then {
						_pos = getPos _this;
						["groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0], _this call EPOCH_server_CargoSave] call EPOCH_server_CargoFill;
					};
				};
			
			};
			_pos = getPos _killed;
			["groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0], _killed call EPOCH_server_CargoSave] call EPOCH_server_CargoFill;
		};
	}];
};

You can call in any script, the Server is running on startup.

Oh and thx to @Tarabas for his hint about the Eventhandler "EntityKilled". I was not aware about it before

Share this post


Link to post
Share on other sites
  • 0

I noticed VGS calls EPOCH_server_save_killedVehicle on storing, so I think I need to check it.

Spoiler

/*
    Author: IT07

    Contributor: DirtySanchez from DonkeyPunch.INFO
    
    Description:
    Write Vehicle to client Garage
    
    Returns:
    remoteExecCall to client updated garage contents
*/
params [ 
    ["_slot", -1, [0]],
    ["_vehObj", objNull, [objNull]],
    ["_playerObj", objNull, [objNull]],
    ["_playerKey", "", [""]] 
];
// debug start message
_debug = "debug" call SC_fnc_vgsGetClientSetting;
if (_debug isEqualTo 1) then {diag_log format["[EPOCH VGS]: WriteToGarage _data = %1", [_slot, _vehObj, _playerObj, _playerKey]]};

if isNull _playerObj exitWith    {diag_log format["[EPOCH VGS]: WriteToGarage Player isNull - data:%1", _playerObj]};

if !([_playerObj, _playerKey] in (uiNamespace getVariable "EPOCH_vgsKeys"))exitWith{diag_log format["[EPOCH VGS]: WriteToGarage Bad Player and Key - data:%1", [_playerObj, _playerKey]]};

if (_slot isEqualTo -1) exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Error - slot number is -1 - data:%1", _slot]};

_slots = "maxGarageSlots" call VGS_fnc_vgsGetServerSetting;
if !(_slot < _slots) exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Error - slot not less than max slots - data:%1", [_slot, _slots]]};

if isNull _vehObj exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Vehicle isNull - data:%1", _vehObj]};

if isPlayer _vehObj exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Vehicle isPlayer - data:%1", _vehObj]};

if !((owner _vehObj) isEqualTo (owner _playerObj)) exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Player not Vehicle Owner - data:%1", _vehObj]};

_blacklist = "vehBlacklist" call VGS_fnc_vgsGetServerSetting;
if (typeOf _vehObj in _blacklist) exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Vehicle is BlackListed - data:%1", _vehObj]};

_maxDist = "range" call SC_fnc_vgsGetClientSetting;
if !(((position _playerObj) distance (position _vehObj)) < _maxDist) exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Vehicle is too far > data:%1m", _maxDist]};

// Define player's UID
_playerUID = getPlayerUID _playerObj;
// Define the classname of _veh
_typeOf = typeOf _vehObj;
// Get the storage usage
_inventory = _vehObj call EPOCH_server_CargoSave;

_pos = getPosATL _vehObj;
_dir = getDir _vehObj;
// Get the fuel level of _veh
_fuel = fuel _vehObj;
// Get the hitPoint(s) damage of given vehicle
_hitpoints = (getAllHitPointsDamage _vehObj) param [2,[]];

// Get existing vehicles
_response = ["VirtualGarage", _playerUID] call EPOCH_fnc_server_hiveGETRANGE;
if((_response select 1) isEqualTo []) exitWith {diag_log format["[EPOCH VGS]: WriteToGarage Client DB entry error - data:%1m", _response]};
if ((_response select 0) isEqualTo 1) then
{
    if (typeName (_response select 1) isEqualTo "ARRAY") then
    {
        _vehsFriendly = _response select 1 select 0;
        _vehsRaw = _response select 1 select 1;
        if not(count _vehsFriendly isEqualTo 0) then
        { // If there is already a vehicle, clear it
            _vehsFriendly set [_slot, []];
            _vehsRaw set [_slot, []];
        };
        (_vehsFriendly select _slot) pushBack _typeOf;
        {
            (_vehsRaw select _slot) pushBack _x
        } forEach [_typeOf, [(getposATL _vehObj call EPOCH_precisionPos),vectordir _vehObj,vectorup _vehObj], damage _vehObj, _hitpoints, _fuel, _inventory, [true,magazinesAllTurrets _vehObj], _vehObj getVariable ["VEHICLE_TEXTURE",0], _vehObj getVariable ["VEHICLE_BASECLASS",""]];
        _expiresVG = "expiresVirtualGarage" call VGS_fnc_vgsGetServerSetting;
        _return = ["VirtualGarage", _playerUID, _expiresVG, [_vehsFriendly, _vehsRaw]] call EPOCH_fnc_server_hiveSETEX;
        {
            moveOut _x;
        } forEach (crew _vehObj);
        [_vehObj, format["VGSMoveIn_%1",_playerUID]] call  EPOCH_server_save_killedVehicle;
        deleteVehicle _vehObj;
        if not(isNull _playerObj) then
        {
            ["Garage", _vehsFriendly] remoteExecCall ["SC_fnc_vgsRecvFromServer",owner _playerObj];
            // debug end message
            if (_debug isEqualTo 1) then {diag_log format["[EPOCH VGS]: WriteToGarage Client (%1) put his/her %2 in garage", name _playerObj, _typeOf]};
        };
    };
};

so the code to add (into EPOCH_server_save_killedVehicle) maybe

Spoiler

        //crashLoot
        if !("VGSMoveIn_" in _killer) then {
            _pos = getPos _vehicle;
            [("groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0]), ([_vehicle] call EPOCH_server_CargoSave)] call EPOCH_server_CargoFill;
        };

 

Share this post


Link to post
Share on other sites
  • 0

@Schalldampfer

I do not really know the VG script. But from your code above, I would directly add it into the VG code:

[_vehObj, format["VGSMoveIn_%1",_playerUID]] call  EPOCH_server_save_killedVehicle;

	// put Items on the ground
	_pos = getPos _vehObj;
	["groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0], _vehObj call EPOCH_server_CargoSave] call EPOCH_server_CargoFill;

deleteVehicle _vehObj;

 

Share this post


Link to post
Share on other sites
  • 0

 

19 hours ago, He-Man said:

@Schalldampfer

I do not really know the VG script. But from your code above, I would directly add it into the VG code:

[_vehObj, format["VGSMoveIn_%1",_playerUID]] call  EPOCH_server_save_killedVehicle;

	// put Items on the ground
	_pos = getPos _vehObj;
	["groundWeaponHolder" createVehicle [_pos select 0, _pos select 1, 0], _vehObj call EPOCH_server_CargoSave] call EPOCH_server_CargoFill;

deleteVehicle _vehObj;

 

Why you need to duplicate items in vehicles twice...
Items are stored in vehicle, and EPOCH_server_save_killedVehicle duplicates them on ground, and again put items on the ground?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Advertisement
  • Supporters
  • Discord

×
×
  • Create New...