Benny/gamemodes/benny/gamemode/modules/meta/sh_itemdef.lua

53 lines
963 B
Lua
Raw Permalink Normal View History

2024-01-01 16:12:35 -05:00
--[[
Your Name Is Benny
Item definition
]]
-- Not 100% sure how metastuff works yet.
-- Global weapons table
WEAPONS = {}
function WeaponGet(class)
return ItemDef(class)
end
-- ItemDef metatable
ItemDef = {}
2024-01-15 01:43:44 -05:00
ItemDefHelpers = {
Get = function( self, key )
return self.key
end,
GetRaw = function( self, key )
return rawget( self, key )
end,
}
2024-01-01 16:12:35 -05:00
function ItemDef.__index( self, key )
2024-01-15 01:43:44 -05:00
if ItemDefHelpers[key] then return ItemDefHelpers[key] end
2024-01-01 16:12:35 -05:00
if rawget(self, "BaseClass") then
return rawget(self, "BaseClass")[key]
2024-01-01 16:12:35 -05:00
end
end
function ItemDef:new( classname, classtable )
if classtable then
local newdef = classtable
newdef.ClassName = classname
newdef.BaseClass = WEAPONS[newdef.Base]
setmetatable( newdef, ItemDef )
2024-01-15 01:43:44 -05:00
WEAPONS[classname] = newdef
2024-01-01 16:12:35 -05:00
return newdef
else
return WEAPONS[classname]
end
end
function ItemDef:__tostring()
return "ItemDef [" .. self.ClassName .. "]"
end
setmetatable( ItemDef, { __call = ItemDef.new } )