Jump to content

Is there a way to add items to the loot tables of certain vanilla monsters?


Recommended Posts

Is there a way to quickly add this code into the loot tables of certain monsters? Still have a poor understanding of how to add stuff to vanilla files.

I'd like to add this to hound, bishop, and knight for now.

    {'money1', 1.0},
    {'money1', 0.25},
    {'money2', 0.05},

Or just overriding their existing loot tables is fine for me as well.

Thanks

Link to comment
Share on other sites

The way you'd add something to vanilla files depends a lot on what you're doing. In most cases you'd use AddPrefabPostInit to change something about an entity, but in this case I think you'll have to use a different approach.

The way a lot of loot tables work is that they're saved in the global table LootTables (you can find this in components/lootdropper.lua) under a specific key. This key usually matches with the prefab name, but not always! So always make sure to check what it's actually called.

Now, if you want to add the loot to the hound's table, I'd go with this approach:

AddGamePostInit(function()
    local loot = GLOBAL.LootTables.hound
    
    table.insert(loot, {"money1", 1.0})
    table.insert(loot, {"money1", 0.25})
    table.insert(loot, {"money2", 0.05})
end)

I'm using AddGamePostInit because it runs after the game files have loaded, so LootTables actually contains something. AddPrefabPostInit runs every time the entity is spawned in, so it wouldn't be the right choice for this.

Now, to save your sanity, instead of manually repeating the code for each mob, I'd recommend iterating through a table of all the loot tables you want to add money to. Something like this would do the trick:

local moneymobs = {
    "hound",
    "knight",
    "bishop",
}

AddGamePostInit(function()
    for k,v in pairs(moneymobs) do
    	local loot = GLOBAL.LootTables[v]
        
    	table.insert(loot, {"money1", 1.0})
    	table.insert(loot, {"money1", 0.25})
    	table.insert(loot, {"money2", 0.05})
    end
end)

And you can just keep adding more entries to the table as needed. Either code goes in modmain, by the way. If you have more questions, feel free to ask!

  • Thanks 1
  • Sanity 1
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
 Share

×
  • Create New...