What's the best way to implement an item system with custom functions for each item?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tesohh

I’m building a game with consumable items and such, and wanted to implement an item system, possibly a class based one, but I really don’t know where to begin as godot doesn’t have First-Class functions and the way that classes work is pretty weird.

Also, for some items i need to execute a function when something specific happens (like firing a gun, picking up money, being hit ect.)

Can someone explain me or at least give me some tips?

and the way that classes work is pretty weird.

What’s exactly wrong with just Object - based classes?
This site works best with concrete questions. Do you have one?

sash-rc | 2022-01-31 08:17

:bust_in_silhouette: Reply From: Inces

I based my item system almost entirely on dictionaries and I am glad with result. It was classic Hack and Slash game like Diablo, I am not sure if You are going for this kind of RPG weapon system ?
Anyways it worked like this : single nested dictionary was a complete database about one item. It contained data like mesh, shader, requirements, type, armature bone placement, cost, preview icon, and special effects. When item was rolled after mobs death, this dictionary was created partially randomly, based on serialized information about items, which was another dictionary kept in Autoload. Dictionary in Autoload was used to keep default data about all items (like what weapon has which mesh and damage it deals without magical affixes ). So these two dictionaries were working together to create final data about individual item. There was a “special effect” key in this dictionary, that determined different bahaviors of these items. I used Strings there to hold data about names of functions, that were supposed to be called for these specific objects ( like “shoot” or “defend” “oncrit” “backstab”, as well as String paths components for magical effects to be loaded with those special items ( like “lifesteal”, “fireaura”) and they were next loaded dynamically in code ( load(“res//effects” + name +“.tscn”). So this is in general how individual scripted behaviors were handled. Special effects scenes and certain functions worked as additional agents extending original script , since all effects were iterated and called from their parent.