Forum

> > CS2D > General > Lua Scripts for CS2D
Forums overviewCS2D overviewGeneral overviewLog in to reply

English Lua Scripts for CS2D

134 replies
Page
To the start Previous 1 2 3 4 5 6 7 Next To the start

Poll Poll

What do you think about Lua support in CS2D?

Only registered users are allowed to vote
Awesome!
85.88% (225)
Sounds good.
7.25% (19)
Bad idea. I hate Lua!
3.44% (9)
I have no idea.
3.44% (9)
262 votes cast

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
DC has written
@chuico123:
• gun game
• classes were players have different weapons/armor on spawn
• a skill/level system
• a bet system
• custom voting system
• weapons for free system
• teleport stuff
• and much more.


kkkkkkkk, we can do alotsa stuff, its just limited to the crazy imagination of the players

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
Sorry, I didn't test that code out, did a few revisions and added a few tests for you to see if it works (it does)

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
111
112
113
114
115
116
117
118
119
function switch(t)
	t.case = function (self,x)
		local f=self[x] or self.default
		if f then
			if type(f)=="function" then
				f(self)
			else
				error("case "..tostring(x).." not a function")
			end
		end
	end
  	return t
end

function tableToString(t, n)
	local s = ""
	if (n == nil) then n = 1 end
	while (n <= #t) do
		s = s .. t[n] .. " "
		n = n + 1
	end
	return s
end

function hook_leave(p,r)
	admin_check[p] = nil
end


--To Test out this system uncomment this out
--function msg2(p, t)
	--print (p, t)
--end

admin_check = {}

function hook(p, t)
	if (string.lower(string.sub(t, 1, 5)) == "admin") then
		-- Get the substring from position 11 to the end
		t = string.sub(t, 6)

		-- Dec and init of local variables
		local cmd = {}
		local users = {}

		--Iterates through t and adds each word into the table cmd
		for word in string.gmatch(t, "%a+") do
			table.insert(cmd, word)
		end

		--Command Type + pop top element
		local typ = string.lower(cmd[1])
		table.remove(cmd, 1)

		 --This probably go in the init block instead of here.
        
		--Uncomment this out
		--lines = {"user password a"}
		--for i,line in ipairs(lines) do
		--And comment out the line below
        
		for line in io.lines("Admins.cfg") do
			local tempUser = {}
			for word in string.gmatch(line, "%a+") do
				table.insert(tempUser, word)
			end
			users[tempUser[1]] = {password=tempUser[2], privilege = tempUser[3]}
		end
        
		if (typ == "login") then
			username = cmd[1]
			password = cmd[2]
			 if (users[username]) then
				--Here, admin_check will return nil if user id is not in the list				
				if (users[username].password == password) then
					admin_check[p] = users[username].privilege
				else
					msg2(p, "Wrong Password")
				end
			else
				msg2(p, "No User with that Username")
			end
		elseif (admin_check[p]) then
			local privilege = admin_check[p]
            
				command = tableToString(cmd)
            
				--Do the rest of the stuff, you can dec a variable as a fn and store it.
			action = switch {
				["slap"] = function () msg2(p, "This is the slap command") end,
				["echo"] = function () msg2(p, command) end,
				default = function() msg2(p, "Command Does Not exist") end,
			}
			action:case(typ)

		else
			msg2(p, "No admin privileges")
		end
	end
end



--Test1 - Uncomment where necessary
--hook(1, "admin slap 1")
--hook(1, "admin login u p")
--hook(1, "admin login user p")
--hook(1, "admin login user password")
--hook(1, "admin huh")
--hook(1, "admin slap 1")
--hook(1, "admin echo Hello World")

--Test2 - Uncomment where necessary
--hook(2, "admin echo Hello World")
--hook(2, "admin login user password")
--hook_leave(1); msg2(1,"Player 1 has left the game")
--hook(2, "admin echo Hello World")
--msg2(1,"Player 1 Joined the game")
--hook(1, "admin echo Hello World")

And yes, I know I misspelled "privilege"

use http://www.lua.org/cgi-bin/demo for the test

output

1
2
3
4
5
6
7
8
9
10
11
1	No admin privileges
1	No User with that Username
1	Wrong Password
1	Command Does Not exist
1	This is the slap command
1	Hello World 
2	No admin privileges
1	Player 1 has left the game
2	Hello World 
1	Player 1 Joined the game
1	No admin privileges

old Re: Lua Scripts for CS2D

Tehmasta
User Off Offline

Quote
Is lua able to create new files by itself? such as create a new textfile when you type /create name pass. At large amounts of users it would be much easier to work with than a giant file with everyone's data. Also, how would you go about editing a single line in a cfg file. for example,
1
2
3
4
5
Hello 1 2 3
This is a line 2 3 4
Myvar 3
Hisvar 6
Bye 3 4 5
is there a way to change Myvar 3 to Myvar 7 without having to save the lines in a table, change the table[3] to Myvar 7 and then open the file with update mode(w+) and rewrite everything to the file. Theres nothing to do with editing a single part of a file in the lua manual, this way just seems tedious

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
Tehmasta has written
Is lua able to create new files by itself? such as create a new textfile when you type /create name pass. At large amounts of users it would be much easier to work with than a giant file with everyone's data.


Yes, try using io.write(handle, data) where handle is given "w", "a", or "w+" privileges. But be warned, sorting through a large number of files is much less efficient than using a central user table to store the data. Also remember, lua supports multidimensional arrays and nested arrays (see my rewrite of the code above) which makes this process much easier if you just add the user functions in the initialize function and have it available globally. And since lua returns nil for out of bound arrays, you can just do one conditional check instead of a for to find the user element vs the login.

Quote
Also, how would you go about editing a single line in a cfg file.
1
2
3
4
5
Hello 1 2 3
This is a line 2 3 4
Myvar 3
Hisvar 6
Bye 3 4 5
is there a way to change Myvar 3 to Myvar 7 without having to save the lines in a table, change the table[3] to Myvar 7 and then open the file with update mode(w+) and rewrite everything to the file. Theres nothing to do with editing a single part of a file in the lua manual, this way just seems tedious


This is just how the computer works. Files are linear objects. There are ways to manipulate singe lines only but those are resource intensive and in a game script engine speed is everything. Just modify the user's nested tables and use the tableToString() and rewrite that to the file at the server close.

1
2
3
4
5
6
7
8
9
function hook_serverclose()
	_data = ""
	for uname, uinfo in pairs(users) do
		_data = _data .. "\n" .. uname .. " " .. tableToString(user)
	end
	_f = io.open("Admins.cfg", "w+") -- All data in Admins.cfg are automatically erased
	_f:write(_data)
	_f:close()
end

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
I'm guessing this "Admins.cfg" is the some type of admin login for like USGN's and such, or just a test.

old Re: Lua Scripts for CS2D

Tehmasta
User Off Offline

Quote
@zune: check the file i uploaded, it has my original code, which has admins.cfg

leegao, how fast does lua run off of cs2d. If you were to have thousands of accounts (right now im speaking in general not admin accounts) that have many variables to hold that user's stats, wouldn't it take up a lot of memory? And would crashes count as server close?

btw, for the rewriten script, you made it as long as the person has any type of admin privilege, then they are able to do any of the commands. what i wanted to do was a set of privileges from a to z each allowing the user to access a different command, such as slap, slay, echo, msg, mapchange, and later, custom user commands like give_wep and stuff. If one person was abusing with a certain command like slay, you can just remove their access from that one thing

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
function switch(t)
	t.case = function (self,x)
		local f=self[x] or self.default
			if f then
				if type(f)=="function" then
					f(self)
				else
					error("case "..tostring(x).." not a function")
				end
			end
		end
	return t
end

function tableToString(t, n)
	local s = ""
	if (n == nil) then n = 1 end
	while (n <= #t) do
		s = s .. t[n] .. " "
		n = n + 1
	end
	return s
end

function hook_leave(p,r)
	admin_check[p] = nil
end


--To Test out this system uncomment this out
--function msg2(p, t)
	--print (p, t)
--end

admin_check = {}

function hook(p, t)
	if (string.lower(string.sub(t, 1, 5)) == "admin") then
		-- Get the substring from position 11 to the end
		t = string.sub(t, 6)

		-- Dec and init of local variables
		local cmd = {}
		local users = {}

		--Iterates through t and adds each word into the table cmd
		for word in string.gmatch(t, "%a+") do
			table.insert(cmd, word)
		end

		--Command Type + pop top element
		local typ = string.lower(cmd[1])
		table.remove(cmd, 1)

		--This probably go in the init block instead of here.

		--Uncomment this out
		--lines = {"user password a"}
		--for i,line in ipairs(lines) do
		--And comment out the line below

		for line in io.lines("Admins.cfg") do
			local tempUser = {}
			for word in string.gmatch(line, "%a+") do
				table.insert(tempUser, word)
			end
			users[tempUser[1]] = {password=tempUser[2], privilege = tempUser[3]}
		end

		if (typ == "login") then
			username = cmd[1]
			password = cmd[2]
			if (users[username]) then
				--Here, admin_check will return nil if user id is not in the list                    
				if (users[username].password == password) then
					admin_check[p] = users[username].privilege
					msg2(p,"Successful login")
				else
					msg2(p, "Wrong Password")
				end
			else
				msg2(p, "No User with that Username")
			end
		elseif (admin_check[p]) then
			local privilege = admin_check[p]

			command = tableToString(cmd)

				--Do the rest of the stuff, you can dec a variable as a fn and store it.
			access = {
				slap = "a",
				echo = "b"
			}
			if access[typ] then
				if string.find(privilege,access[typ]) then
					action = switch {
						["slap"] = function () msg2(p, "This is the slap command") end,
						["echo"] = function () msg2(p, command) end,
						default = function() msg2(p, "Command Does Not exist") end,
					}
					action:case(typ)
				else
					msg2(p, "You are restricted from that command")
				end
			else
				msg2(p,"Command Does Not exist")
			end
		else
			msg2(p, "No admin privileges")
		end
	end
end



--Test1 - Uncomment where necessary
--hook(1, "admin slap 1")
--hook(1, "admin login u p")
--hook(1, "admin login user p")
--hook(1, "admin login user password")
--hook(1, "admin huh")
--hook(1, "admin slap 1")
--hook(1, "admin echo Hello World")

--Test2 - Uncomment where necessary
--hook(2, "admin echo Hello World")
--hook(2, "admin login user password")
--hook_leave(1); msg2(1,"Player 1 has left the game")
--hook(2, "admin echo Hello World")
--msg2(1,"Player 1 Joined the game")
--hook(1, "admin echo Hello World")

running this with the tests results in:

1
2
3
4
5
6
7
8
9
10
11
12
13
1	No admin privileges
1	No User with that Username
1	Wrong Password
1	Successful login
1	Command Does Not exist
1	This is the slap command
1	You are restricted from that command
2	No admin privileges
2	Successful login
1	Player 1 has left the game
2	You are restricted from that command
1	Player 1 Joined the game
1	No admin privileges
This was something closer to my intention

btw, don't you mean
1
_data = _data .. "\n" .. uname .. " " .. tableToString(uname)

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
the individual privilege check should be manually implemented inside the switch functions, it can be accessed using users["name"].privilege. But do not use a conditional check outside since by logic the code should look for the case and then check privilege (less iterations).

For the tables, lua runs on a rather optimized version of the C type arrays, a thousand elements, assuming each elements is no more then 20 bytes (which would be a really long username-password combination itself) then a thousand lines would take no more memory than 20KB of ram, compared to using the lua os access functions which uses considerably more resource when you have to open it, read the whole content, store it temporarily (using the same amount of memory I might add), close the file, check if a certain user is in the file, all this every single time you have to parse a command (Because that's the only viable way to do it without a permanent storage). This by itself can take a while if your file is large and not to mention it's also slower to access since lua indexes elements by default in tables.

1
_data = _data .. "\n" .. uname .. " " .. tableToString(uinfo)

No, don't use uname as the parameter since Pair returns the key/definition. But yeah, I did get the parameter wrong since I originally had the key/def pairs set up as uname/user, but changed it for context's sake to uname/uinfo, so the correct parameter would be uinfo, of course, you'll have to modify tableToString function though since the current one only supports indexed keys.
edited 2×, last 04.03.09 07:14:13 pm

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
Ahhhh so what your trying to do is restrict one person to be able to do something, such as this and that, and another may have be able to do all commands and such. I see.

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
will it be possible to make Rambo (or Powerball) games where someone is the Rambo and every one is hunting you, but you can only score when u are the rambo (or when you have the powerball), and if you kill the rambo then u become the rambo, also rambo can only use M249, just a idea...

old Re: Lua Scripts for CS2D

Zune5
COMMUNITY BANNED Off Offline

Quote
I would think it is possible. I mean you change the team so only 1 is terrorist, and everyone is on CT. So yeah, I would think so.

old Re: Lua Scripts for CS2D

Kiffer-Opa
User Off Offline

Quote
I'm currently working on some new game types. These are:

•Kiffer-Opa's GunGame (KOGG)
An all-vs.-all Deathmatch where you have to be the first to reach the score limit by owning the others with all weapons.
> You get a certain weapon you have to kill with
> get a new weapon with every x kills (x is usually between 1 and 5)
> start with cheap-kill weapons (Laser, Flamethrower) and ...
> ... end up with expensive-kill (:D) weapons like AWP, Knife and even Wrench

> short: like TMK's "GunGame Turbo" on his server "cs2dg.rox.pl@GG" with some differences


•Ghost Bomb
A variation of Bombdefuse where
> all Terrorists get invisible,
> only have knifes,
> and can't buy or collect guns/equipment

> the CTs are like in normal Bombdefuse

I plan to use this game mode for normal de_ bombdefuse maps. It's not neccessary, but possible to create new maps for that mode.
The idea is taken from the game mode "Ghost Mode" from the game "Crossfire".

•The Hidden 2D
> A round-based Deathmatch:
One fast and invisible Terrorist only with knife and without Fog of War
versus
many slow and visible CTs with guns and with FoW


Maybe this can't be realized unless DC makes it possible to change the player's speed and allows full invisibility and allowes different FOW settings for different players
Idea taken from The Hidden 2D mod for CS2D (development currently stopped at the moment).

• Rambo (later)
chuico123 has written
will it be possible to make Rambo (or Powerball) games where someone is the Rambo and every one is hunting you, but you can only score when u are the rambo

Yes, it will. Because item stuff and score is both server-sided.
Great idea! I think, I will make a Lua script for that.

It's important to say that this game has exactly one strong Rambo weapon; the player who got it is the Rambo.
Then it should technically a Deathmatch so you can prevent other players from collecting the strong Rambo weapon after someone owned Rambo.

Maybe this rambo weapon can be determinated by the server.
It could be a scout (all other players get rifles, SMGs and pistols),
or a flamethrower or even a laser (if playing with lots of players).

What Rambo definately should NOT get is high health or high defense. Just a strong weapon.

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
here's a premature concept of a modular system for lua so we can simultaneously run multiple mods at the same time.

I would ask that all developers, for the sake of ease of use for us and for the users, hold off on making mods that are not cross compatible until this system is finished.

hooks.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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
users = {}
players = {}
modules = {}
admins = {}
cmd_priv = {}

--Temp msg2(p, t)
function msg2(p, t)
	print (p, t)
end

function switch(t)
	t.case = function (self,x, y)
		local f=self[x] or self.default
		if f then
			if type(f)=="function" then
				f(self, y)
			else
				error("case "..tostring(x).." not a function")
			end
		end
	end
  	return t
end

function tableToString(t, n)
	local s = ""
	if (n == nil) then n = 1 end
	while (n <= #t) do
		s = s .. t[n] .. " "
		n = n + 1
	end
	return s
end

function mod_init()
    for line in io.lines("mods.cfg") do
		local f = loadfile(line)
		setglobal(f, t)
		f()
	end
end

function hook_init()

	mod_init()
    
	for line in io.lines("Admins.cfg") do
		local tempUser = {}
		for word in string.gmatch(line, "%a+") do
			table.insert(tempUser, word)
		end
		users[tempUser[1]] = {password=tempUser[2], privilege = tempUser[3]}
	end
	
	local acts = {}
	acts.default = function(p) msg2(p[1], "Error: Command Does Not Exist: "..p[2]) end
	local admacts = {}
	admacts.default = function(p) msg2(p[1], "Error: Admin Command Does Not Exist: "..p[2]) end
	
	for mod_name, module in pair(modules) do
		for act_name, act_fn in pair(module.acts) do
			acts[act_name] = act_fn
		end
	    
		for admact_name, admact_fn in pair(module.admacts) do
			admacts[admact_name] = admact_fn
		end
	end
	
	action = switch(acts)
	admin_action = switch(admacts)
end

function parseCmd(t, priv, args)
	local cmd = {}
	if (type(t) ~= "table") then cmd = t end
	if (priv == nil) then priv = false end
	if (type(priv) == "table") then args = priv; priv = false end
	
	if (cmd[1] == nil) then
		for word in string.gmatch(t, "%a+") do
			table.insert(cmd, word)
		end
	end
	
	local typ = string.lower(cmd[1])
	table.remove(cmd, 1)
	
	if priv then
		if (typ == "login") then
			username = cmd[1]
			password = cmd[2]
			if (users[username]) then			
				if (users[username].password == password) then
					admin[p] = users[username].privilege
				else
					msg2(p, "User Found but Incorrect Password")
				end
			else
				msg2(p, "No User with the Username: "..username)
			end
		elseif (cmd_priv[admin[p]]) then
			local privilege = admin[p]
            
			command = tableToString(cmd)
			admin_action:case(typ, {args[1], typ, command})
		else
			msg2(p, "No admin privileges")
		end
	else
		command = tableToString(cmd)
		action:case(typ, {args[1], typ, command})
	end
	
end

function hook_say(p, t)
	if (string.lower(string.sub(t, 1, 1)) == "@") then
		t = string.sub(t, 1)
		parseCmd(cmd, true, {p})
	elseif (string.lower(string.sub(t, 1, 1)) == "/") then
		t = string.sub(t, 1)
		parseCmd(cmd, false, {p})
	end
end

testMod.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
modules[testMod] = {}

--Acts
modules[testMod].acts = {}
--Sample command - sampleAct - parameters {p, typ, cmd}
function testMod_sampleAct(args)
	local id = args[1]
	local typ = args[2]
	local cmd = args[3]
    
	msg2(p, cmd)
end
--Add the sampleAct command to the acts list
modules[testMod].acts.sampleAct = function(p) testMod_sampleAct(p) end 

--Admin Acts
modules[testMod].admacts = {}
--Sample command - sampleAdmAct - parameters {p, typ, cmd}
function testMod_sampleAdmAct(args)
	local id = args[1]
	local typ = args[2]
	local cmd = args[3]
    
	msg2(p, cmd)
end
--Add the sampleAdmAct command to the acts list
modules[testMod].admacts.sampleAdmAct = function(p) testMod_sampleAdmAct(p) end

The only problem currently is that the global table of the super process isn't being delegated to the sub process when we call in loadfile, however I'm sure there's a good way to handle this since the only thing that needs to be returned is a module table which means that we can fork the functions and just call subprocess.returnTable() (to be written) which would return the module table that we can add to the global modules table.

In this case, we will be able to add different "subhooks" into the module files and call them along with a customized "cron" system for periodic checks. The concept is relatively simple, the modules will be placed in 2 dimensional tables and for each hook, we iterate through all of the module tables and call the subhook for that particular module. This ensures a standard way of writing mods for the game as well as the flexibility of co-using different mods at the same time.

old Re: Lua Scripts for CS2D

chuico123
User Off Offline

Quote
thanks kiffer opa, i really liked what u have writen, also, the person that is the rambo (or is holding the Powerball), should get more armor, since its everyone against 1

old Re: Lua Scripts for CS2D

Tehmasta
User Off Offline

Quote
wow leegao, that was what i was trying to do, you already finished before i could....

btw, i think you make a couple of errors

1
t = string.sub(t, 1)
would this actually accomplish anything? Wouldn't this just take the sub of the string t, starting from 1 to the end? which is the entire string of t
1
parseCmd(cmd, true, {p})
you didn't declare the variable cmd, i think you meant

1
2
cmd = string.sub(t, 2)
parseCmd(cmd, true, {p})

also, is there a way to bypass standard the standard cs2d display and not display the text when someone says something? Otherwise, @login user pass would let everyone see it.
edited 1×, last 06.03.09 11:57:00 pm

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
Tehmasta has written
wow leegao, that was what i was trying to do, you already finished before i could....

btw, i think you make a couple of errors

1
t = string.sub(t, 1)
would this actually accomplish anything? Wouldn't this just take the sub of the string t, starting from 1 to the end? which is the entire string of t
1
parseCmd(cmd, true, {p})
you didn't declare the variable cmd, i think you meant

1
2
cmd = string.sub(t, 2)
parseCmd(cmd, true, {p})

also, is there a way to bypass standard the standard cs2d display and not display the text when someone says something? Otherwise, @login user pass would let everyone see it.


1. No, the substring function splices a string after the i indice (the second parameter) and returns the upper tail.

2. probably will be, I'm pretty sure I encountered the same error while I redid the code (yet again) so nice catch there

Anyways, I've finished a modular hook system so people can run multiple mods at the same time, you can find it in the other thread.

on the bubbling question, I was about to ask DC to implement a bubble nullification method (ie calling return nil in hook_say to not display what was spoken), in this case it would make any type of administration system tons easier to use.

old Re: Lua Scripts for CS2D

DC
Admin Off Offline

Quote
done. in another way. returning 1 in the hooks say, sayteam or radio will skip the message output.

old Re: Lua Scripts for CS2D

Reaper
User Off Offline

Quote
Kiffer-Opa has written
•The Hidden 2D
Maybe this can't be realized unless DC makes it possible to change the player's speed and allows full invisibility and allowes different FOW settings for different players
Idea taken from The Hidden 2D mod for CS2D (development currently stopped at the moment).


Hi Kiffer-Opa, check my quote in the cs2dn forum in the hidden 2d topic.

old Re: Lua Scripts for CS2D

Lee
Moderator Off Offline

Quote
here's a quick rewrite of DC's quake sounds using the new mods system with a few extra commands.

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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
--------------------------------------------------
-- UT+Quake Sounds Script by Unreal Software --
-- 22.02.2009 - www.UnrealSoftware.de --
-- Adds UT and Quake Sounds to your Server --
--------------------------------------------------
--** Ported By Lee Gao: http://tgvserver.info **--

quakeMod_module = {}

--***********--
--*Variables*--
--***********--

quakeMod_sound = "fun"
quakeMod_timeout = 3
quakeMod_timer = {}
quakeMod_level = {}

--************--
--*Initialize*--
--************--
function quakeMod_init(arg)
	--init the arrays so they don't return nil.
	quakeMod_level=initArray(32)
	quakeMod_timer=initArray(32)
end
quakeMod_module.init = function(arg) quakeMod_init(arg) end

--******--
--*Acts*--
--******--

quakeMod_module.acts = {}
--Sample command - sampleAct - parameters {p, typ, cmd}
function quakeMod_qklevel(p, x, cmd)
	local n = p
	if (cmd and tonumber(cmd)) then n = tonumber(cmd) end
	if quakeMod_level[n] then
		msg2(p, player(n,"name").." scored "..quakeMod_level[n].." kills")
	end
end
--Add the sampleAct command to the acts list - Do not forget to use all lower for the name of the field
quakeMod_module.acts.qklevel = function(p, x, cmd) quakeMod_qklevel(p, x, cmd) end

function quakeMod_qktimeout(p, x, cmd)
	local n = p
	if (cmd and tonumber(cmd)) then n = tonumber(cmd) end
	if quakeMod_timer[n] then
		msg2(p, player(n,"name").." have "..math.floor(quakeMod_timeout-(os.clock()-quakeMod_timer[n])).." seconds until his level is reset")
	end
end
--Add the sampleAct command to the acts list - Do not forget to use all lower for the name of the field
quakeMod_module.acts.qktimeout = function(p, x, cmd) quakeMod_qktimeout(p, x, cmd) end

--************--
--*Admin Acts*--
--************--

--Admin Acts
quakeMod_module.admacts = {}
--Admin Privilege
quakeMod_module.privilege = {}

--Sample command - sampleAdmAct - parameters {p, typ, cmd}
function quakeMod_setSound(p, x, cmd)
	if (cmd and type(cmd) == "string") then
		if (io.open(cmd.."/prepare.wav") or cmd == "no") then
			quakeMod_sound = cmd;
			msg2(p, "cvar qk_sound set to \'"..cmd.."\'")
		end
	end
end
--Add the sampleAdmAct command to the acts and privilege list - Do not forget to use all lower for the name of the field
quakeMod_module.admacts.qksetsound = function(p, x, cmd) quakeMod_setSound(p, x, cmd) end
quakeMod_module.privilege.qksetsound= "a"

--Sample command - sampleAdmAct - parameters {p, typ, cmd}
function quakeMod_setTimeout(p, x, cmd)
	if (cmd and tonumber(cmd)) then
		quakeMod_timeout = tonumber(cmd);
		msg2(p, "cvar qk_timeout set to \'"..cmd.."\'")
	end
end
--Add the sampleAdmAct command to the acts and privilege list - Do not forget to use all lower for the name of the field
quakeMod_module.admacts.qksettimeout = function(p, x, cmd) quakeMod_setTimeout(p, x, cmd) end
quakeMod_module.privilege.qksettimeout= "a"

--*******--
--*Hooks*--
--*******--

--startround
function quakeMod_startround()
	--start round stuff
	parse("sv_sound \""..quakeMod_sound.."/prepare.wav\"");
end
quakeMod_module.startround = function() quakeMod_startround() end

function quakeMod_kill(killer,victim,weapon)
	--On kill
     if (os.clock()-quakeMod_timer[killer])>quakeMod_timeout then
          quakeMod_level[killer]=0;
     end
     quakeMod_level[killer]=quakeMod_level[killer]+1;
	 local level = quakeMod_level[killer]
     quakeMod_timer[killer]=os.clock();
     -- HUMILIATION? (KNIFEKILL)
     if (weapon==50) then
          -- HUMILIATION!
          parse("sv_sound \""..quakeMod_sound.."/humiliation.wav\"");
          msg (player(killer,"name").." humiliated "..player(victim,"name").."!");
	 end

          -- REGULAR KILL
          if (level==1) then
               -- Single Kill! Nothing Special!
          elseif (level==2) then
               parse("sv_sound \""..quakeMod_sound.."/doublekill.wav\"");
               msg (player(killer,"name").." made a Doublekill!");
          elseif (level==3) then
               parse("sv_sound \""..quakeMod_sound.."/multikill.wav\"");
               msg (player(killer,"name").." made a Multikill!");
          elseif (level==4) then
               parse("sv_sound \""..quakeMod_sound.."/ultrakill.wav\"");
               msg (player(killer,"name").." made an ULTRAKILL!");
          elseif (level==5) then
               parse("sv_sound \""..quakeMod_sound.."/monsterkill.wav\"");
               msg (player(killer,"name").." made a MO-O-O-O-ONSTERKILL-ILL-ILL!");
          else
               parse("sv_sound \""..quakeMod_sound.."/unstoppable.wav\"");
               msg (player(killer,"name").." is UNSTOPPABLE! "..level.." KILLS!");
          end

end
quakeMod_module.kill = function(arg1, arg2, arg3) quakeMod_kill(arg1, arg2, arg3) end

--********--
--*Return*--
--********--
return quakeMod_module

Simulated round
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
--Simulated Round
--Start the round
--Then have Player 1 magically kill 5 people in the course of 3 seconds.
hook_init()
hook_startround()
hook_kill(1, 2, 40)
sleep(1)
hook_kill(1, 2, 40)
hook_kill(1, 3, 40)
sleep(1)
hook_kill(1, 4, 40)
sleep(1)
hook_kill(1, 2, 50)
hook_say(1, "/qk_level")
hook_say(1, "/qk_level 2")
hook_say(1, "/qk_timeout 1")
sleep(1)
hook_say(1, "/qk_timeout 1")
hook_say(1, "@login admin pass")
hook_say(1, "@qk_setTimeout 10")
hook_say(1, "/qk_timeout 1") -- Note, this should return 9 since we've already used one of those seconds.

Output
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Debug message from testMod_init
Srv	Server executed command: sv_sound "fun/prepare.wav"
Slp	Sleeping for 1 seconds
Srv	Server executed command: sv_sound "fun/doublekill.wav"
All	Player 1 made a Doublekill!
Srv	Server executed command: sv_sound "fun/multikill.wav"
All	Player 1 made a Multikill!
Slp	Sleeping for 1 seconds
Srv	Server executed command: sv_sound "fun/ultrakill.wav"
All	Player 1 made an ULTRAKILL!
Slp	Sleeping for 1 seconds
Srv	Server executed command: sv_sound "fun/humiliation.wav"
All	Player 1 humiliated Player 2!
Srv	Server executed command: sv_sound "fun/monsterkill.wav"
All	Player 1 made a MO-O-O-O-ONSTERKILL-ILL-ILL!
1	Player 1 scored 5 kills
1	Player 2 scored 0 kills
1	Player 1 have 3 seconds until his level is reset
Slp	Sleeping for 1 seconds
1	Player 1 have 2 seconds until his level is reset
1	User "admin" logged in successfully, your privilege mask is "a"
1	cvar qk_timeout set to '10 '
1	Player 1 have 9 seconds until his level is reset
To the start Previous 1 2 3 4 5 6 7 Next To the start
Log in to replyGeneral overviewCS2D overviewForums overview