Forum

> > CS2D > Scripts > Unknown command
Forums overviewCS2D overview Scripts overviewLog in to reply

English Unknown command

7 replies
To the start Previous 1 Next To the start

old Unknown command

tos12345678
User Off Offline

Quote
Hi, i need a script which will be saying player that the command is unknown after entering wrong command.
e.g !adadadadadad(now server should tell(Error:unknown command)
cause this command doesn't not exist on the server. thanks

old Re: Unknown command

DC
Admin Off Offline

Quote
In order to know that the command is unknown you have to know whether a command has been processed successfully.

So you basically have to adjust your existing script(s). They probably have one or more say-hooks for command processing. If it's just one hook you can do something like:

1
2
3
4
5
6
7
8
9
10
11
if cmd == "foo" then
	...
else if cmd == "bar" then
	...
else if cmd == "..." then
	...
	...
	...
else
	msg("unknown command: " ..  cmd)
end

If you have multiple say-hooks for command parsing the easiest solution would probably be to merge them to just one say-hook.

Otherwise you would have to work with a global flag variable which indicates that a command has been parsed and which is reset and checked by two additional say-hooks with proper priorities (one lower and one higher than all other say hooks for command parsing).

old Re: Unknown command

tos12345678
User Off Offline

Quote
I mean about all unknown commands which player writing will be not working and and chat will be revelaed text: Unknown command.
@user DC: Can you explain more clearly?
edited 1×, last 09.06.18 03:13:25 pm

old Re: Unknown command

tos12345678
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
addhook("say","say2")
function say2(id,txt)
        if txt:sub(1,1) == "!" then
          local cmd = txt:sub(2)
          if cmd == "help" then
			msg2(id,"Server commands")
		msg2(id,"©100255100!help - all commands")
		msg2(id,"©100255100!antidote - move to survivor for 500leaves")
		msg2(id,"©100255100!shop - shop for vips")
		msg2(id,"©100255100!reset - reset your account")
		msg2(id,"©100255100!info [player id] - check player stats")
	 return 1
	 end
	 end

others commands e.g !jasdnsda should saying Error unknown commands.

old Re: Unknown command

Rainoth
Moderator Off Offline

Quote
1
2
else
	msg2(id, "unknown command: !" ..  cmd)

Add this after
msg2(id,"©100255100!info [player id] - check player stats")
and add an
end
after
return 1

old Re: Unknown command

Cure Pikachu
User Off Offline

Quote
In that case,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
addhook("say","say2")
function say2(id,txt)
	if txt:sub(1,1) == "!" then
		local cmd = txt:sub(2)
		if cmd == "help" then
			msg2(id,"Server commands")
			msg2(id,"©100255100!help - all commands")
			msg2(id,"©100255100!antidote - move to survivor for 500leaves")
			msg2(id,"©100255100!shop - shop for vips")
			msg2(id,"©100255100!reset - reset your account")
			msg2(id,"©100255100!info [player id] - check player stats")
		-- do your other commands first, such as the 4 commands shown in your help uh... prompt?
		elseif cmd == "antidote" then
		elseif cmd == "shop" then
		elseif cmd == "reset" then
		elseif cmd:sub(1,4) == "info" then
		-- the one you are looking for after all that
		else
			msg2(id,"unknown command: !"..cmd)
		end
		return 1
	end
end
That's what user DC is trying to say, pretty much.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview