![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | JeremiasDev |
Hi, i want a loot drop system. If the player kill a enemy or fishing a fish or axe a tree…
example pictures:
Do you have an working inventory system?
If yes just work with item objects maybe an area 2d. You could add those as child of the scene when killing something. When colliding with the player change the inventory values.
If you don’t have an inventory system there are tutorials for this.
Edit:
Please have a look at this.
RoniPerson | 2021-01-02 18:25
Yes,i have a inventory system but how can i make it, that objects are dropped? and the random? Can you write a Code?
JeremiasDev | 2021-01-02 18:36
This problem consists of two parts.
Part 1: collectable items in your scene
This basicly works like coins. For this there are tutorials.
Additional each item has to store its item id.
Baaed on this you can change the correaponding inventory value
Part 2 droping items (including randomnes)
This can be solved in diffrent ways. But i would suggest using a autoloaded manager for this. In it you have a dictionary of loottables.
The key is the name for the loottable e.g. “fishing”.
The value which correspond to a key is a list. This contains more list.
Each of it contains 3 values. At index 0 the weight. At index 1 the item id.
At index 2 the amount.
The class has a function invoce_drop or so. It takes an position and the name of a loottable. Based on the weights you can choose an entry of the loottable list.
For weighted randomness have a look at this.
Based on the entry for value and item you can now add items from part 1 to the scene.
Try to figure out the code for yourself
RoniPerson | 2021-01-02 19:12
Thanks, i write back If i have questions
JeremiasDev | 2021-01-02 19:14
Hey, I tried it but didn’t work, I know how to do a random generator and also how to store the id of the item but I don’t know how to do the items In the case of wood that drops from a tree. Please write me a code where I can do that. thanks
Edit: It doesn’t have to be random
JeremiasDev | 2021-01-02 22:07