Need help with NPC loot drops

I am pretty new to scripting and need help with my RPG type game.
What i want is a script that whenever an NPC dies, there is a chance that a certain item will go into your inventory. I tried looking online and on the Devforum but there aren’t many topics on it. If you need more info then I can try to help. thx

1 Like

I think there’s a lot of searchable material you might’ve missed because I know for a fact that there are a lot of items in the toolbox and threads on NPC drops. You might want to refine your search terms a little bit to see if you get a better result when searching.

LootPlan is easily my favourite resource for working with loot drops right now and I haven’t made any switch since I haven’t felt it necessary to write my own loot drop mechanic when this resource exists. I have this plugged in whenever I need loot drops which handles the chances and drops for me.

There’s a pretty good explanation of how it works on the page and in the module itself but if you want to really learn what it’s doing it might take a bit to grasp, though it’s not all important if you’re still fresh into programming and aren’t going to eventually make a similar system on your own time. Create a new plan, plug in your items and then you’re good to go. Do note that you also need to include “Nothing” as an item in your plan if you want the player to also have a chance of not getting an item.

LootPlan does not handle everything for you, just the algorithm for loot drops. You are responsible for using the results LootPlan generates for you to further polish your system. That is, using what LootPlan gives you back, find the related tool (if the returned item isn’t “Nothing”) and clone it into the player’s backpack and whatever other data settings you need to commit.

2 Likes

Thanks for the tips and (very) thought out message I’ll go try it out

1 Like

@colbert2677 So i tried lootplan and it works great (thank you for the suggestion) but i was just wondering how i would clone the item to the player’s backpack (i told you i was new)

1 Like

item:Clone().Parent = player.Backpack

1 Like