Detecting a cmd and the value, zcmd issue
#1

Hey there,

I have tried a lot of options to fix this problem but I couldn't find a valid solution. I use zcmd in a gamemode and I scripted an anti spam recently, it works fine but the thing is I'd like to skip a few commands, keep them out of the anti spam script.

I can skip them like that;

Код:
new lastcmd[MAX_PLAYERS];

public OnPlayerCommandPerformed(playerid,cmdtext[],success)
{
    if(!success) return 1;
    if(success)
	{
		lastcmd[playerid]=gettime();
	}
	return 1;
}

public OnPlayerCommandReceived(playerid, cmdtext[])
{
	if(strcmp(cmdtext, "/xx", false))
	{
	    if(lastcmd[playerid]!=0 && gettime()-lastcmd[playerid] <= 3)
		{
			SendClientMessage(playerid,-1,"stop spamming");
			return 0;
		}
	}
	return 1;
}
With this code, we prevent the anti spam system to keep "/xx" command out of spam but the thing is, my /xx command has a value, it works like '/xx [texthere]'

So the output at the end is something like that "/xx hello" so, how can I block this ? Using a similar code as above?

EDIT: If you wonder the command;

Код:
CMD:xx(playerid, params[])
{
	if(isnull(params)) return SendClientMessage(playerid,-1,"/xx [text]");
	return 1;
}
Basically something like that, I get params from the cmd and use it somewhere else.
Reply
#2

I still need help.
Reply
#3

If you write inside a "command function", you already know its name. For the parameters search for "string scan format"
Reply
#4

Quote:
Originally Posted by BigETI
Посмотреть сообщение
If you write inside a "command function", you already know its name. For the parameters search for "string scan format"
Well, how can I use a command's parameter in OnPlayerCommandReceived public? How do I detect it, can you expand your answer a little bit more?

An example would be great.
Reply
#5

deleted
Reply
#6

I still need help, how can I detect a cmd with it's parameters?
Reply
#7

I couldn't find a way to get it working, still need help.
Reply
#8

strcmp has a length option which is optional.

pawn Код:
if(strcmp(cmdtext, "/xx") && strcmp(cmdtext, "/xx ", true, 4))
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
strcmp has a length option which is optional.

pawn Код:
if(strcmp(cmdtext, "/xx") && strcmp(cmdtext, "/xx ", true, 4))
pawn Код:
strcmp(cmdtext, "/xx ", true, 4)
What does actually this do? I mean, what if it's longer than 4 characters, my command's output is usually something like that: "/xx hello people, this is a channel that you can talk like that." So, in this situation, should I put an estimated length?
Reply
#10

Quote:
Originally Posted by Omirrow
Посмотреть сообщение
pawn Код:
strcmp(cmdtext, "/xx ", true, 4)
What does actually this do? I mean, what if it's longer than 4 characters, my command's output is usually something like that: "/xx hello people, this is a channel that you can talk like that." So, in this situation, should I put an estimated length?
It only compares the first 4 characters "/xx hello people, this is a channel that you can talk like that." and ignores the params part.

@jlalt: strfind returns -1 if not found.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)