striker Posted December 4, 2014 Report Share Posted December 4, 2014 https://www.youtube.com/watch?v=nNbjP3EgBDI Description The purpose of this script is to scatter gear from player vehicles on the ground when they are destroyed. This script allows you to set many different settings to suit your needs. It runs mostly on the server side other than the config variable so you don't have to repack your PBO every time you want to make a change. You can enable or disable the script from spawning gear on the ground depending on if the vehicle is locked or not. This is a important one as it will prevent many people from going around and blowing up every vehicle they see ;) You can also state the min and max loot piles that you want to spawn around the vehicle. You can also set the radius that the loot piles will spawn in creating a nice random look (don't judge the video). The file controllable element at your disposal is the ability to set the chance the gear will be destroyed. More detail will be given when we implement the config variable in the init.sqf. Without further ado, let the installation begin! :lol: WARNING: Only use vehicles spawned by the server to test to see if the script is working. Infistar spawned vehicles will not work (However, HIVE spawned might). Installation Sever Side Script: Spoiler server_crashLoot.sqf Create a file named server_crashLoot.sqf in the compile folder of your dayz_server.pbo. (You actually put it where you want, you just need to change the file path) Once you have created the file, add the following code to it: private["_veh","_gear","_pos","_crashPile","_crashPiles","_element","_objWpnTypes","_objWpnQty","_isOK","_countr","_count","_cont","_temp","_rnd","_lockPrevent","_guaranteedLoot","_randomizedLoot","_radius","_chance"]; _veh = _this; _gear = _veh getVariable ["lastInventory", []]; if(isNil "DZE_crashLootConfig") then{ DZE_crashLootConfig = [true,2,5,5,0]; }; _lockPrevent = DZE_crashLootConfig select 0; _guaranteedLoot = DZE_crashLootConfig select 1; _randomizedLoot = DZE_crashLootConfig select 2; _radius = DZE_crashLootConfig select 3; _chance = DZE_crashLootConfig select 4; _crashPile = objNull; _crashPiles = []; _cont = false; if(_lockPrevent) then{ if(locked _veh) then{ _cont = false; }else{ _cont = true; }; }else{ _cont = true; }; if(((count _gear) > 0) && _cont) then{ //Wait for vehicle to stop moving sleep 1; _count = 0; while{(speed _veh) > 0.1 && _count <= 20} do{ sleep 0.1; _count = _count + 0.1; }; //Spawn the loot diag_log format["DEAD VEHICLE - server_crashLoot.sqf - %1",_gear]; _pos = getPos _veh; _num = round(random _randomizedLoot) + _guaranteedLoot; for "_x" from 1 to _num do { _temp = createVehicle ["WeaponHolder", [_pos select 0, _pos select 1, 0], [], _radius, "CAN_COLLIDE"]; _crashPiles = _crashPiles + [_temp]; }; //Add weapons _objWpnTypes = (_gear select 0) select 0; _objWpnQty = (_gear select 0) select 1; _countr = 0; { if(_x in (DZE_REPLACE_WEAPONS select 0)) then { _x = (DZE_REPLACE_WEAPONS select 1) select ((DZE_REPLACE_WEAPONS select 0) find _x); }; _isOK = isClass(configFile >> "CfgWeapons" >> _x); if (_isOK) then { _element = floor(random _num); _crashPile = _crashPiles select _element; for "_i" from 1 to (_objWpnQty select _countr) do { _rnd = random 1; if(_rnd >= _chance) then{ _crashPile addWeaponCargoGlobal [_x,1]; }; }; }; _countr = _countr + 1; } count _objWpnTypes; //Add Magazines _objWpnTypes = (_gear select 1) select 0; _objWpnQty = (_gear select 1) select 1; _countr = 0; { if (_x == "BoltSteel") then { _x = "WoodenArrow" }; // Convert BoltSteel to WoodenArrow if (_x == "ItemTent") then { _x = "ItemTentOld" }; _isOK = isClass(configFile >> "CfgMagazines" >> _x); if (_isOK) then { _element = floor(random _num); _crashPile = _crashPiles select _element; for "_i" from 1 to (_objWpnQty select _countr) do { _rnd = random 1; if(_rnd >= _chance) then{ _crashPile addMagazineCargoGlobal [_x,1]; }; }; }; _countr = _countr + 1; } count _objWpnTypes; //Add Backpacks _objWpnTypes = (_gear select 2) select 0; _objWpnQty = (_gear select 2) select 1; _countr = 0; { _isOK = isClass(configFile >> "CfgVehicles" >> _x); if (_isOK) then { _element = floor(random _num); _crashPile = _crashPiles select _element; for "_i" from 1 to (_objWpnQty select _countr) do { _rnd = random 1; if(_rnd >= _chance) then{ _crashPile addBackpackCargoGlobal [_x,1]; }; }; }; _countr = _countr + 1; } count _objWpnTypes; }; *This is the main file which handles checking requirements and spawning the gear on the ground. server_monitor.sqf Find the following line in the server_monitor.sqf: if (_object isKindOf "AllVehicles") then { And place the following after it: _object setVariable ["lastInventory", _intentory]; *This sets the "lastInventory" to the gear that was saved to the database (prevents the crashLoot script from dropping nothing when there really is something). server_updateObject.sqf Find the following line in server_updateObject.sqf: _object setVariable["lastInventory",_inventory]; And replace it with: if(alive _object) then{ _object setVariable["lastInventory",_inventory]; }; *This just makes sure that the "lastInventory" array isn't set back to nothing. Then find: _object_killed = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; And place the following after it: if(_object isKindOf "AllVehicles") then{ _object execVM "\z\addons\dayz_server\compile\server_crashLoot.sqf"; }; *This calls the crashLoot script when vehicle is destroyed. server_publishVehicle.sqf, server_publishVehicle2.sqf, server_publishVehicle3.sqfIn all three of these files find the following line: publicVariable "PVDZE_veh_Init"; If the file is server_publishVehicle3.sqf add the following after that line: _object setVariable ["lastInventory", [_weapons,_magazines,_backpacks]]; Else add the following after that line: _object setVariable ["lastInventory", []]; *This adds the variable to the published vehicles. That completes the server side! :) Mission Side Script: Spoiler init.sqf In the init.sqf, add the following near the top with the rest of the dayz variables: /* Revamped instructions by Ree select 0 = Locked vehicles Will not drop Loot ("Default: True") select 1 = The Amount of Loot Piles around destroyed vehicles ("Default: 2") out of Max amount ___? "Max Safe Amount" select 2 = Max additional loot piles On top of select 1 loot Piles ("Default: 5") out of Max amount ___? "Max Safe Amount" select 3 = Radius around crash site to drop loot ("Default: 5")m out of Max amount ___? "Max Safe Amount" select 4 = Chance of gear being destroyed (Between 0-1, Ex: 0 = Never lost, 0.5 = Half lost, 1 = All lost) Default: DZE_crashLootConfig = [true,2,5,5,0]; */ DZE_crashLootConfig = [true,2,5,5,0]; Version 1 - initial release Version 1.1 (Complete) - change code to use the _object_killed funciton(overlooked that one <_<) Appreciate and support my work? harcosgoogle, Linux, calamity and 8 others 11 Link to comment Share on other sites More sharing options...
CordIAsis Posted December 4, 2014 Report Share Posted December 4, 2014 Very nice mate! I was gonna have a go at this but then I realised it takes a little more that a killed eventHandler, so I couldn't be bothered XD Excellent work! Link to comment Share on other sites More sharing options...
striker Posted December 4, 2014 Author Report Share Posted December 4, 2014 Very nice mate! I was gonna have a go at this but then I realised it takes a little more that a killed eventHandler, so I couldn't be bothered XD Excellent work! Thanks! :D striker Link to comment Share on other sites More sharing options...
Gr8 Posted December 4, 2014 Report Share Posted December 4, 2014 Using Infistar, Tried RPG and C4 but no go Link to comment Share on other sites More sharing options...
striker Posted December 4, 2014 Author Report Share Posted December 4, 2014 Using Infistar, Tried RPG and C4 but no go Where vehicles spawned with infistar? If so, it will not work. However, with v1.1, vehicles spawned with the hive method should work fine. striker Link to comment Share on other sites More sharing options...
Gr8 Posted December 4, 2014 Report Share Posted December 4, 2014 Where vehicles spawned with infistar? If so, it will not work. However, with v1.1, vehicles spawned with the hive method should work fine. striker Right, wasnt using the Hive Vehicles, ill try it report the result Link to comment Share on other sites More sharing options...
striker Posted December 4, 2014 Author Report Share Posted December 4, 2014 Right, wasnt using the Hive Vehicles, ill try it report the result Remember, HIVE Vehicles will only work with the new version of the script. You might of installed the old one striker Link to comment Share on other sites More sharing options...
Gr8 Posted December 4, 2014 Report Share Posted December 4, 2014 I replaced my server_crashLoot.sqf to the latest. What else do i need to change. Hive Infistar vehicles still dont work. even the trader ones dont Link to comment Share on other sites More sharing options...
zipper Posted December 4, 2014 Report Share Posted December 4, 2014 Thank you very very very much for this striker, my players will enjoy this one :P Link to comment Share on other sites More sharing options...
striker Posted December 4, 2014 Author Report Share Posted December 4, 2014 I replaced my server_crashLoot.sqf to the latest. What else do i need to change. Hive Infistar vehicles still dont work. even the trader ones dont Alright, remove everything done to server_functions.sqf, no longer need to use this file for the script. Should just need to remove the following from the file: if(_unit isKindOf "AllVehicles") then{ //execVM instead of function so we can sleep _unit execVM "\z\addons\dayz_server\compile\server_crashLoot.sqf"; }; Remove all the addMPEventHandlers you added from ALL THE FILES. They should look like the one below _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}]; Open up server_updateObject.sqf and search for _object_killed = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; Add the following under it if(_object isKindOf "AllVehicles") then{ //execVM instead of function so we can sleep _object execVM "\z\addons\dayz_server\compile\server_crashLoot.sqf"; }; Link to comment Share on other sites More sharing options...
zipper Posted December 4, 2014 Report Share Posted December 4, 2014 Works like a charm dude, thanks man. Gr8Boi - You don't think you might have gotten confused at the last few steps in the server_publishvehicle.sqf files causing your side not to function as expected? I spawned a Hive vehicle with infistar and it worked just fine. For server_publishVehicle.sqf and server_publishVehicle2.sqf place _object setVariable ["lastInventory", []]; after publicVariable "PVDZE_veh_Init"; and in server_publishVehicle3.sqf, place _object setVariable ["lastInventory", [_weapons,_magazines,_backpacks]]; after publicVariable "PVDZE_veh_Init"; Hope you get your side sorted. Link to comment Share on other sites More sharing options...
striker Posted December 4, 2014 Author Report Share Posted December 4, 2014 Thank you very very very much for this striker, my players will enjoy this one :P No problem :) striker Link to comment Share on other sites More sharing options...
zipper Posted December 4, 2014 Report Share Posted December 4, 2014 Alright, remove everything done to server_functions.sqf, no longer need to use this file for the script. Should just need to remove the following from the file: if(_unit isKindOf "AllVehicles") then{ //execVM instead of function so we can sleep _unit execVM "\z\addons\dayz_server\compile\server_crashLoot.sqf"; }; Remove all the addMPEventHandlers you added from ALL THE FILES. They should look like the one below _object addMPEventHandler ["MPKilled",{_this call object_handleServerKilled;}]; Open up server_updateObject.sqf and search for _object_killed = { private["_hitpoints","_array","_hit","_selection","_key","_damage"]; Add the following under it if(_object isKindOf "AllVehicles") then{ //execVM instead of function so we can sleep _object execVM "\z\addons\dayz_server\compile\server_crashLoot.sqf"; }; Hey striker, Confirmed working, once again, thanks you. Link to comment Share on other sites More sharing options...
striker Posted December 4, 2014 Author Report Share Posted December 4, 2014 Hey striker, Confirmed working, once again, thanks you. Thanks for informing me! ;) striker Link to comment Share on other sites More sharing options...
calamity Posted December 4, 2014 Report Share Posted December 4, 2014 this is great... thankz for the share.... working great Link to comment Share on other sites More sharing options...
THEbookie Posted December 4, 2014 Report Share Posted December 4, 2014 So what happens to helis when they blow up in flight for example? Or if you crash and then it blows up? Dose the loot float down to the ground or is this only for land vehicles. Sorry will check this out when I get back looks great either way Link to comment Share on other sites More sharing options...
striker Posted December 4, 2014 Author Report Share Posted December 4, 2014 So what happens to helis when they blow up in flight for example? Or if you crash and then it blows up? Dose the loot float down to the ground or is this only for land vehicles. Sorry will check this out when I get back looks great either way Ill actually check that out myself too, I do have a speed check as shown below, but for some reason I do not think it works as planned. _count = 0; while{(speed _veh) > 0.1 && _count <= 20} do{ sleep 0.1; _count = _count + 0.1; }; Thanks for bringing that up! striker Link to comment Share on other sites More sharing options...
Ree Posted December 6, 2014 Report Share Posted December 6, 2014 *Droolz* I needed this but let me get this right because config details feel little light /* select 0 = Prevent gear from spawning on locked vehicles (boolean) select 1 = Guaranteed loot piles (int) select 2 = Max additional loot piles on top of guaranteed (int) select 3 = Radius around crash site to spawn loot (double or int) select 4 = Chance of gear being destroyed (Between 0-1, Ex: 0 = Never lost, 0.5 = Half lost, 1 = All lost) Default: DZE_crashLootConfig = [true,2,5,5,0]; */ select 0 = Locked vehicles Will not drop Loot ("Default: True") select 1 = The Amount of Loot Piles around destroyed vehicles ("Default: 2") out of Max amount ___? "Max Safe Amount" select 2 = Max additional loot piles On top of select 1 loot Piles ("Default: 5") out of Max amount ___? "Max Safe Amount" select 3 = Radius around crash site to drop loot ("Default: 5")m out of Max amount ___? "Max Safe Amount" select 4 = Chance of gear being destroyed (Between 0-1, Ex: 0 = Never lost, 0.5 = Half lost, 1 = All lost) So if i do DZE_crashLootConfig = [false,10,5,10,0]; [false, Items Will drop even if Vehicle is locked 10, the amount of loot piles around destroyed vehicles is 10 that's if Vehicle has that much loot 5, is the amount of piles on top of the default loot piles "Does this number need to be greater then select 1? 10, the loot will be dropped with in 10m of the destroyed vehicle or is it 1 to 10m letting it pick from random from 1 thru 10 0, all drops Sorry for the question i tryed it out on default and loved it but i just want to know if those setting i have there will make it look more spread out like stuff got flung around. Anymore details would be great =) Thank you Re Link to comment Share on other sites More sharing options...
striker Posted December 7, 2014 Author Report Share Posted December 7, 2014 *Droolz* I needed this but let me get this right because config details feel little light /* select 0 = Prevent gear from spawning on locked vehicles (boolean) select 1 = Guaranteed loot piles (int) select 2 = Max additional loot piles on top of guaranteed (int) select 3 = Radius around crash site to spawn loot (double or int) select 4 = Chance of gear being destroyed (Between 0-1, Ex: 0 = Never lost, 0.5 = Half lost, 1 = All lost) Default: DZE_crashLootConfig = [true,2,5,5,0]; */ select 0 = Locked vehicles Will not drop Loot ("Default: True") select 1 = The Amount of Loot Piles around destroyed vehicles ("Default: 2") out of Max amount ___? "Max Safe Amount" select 2 = Max additional loot piles On top of select 1 loot Piles ("Default: 5") out of Max amount ___? "Max Safe Amount" select 3 = Radius around crash site to drop loot ("Default: 5")m out of Max amount ___? "Max Safe Amount" select 4 = Chance of gear being destroyed (Between 0-1, Ex: 0 = Never lost, 0.5 = Half lost, 1 = All lost) So if i do DZE_crashLootConfig = [false,10,5,10,0]; [false, Items Will drop even if Vehicle is locked 10, the amount of loot piles around destroyed vehicles is 10 that's if Vehicle has that much loot 5, is the amount of piles on top of the default loot piles "Does this number need to be greater then select 1? 10, the loot will be dropped with in 10m of the destroyed vehicle or is it 1 to 10m letting it pick from random from 1 thru 10 0, all drops Sorry for the question i tryed it out on default and loved it but i just want to know if those setting i have there will make it look more spread out like stuff got flung around. Anymore details would be great =) Thank you Re Everything is setup like how you have it in the script, so anywhere between 10 and 15 weapon holders will spawn. However, how the script is set up now, it will choose from 1 to 10-15. I have to re-script the mechanism to put at least one thing in each and then go random after that to get the desired effects. As for the radius, it should be anywhere from 0-10 meters from the wreck, however, it might not be. If it is a constant 10 meters from the wreck, try this fix. Where it says: _temp = createVehicle ["WeaponHolder", [_pos select 0, _pos select 1, 0], [], _radius, "CAN_COLLIDE"]; Change to: _temp = createVehicle ["WeaponHolder", [_pos select 0, _pos select 1, 0], [], (random _radius), "CAN_COLLIDE"]; As for the rest, you are correct. :) striker Link to comment Share on other sites More sharing options...
Fidy Posted December 7, 2014 Report Share Posted December 7, 2014 EDIT: Had replaced instead of insterted one place, my bad. Link to comment Share on other sites More sharing options...
Ree Posted December 7, 2014 Report Share Posted December 7, 2014 server_monitor.sqf And place the following after it: _object setVariable ["lastInventory", _intentory]; mine --LINE 323--> if (_object isKindOf "AllVehicles") then { _object setVariable ["lastInventory", _intentory]; { _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; Also tried if (_object isKindOf "AllVehicles") then { { _object setVariable ["lastInventory", _intentory]; _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; Server RPT 2:03:56 Error in expression <{ _object setVariable ["lastInventory", _intentory]; { _selection = _x select 0;> 2:03:56 Error position: <_intentory]; { _selection = _x select 0;> 2:03:56 Error Undefined variable in expression: _intentory 2:03:56 File z\addons\dayz_server\system\server_monitor.sqf, line 323 server_updateObject.sqf Find the following line in server_updateObject.sqf: _object setVariable["lastInventory",_inventory]; And replace it with: if(alive _object) then{ _object setVariable["lastInventory",_inventory]; }; Mine _previous = str(_object getVariable["lastInventory",[]]); --LINE 92--> if (str(_inventory) != _previous) then { if(alive _object) then{ _object setVariable["lastInventory",_inventory]; }; if (_objectID == "0") then { _key = format["CHILD:309:%1:%2:",_uid,_inventory]; } else { _key = format["CHILD:303:%1:%2:",_objectID,_inventory]; }; //diag_log ("HIVE: WRITE: "+ str(_key)); _key call server_hiveWrite; }; }; Server RPT 2:04:32 Error in expression <Inventory",[]]); if (str(_inventory) != _previous) then { if(alive _object) the> 2:04:32 Error position: <_previous) then { if(alive _object) the> 2:04:32 Error Undefined variable in expression: _previous 2:04:32 File z\addons\dayz_server\compile\server_updateObject.sqf, line 92 server_crashLoot.sqf --LINE 30--> if(((count _gear) > 0) && _cont) then{ Server RPT 2:05:17 Error in expression < }; }else{ _cont = true; }; if(((count _gear) > 0) && _cont) then{ sleep 1; _> 2:05:17 Error position: <_gear) > 0) && _cont) then{ sleep 1; _> 2:05:17 Error Undefined variable in expression: _gear 2:05:17 File z\addons\dayz_server\compile\server_crashLoot.sqf, line 30 I use a player buys a car and puts loot into it I think due to the Car going into Car God in the safezone its bugging it out but cars are shooting out loot all over the place just duping items over and over as u park or drive the car even out of the safezone. WIll test it more when its patched up Thanks Re. It may be the lack of sleep but as i was posting this i noticed u use _intentory and not _inventory in your server_monitor.sqf i'll change that in mine and see if it fix's the first error Link to comment Share on other sites More sharing options...
THEbookie Posted December 7, 2014 Report Share Posted December 7, 2014 Rechecked everything twice, still nothing, i use originally spawned vehicles, the loot piles appear around, but empty, you just find specific spots rights after the crash that say gear, but they are empty. Any advice? Default: DZE_crashLootConfig = [true,2,5,5,0]; You don't have a 1 at the end of that do you? I mean rather then the 0 in that example Fidy 1 Link to comment Share on other sites More sharing options...
Fidy Posted December 7, 2014 Report Share Posted December 7, 2014 Default: DZE_crashLootConfig = [true,2,5,5,0]; You don't have a 1 at the end of that do you? I mean rather then the 0 in that example I used the default values. Link to comment Share on other sites More sharing options...
striker Posted December 7, 2014 Author Report Share Posted December 7, 2014 Hey Ree, Ill look into the RPT errors more, as for this issue: It may be the lack of sleep but as i was posting this i noticed u use _intentory and not _inventory in your server_monitor.sqf i'll change that in mine and see if it fix's the first error In the 1.0.5.1 release of the server_monitor.sqf, there was a spelling error of the word _inventory, that is why it is _intentory. If you fixed that spelling error in your files, than changing it may help. striker Schalldampfer 1 Link to comment Share on other sites More sharing options...
BHBorn2Kill Posted December 16, 2014 Report Share Posted December 16, 2014 Nice mod. I will give this a test on my server and see how it goes. This also sparked an idea for a new mission idea to add to my current mission system. I had at one point animated heli-crashes, but the code stopped working a while ago and I never had time to debug it. I'm thinking of somehow combining this with DayZAI vehicles so that if destroyed the loot scatters around the wreck rather than losing it. I'll tinker with it and post back. I'll be sure to credit your code if I get it working. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now