SA-MP Forums Archive
Detecting a cmd and the value, zcmd issue - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Detecting a cmd and the value, zcmd issue (/showthread.php?tid=635731)



Detecting a cmd and the value, zcmd issue - Omirrow - 12.06.2017

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.


Re: Detecting a cmd and the value, zcmd issue - Omirrow - 12.06.2017

I still need help.


Re: Detecting a cmd and the value, zcmd issue - BigETI - 13.06.2017

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


Re: Detecting a cmd and the value, zcmd issue - Omirrow - 13.06.2017

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.


Re: Detecting a cmd and the value, zcmd issue - Freedom. - 13.06.2017

deleted


Re: Detecting a cmd and the value, zcmd issue - Omirrow - 14.06.2017

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


Re: Detecting a cmd and the value, zcmd issue - Omirrow - 17.06.2017

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


Re: Detecting a cmd and the value, zcmd issue - Konstantinos - 17.06.2017

strcmp has a length option which is optional.

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



Re: Detecting a cmd and the value, zcmd issue - Omirrow - 19.06.2017

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?


Re: Detecting a cmd and the value, zcmd issue - Konstantinos - 20.06.2017

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.