• Entity like way to create new items for addons.
    3 replies, posted
I'm currently working on an addon that will be using items and I will need some way of adding new items. What I have thought about is to use a method similar to creating entities where you create 3 files in a directory and then set variables like, ITEM.NAME, etc.. I've seen addons such as Pointshop using this method to add items which is a pretty convenient way of adding items. The only problem that I have is that I don't know how I should do this. I've looked into [URL="https://wiki.garrysmod.com/page/Metamethods"]metamethods[/URL] but I found it kinda hard to understand how I should use them. I currently load the items by looping through all folders in the items directory of my addon and then loading each file inside each directory by including it. I would really appreciate if anyone could help me with this so I can continue working on the addon that I'm currently working on. Kind regards, Jompe.
You can use Pointshop's method which just creates a global ITEM table for each new file loaded, then stores it as an entry in a master table. If you want to go a more formal route, I made a weapon/entity loader in Lua which gives each file its own environment if you want to use it as an example (it uses metamethods): [url]https://github.com/Kefta/gs_weapons/blob/master/gs_weapons_base/lua/code_gs/weapons.lua#L334-L486[/url]
[QUOTE=code_gs;51955191]You can use Pointshop's method which just creates a global ITEM table for each new file loaded, then stores it as an entry in a master table. If you want to go a more formal route, I made a weapon/entity loader in Lua which gives each file its own environment if you want to use it as an example (it uses metamethods): [url]https://github.com/Kefta/gs_weapons/blob/master/gs_weapons_base/lua/code_gs/weapons.lua#L334-L486[/url][/QUOTE] Alright. Thanks! I'll try the first method and then reply tomorrow when I have tested it.
[QUOTE=Jompe;51955634]Alright. Thanks! I'll try the first method and then reply tomorrow when I have tested it.[/QUOTE] First method works exactly like it should. Thanks, appreciate it.
Sorry, you need to Log In to post a reply to this thread.