-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamemode.lua
80 lines (57 loc) · 1.53 KB
/
gamemode.lua
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
--[[
Kent-Hook-Library
This is gamemode library for kent-hook-library.
Pros:
Should be faster than regular gamemode library.
Cons:
Untested.
Credits: Kentovka
Jaff&Radon
]]
local gamemode = {}
local gamemodes = {}
local currentGM
local callFunc
function gamemode.Register(tab, name, derived)
currentGM = gmod.GetGamemode()
if currentGM then
if currentGM.FolderName == name then
table.Merge( currentGM, tab ) -- why it isn't called table.mixin?
gamemode.Call( "OnReloaded" )
end
local baseClass = currentGM.BaseClass
if baseClass and baseClass.FolderName == name then
table.Merge( baseClass, tab )
gamemode.Call( "OnReloaded" )
end
end
-- This gives the illusion of inheritence
if name ~= "base" then
local baseTable = gamemodes[derived]
if baseTable then
tab = table.Inherit( tab, baseTable )
else
print("Warning: Couldn't find derived gamemode (", derived, ")")
end
end
gamemodes[ name ] = tab
baseclass.Set( "gamemode_" .. name, tab )
end
function gamemode.Get(name)
return gamemodes[name]
end
local function call(name, ...)
if currentGM[name] == nil then return false end
return callFunc(name, currentGM, ...)
end
timer.Simple(1, function() -- very bad btw
callFunc = hook.Call
currentGM = gmod.GetGamemode()
gamemode.Call = call
end)
function gamemode.Call(name, ...) -- at first launch it basically same shit.
currentGM = gmod.GetGamemode()
if currentGM and currentGM[name] == nil then return false end
return hook.Call(name, currentGM, ...)
end
_G['gamemode'] = gamemode