aboutsummaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/loaditems.lua
blob: 49e4cdfeefe31340fcf1921a97eff099208f7700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
local Folder  	= GM.Folder:gsub("gamemodes/","").."/gamemode/itemsystem/items"
local insert 	= table.insert
print("Hello from loaditems.lua!")

--This is so that the client can store info about items/recepies too.
local gmitems = (GAMEMODE or GM).Items or {}
local gmrecepies = (GAMEMODE or GM).Recipes or {}

function RegisterItem(tbl)
	assert(gmitems[tbl] == nil, "Cannot register 2 items with the same name!")
	insert(gmitems,tbl)
	if tbl.Recipe then
		insert(gmrecepies,tbl)
	end
	print("Registered item:", tbl.Name)
end

function GetItemByName(name)
	for k,v in pairs( gmitems ) do
		if (v.Name == name) then return v end
	end

	return nil
end

function GetRecipeForItem(name)
	for k,v in pairs( gmrecepies ) do
		if (v.Name == name) then return v.Recipe,v end
	end

	return nil
end

function GetItemsByClass(class)
	local Dat = {}
	for k,v in pairs( gmitems ) do
		if (v.Class == class) then table.insert(Dat,v) end
	end

	return Dat
end