Forum

> > CS2D > Scripts > How to make this thing have a error
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch How to make this thing have a error

7 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt How to make this thing have a error

KagamineLen
User Off Offline

Zitieren
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

alt Re: How to make this thing have a error

Avo
User Off Offline

Zitieren
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

alt Re: How to make this thing have a error

Apache uwu
User Off Offline

Zitieren
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

alt Re: How to make this thing have a error

Gajos
BANNED Off Offline

Zitieren
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
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht