Predefined Constants (Only r77+)
BOTSDIR
GFXDIR
MAPSDIR
SFXDIR
SYSDIR
LUADIR
SERVERDIR
__FILE__
__DIR__
1
2
3
4
5
6
7
8
--> ./sys/lua/server.lua
dofile(LUADIR .."\\test\\init.lua") or require("test")
print(__FILE__)		-- return .\sys\lua\server.lua
print(__DIR__)		-- return .\sys\lua
--> ./sys/lua/test/init.lua
print(__FILE__)		-- return .\sys\lua\test\init.lua
print(__DIR__)		-- return .\sys\lua\test
String:
Various string functions
Table:
Various table functions
Hook:
1
2
3
4
5
6
7
8
9
10
hook.Add("join", "Welcom", function(ply)
	ply:PrintMessage(HUD_PRINTCENTER, "©000128128Welcom to my server.")
end)
or
function welcom(ply)
	ply:PrintMessage(HUD_PRINTCENTER, "©000128128Welcom to my server.")
end
hook.Add("join", "Welcom", welcom)
1
hook.Remove("join", "Welcom")
1
2
3
4
5
6
7
8
9
10
11
12
13
for h,t in pairs(hook.GetTable())
	-- h: hook
	-- t: table
	for n,f in pairs(t)
		-- n: name
		-- f: function
	end
end
for n,f in pairs(hook.GetTable()["join"])
	print(n)
end
Menu:
Easy to use menus. See following for examples.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
quick= menu.Create(ply, "Test Menu")
-- Note that menus with more than 9 items will automatically paginate themselves
button = quick:ButtonAdd("1", function(ply, data)
	ply:ChatPrint("button: 1")
	ply:ChatPrint(string.format("Data1: %s", data[1]))
	ply:ChatPrint(string.format("Data2: %s", data[2]))
end)
button:Data("Test1")
button:Data("Test2")
function button2(ply, args)
	ply:ChatPrint("button: 2")
end
quick:ButtonAdd("2", button2, "Extra Text")
(Only r77+)
1
2
3
4
5
6
7
8
9
10
11
12
quick= menu.Create(ply, "Test 2 Menu")
quick:ButtonAdd("1", nil, function(ply, args)
	ply:ChatPrint("button: 1")
	ply:ChatPrint(string.format("Data1: %s", args[1]))
	ply:ChatPrint(string.format("Data2: %s", args[2]))
end, "Test1", "Test2")
function button2(ply, args)
	ply:ChatPrint("button: 2")
end
quick:ButtonAdd("2", "Extra Text", button2)
Comands module:
Implements a smart users system for cs2d developers that extends the cmds module
Chat:
1
2
3
4
5
6
7
chatcommand.Add("say", function(ply, message)
	if (ply:IsAdmin()) then
		ply:ChatPrint(string.format(“<admin> %s: %s”, ply:Name(), message))
	else
		ply:ChatPrint(string.format(“%s: %s”, ply:Name(), message))
	end
end)
will create the commands !say that will behave as follow:
> !say test
Informatixa: test --user
<admin> Informatixa: test --admin
Console:
rcon password is required
1
2
3
4
5
6
7
8
9
10
comcommand.Add("say", function(args)
	PrintMessage(HUD_PRINTTALK, string.format(“Server: %s”, args[1]))
end)
or
function saycmd(args)
	PrintMessage(HUD_PRINTTALK, string.format(“Server: %s”, args[1]))
end
comcommand.Add("say", saycmd)
> say test
Server: test
File:
> sample text
> true: exist
> false: not exist
1
file.Write(LUADIR .."\\test.txt", "sample text\nsample text")
1
2
3
for k, v in file.Lines(LUADIR .."\\test.txt") do
	print(string.format("%s: %s", k, v))
end
1
2
3
4
for k, v in file.Find(MAPSDIR .."\\*.map") do
	map = string.replace(v, ".map", "")
	print(string.format("%s: %s", k, map))
end
Ini:
1
2
3
4
5
data = ini.Open(SYSDIR .."\\test.ini")
name = data:GetValue("test", "name")
or
test = data:GetBlock("test")
1
2
3
4
5
6
7
data = ini.Open(SYSDIR .."\\test.ini")
data:SetValue("test", "name", "Informatixa")
or
data:SetBlock("test", {"name" = "Informatixa"})
data:Save()
Timer: (Only r77+)
1
2
3
4
5
6
7
8
9
-- Time is in seconds
function timerMessage(ply)
	ply:PrintMessage(HUD_PRINTTALK, "©255000000Dont use speedhack, aimbot or any others hacks!")
end
hook.Add("join", "JoinTest", function(ply)
	ply:Timer("TimerTest", 5, 0, timerMessage)
end)
1
2
3
4
5
6
7
function timerMessage2(ply, arg1, arg2)
	ply:PrintMessage(HUD_PRINTTALK, arg1 .." - ".. arg2)
end
hook.Add("join", "JoinTest", function(ply)
	ply:Timer("TimerTest", 5, 0, timerMessage2, "test3", "test4")
end)
1
2
3
4
5
function timerMessage(arg1, arg2)
	PrintMessage(HUD_PRINTTALK, arg1 .." - ".. arg2)
end
timer.Create("TimerTest", 5, 0, timerMessage, "test1", "test2")