blob: f3d802c1f687dbb9bc63ca57602bfdc1027dae59 (
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
module( "item", package.seeall )
local ItemTables = {}
local ID = 1
function Register( tbl )
tbl.Functions = tbl.Functions or {}
tbl.ID = ID
ItemTables[ ID ] = tbl
util.PrecacheModel( tbl.Model )
ID = ID + 1
end
function GetList()
return ItemTables
end
function GetByID( id )
if not id then return end
if !ItemTables[ id ] then return end
return ItemTables[ id ]
end
function GetByModel( model )
for k,v in pairs( ItemTables ) do
if string.lower( v.Model ) == string.lower( model ) or ( v.DropModel and string.lower( v.DropModel ) == string.lower( model ) ) then
return v
end
end
end
function GetByClass( class )
for k,v in pairs( ItemTables ) do
if v.TypeOverride and string.lower( v.TypeOverride ) == string.lower( class ) then
return v
end
end
end
function GetByName( name )
for k,v in pairs( ItemTables ) do
if string.lower( v.Name ) == string.lower( name ) then
return v
end
end
end
function GetByType( itemtype )
local tbl = {}
for k,v in pairs( ItemTables ) do
if v.Type == itemtype then
table.insert( tbl, v )
end
end
return tbl
end
function RandomItem( itemtype )
if not itemtype then return table.Random( ItemTables ) end
local tbl = GetByType( itemtype )
local rand = table.Random( tbl )
while math.Rand(0,1) < rand.Rarity do
rand = table.Random( tbl )
end
return rand
end
|