Forum

> > CS2D > Scripts > How to make this thing have a error
Forums overviewCS2D overview Scripts overviewLog in to reply

English How to make this thing have a error

7 replies
To the start Previous 1 Next To the start

old How to make this thing have a error

KagamineLen
User Off Offline

Quote
i cant make an error message for this script if the command doents exists on the table

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
usertype[0]=4
commands = {}
commands.admin {"explode","kick","destroy"}

addhook("say","sayed")
function sayed(id,txt)
		if user_type[player(id,"usgn")] == 4 then
			for i = 1,#commands.admin do
				if (string.find(txt,commands.admin[i])~=nil) then
					commandprocessor(id,txt)
					break
				else
					msg2(id,"error: Command doesnt exists")
				end
			end
		end

old Re: How to make this thing have a error

Avo
User Off Offline

Quote
You did here big mistake, becouse if there are 100 commands in "commands.admin" and you try to use last one from this table, you will receive 99 messages. By the way:

1
if (string.find(txt,commands.admin[i])~=nil) then

is same as

1
if (string.find(txt,commands.admin[i])) then

old Re: How to make this thing have a error

Apache uwu
User Off Offline

Quote
Try this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
usertype[0]=4
commands={}
commands.admin={"explode","kick","destroy"}

addhook("say","sayed")

function sayed(id,txt)
	if user_type[player(id,"usgn")]==4 then
		for i=1,#commands.admin do
			if (string.find(txt,commands.admin[i])~=nil) then
			commandprocessor(id,txt)
			break
		 else
			msg2(id,"error: Command doesn't exist")
		end
	end
end

old Re: How to make this thing have a error

Gajos
BANNED Off Offline

Quote
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
usertype = {
	[0] = 4;
	[108942] = 4;
}

commands = {
	admin = {"explode","kick","destroy"};
}

iscmd = function(txt)
	for _, i in pairs(commands.admin) do
		if string.find(txt,commands.admin[i]) ~= nil then
			return true
		end
	end 
	return false
end

addhook("say","_say")
function _say(id,txt)
	if user_type[player(id,"usgn")] == 4 then
		if iscmd(txt) then
			commandprocessor(id,txt)
		else
			msg2(id,"error: Command doesnt exists")
		end
	end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview