100% Custom Loot tables - TUTORIAL

Seven

Moderator
Staff member
UPDATED AS OF 08/04/2012 - 10:02
Ok so I got pestered for this, so here it is.

100% Custom Loot tables, no loot suppression, full control of what loot spawns in your server and where.

Steps:
  1. Decompress your mission pbo
  2. Create a fixes folder
  3. create building_spawnLoot.sqf
  4. Put this code into it http://pastebin.com/UPHj1Q02
  5. open init.sqf
  6. after
    Code:
    call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf";//Compile regular functions
    progressLoadingScreen 1.0;
    put
    Code:
    building_spawnLoot = compile preprocessFileLineNumbers "fixes\building_spawnLoot.sqf";
  7. save your work and pack your pbo.
You have now installed the custom loot tables.
To test that it is running check your CLIENT rpt logs
C:\Users\<username>\AppData\Local\ArmA 2 OA
and look for
SPAWNING WITH CUSTOM LOOT
Once this is showing in your client log files the code is running correctly, you can now start your modifying process.
First order of business is to remove the testing line
So remove
Code:
diag_log "SPAWNING WITH CUSTOM LOOT";//Remove This line after testing
from line 16 of building_spawnLoot.sqf
Best to remove this line to reduce spam of the client log files.
We will take hospital loot for adding for testing, since its the smallest so easy to read.
Code:
case "Hospital": {
    _itemTypes =    [
        ["","trash"],
        ["","hospital"],
        ["MedBox0","object"]
    ];
    _itemChance = [
        0.2,
        1,
        0.2
    ];
};
You must always remember the last object in the list must not have a trailing comma. This will make the engine expect another object and throw up script errors.

so to add another object. I would put a comma after ["MedBox0","object"] and then add my item.
Code:
case "Hospital": {
    _itemTypes =    [
        ["","trash"],
        ["","hospital"],
        ["MedBox0","object"],
        ["BAF_AS50_scoped","weapon"]
    ];
    _itemChance = [
        0.2,
        1,
        0.2,
        1
    ];
};
When you add an object, remember to add a chance value in the correct position, trailing commas work the same in this section.
So I have added an AS50 spawn to the hospital with the same chance to spawn as a medical box.
You may want to go for some more realistic loot but examples are examples.

Other key factors you must watch for. The loot CLASS there are several classes for loot.
Code:
object
weapon
magazine
generic
Best practice is find the item from another table and copy its data,
if you are unsure use generic, it is used for everything that isn't a weapon or box/backpack.

This code was made to be simple so some features of 1.7.6 base was changed to allow this to work. It uses the old 1.7.5 style loot weights rather than the 1.7.6 CBL_Base design so loot may seem to drop differently. But you have to make sacrifices for custom loot. Or you can go through the effort of redoing this to incorporate it, but this works. Why fight it.

Any problems do post here. Please don't PM me, If I fix a problem, might as well let everyone see and learn from any mistakes.

Further more. Enjoy your custom loot tables. (Try not to over run your server with high loot drops :p)

FAQ:
Q. I don't run Chernarus will this code work with other maps?
A. This code is designed on Chernarus' loot tables. You will need to look at the config.cpp file for the map you are running and copy the values for its loot tables to match up correctly. (If you do this, please be kind enough to share for everyone else.)

Q. Does this allow us to spawn banned weapons?
A. No. Weapons are banned at the games start up process which cannot but undone without adding a new mod to override the bans (rMod)

Q. Does this fix allow us to change crash site loot?
A. No Crash sites use a separate method for spawning its loot. This code will not be ran during that method. You will need to modify server_spawnCrashSite.sqf in the same retrospect as this edit to allow custom loot tables there also. I will post another tutorial soon on how to achieve this.

Q. I did this tutorial but there is no loot. What have I done wrong?
A. Post your mission PBO. I'm sure someone or myself will help find the problem. Not everyone is perfect.

Q. Are these tables the default tables?
A. Yes these tables are default Chernarus as of 1.7.6.1

Q. If I did this can I just customize one building or do I have to customize everyone?
A. Loot is spawned based of the buildings loot type. so all Barns go under the Farm class. If you change the farm class anything under farm will change.
You can however add more classes and assign all of the same building to this new class. But you cannot make a single specific building spawn certain loot.
 
Thank you, thank you!

Sorry for "pestering" you. This is much appreciated. gonna go do this now!

EDIT: What about for those of us not on cherno and the diff types of custom buildings that spawn loot? What would have to be differently?

Would that involve taking a look at the cfgbuildingloot.hpp?
 
Sadly you will have to go through the effort of updating the tables to that maps tables.

Here is the standard config.cpp hospital loot.
Code:
    class Hospital: Default {
        zombieChance = 0.4;
        minRoaming = 2;
        maxRoaming = 6;
        zombieClass[] = {"z_doctor","z_doctor","z_doctor"};
        lootChance = 1;
        lootPos[] = {};
        itemType[] =    {
            {"","trash"},
            {"","hospital"},
            {"MedBox0","object"}
        };
        itemChance[] =    {
            0.2,
            1,
            0.2
        };
    };
and my conversion to sqf
Code:
    case "Hospital": {
        _itemTypes =    [
            ["","trash"],
            ["","hospital"],
            ["MedBox0","object"]
        ];
        _itemChance = [
            0.2,
            1,
            0.2
        ];
    };
Its easy enough to figure out how to do it fast and clean. The only difference really is you don't need all the extra variables, you just want to grab the loot data and chance data. (The Arrays)
You will see C++ arrays are stored
{{val,val},{val,val},{val,val}}
while sqf is stored
[[val,val],[val,val],[val,val]]
Shouldn't take you too long to convert all the values over to the correct ones you require.

Edit: Didn't see the building part. Buildings are easy added to, All buildings are defined at the top
case "Land_HouseV_1I4": { _LootClass = "Residential"; };
Just add all the extra buildings from the config.cpp to this with the correct class.
All builds are easy enough to identify: from config.cpp
class Land_HouseV_1I4: Residential {
 
No not the KSVK or the RPK.
You can add extra weapons with this though. As long as they are not on the ban list. check dayz_anim config.cpp for which items are banned.
 
Can those "extra variables" be modified as well?

Code:
    class Hospital: Default {
        zombieChance = 0.4;
        minRoaming = 2;
        maxRoaming = 6;
        zombieClass[] = {"z_doctor","z_doctor","z_doctor"};
        lootChance = 1;
 
you would need to modify them extra values in the building_spawnZombie.sqf, using the same idea here

But the lootChance value can be modified in here, simple add that to the defining class section
Code:
case "Land_HouseV_1I4": { _LootClass = "Residential"; _lootChance = 0.8; };

You can easily push this code further to actually adding more loot spots in buildings or moving them.
 
Back
Top