SA-MP Forums Archive
/Command *HELP* - 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: /Command *HELP* (/showthread.php?tid=582833)



/Command *HELP* - TheSkyBlueTeam - 23.07.2015

Hey, I want to kick players who execute this command, but how do I make it so whenever they type /command 1 they'll be kicked from the server?

Code:

if(strcmp(cmdtext, "/Command", true) == 0)
{
//Random message
SendClientMessage(playerid, 0xFF0000FF, "Kicked");
SetTimerEx("DelayedKick", 1000, false, "i", playerid);
return 1;
}

It's hard to explain, but basically, if the player types /Command (ANYNUMBER FROM 1-1000) they will be kicked? Cause I don't wanna type this a 1000 times i.e like this:

if(strcmp(cmdtext, "/Command 1", true) == 0)
{
//Random message
SendClientMessage(playerid, 0xFF0000FF, "Kicked");
SetTimerEx("DelayedKick", 1000, false, "i", playerid);
return 1;
}

if(strcmp(cmdtext, "/Command 2", true) == 0)
{
//Random message
SendClientMessage(playerid, 0xFF0000FF, "Kicked");
SetTimerEx("DelayedKick", 1000, false, "i", playerid);
return 1;
}

And so on..I'm terrible at describing things...sorry.


Re: /Command *HELP* - TheSkyBlueTeam - 23.07.2015

Anyone?


Re: /Command *HELP* - Abagail - 23.07.2015

Using ZCMD:
pawn Код:
CMD:command(playerid, params[])
{
      new integer = strval(params);
      if(integer >= 1 && integer < 1001) {
            SendClientMessage(playerid, 0xFF0000FF, "Kicked");
            SetTimerEx("DelayedKick", 1000, false, "i", playerid);
      }

      return 1;
}



AW: /Command *HELP* - Mencent - 23.07.2015

Hello!

Try this:
PHP код:
//At the top of OnPlayerCommandText
new cmd[128],idx;
cmd strtok(cmdtext,idx);
//The command
if(!strcmp(cmdtext,"/Command",true))
{
    new 
tmp[128];
    
tmp strtok(cmdtext,idx);
    if(
<= tmp <= 1000)
    {
        
//Random Message
        
SendClientMessage(playerid,0xFF0000FF,"Kicked");
        
SetTimerEx("DelayedKDick",1000,false,"i",playerid);
    }
    return 
1;
}
//in the script
stock strtok(const string[], &index//©Jeffry
{
    new 
result[20], length strlen(string), index;
    while ((
length) && (string[i] == ' ')) i++;
    
strmid(result,string,i,((index strfind(string" "falsei)) == -1) ? (index length) : (index) , 20);
    
index++;
    return 
result;

- Mencent


Re: AW: /Command *HELP* - Abagail - 23.07.2015

@Mencent, all of your code uses outdated methods. Strcmp text handling and strok are both very outdated and are no longer the common practice for commands. You should use something such as ZCMD, or atleast sscanf to split the string(which still using strcmp isn't recommended).


Re: /Command *HELP* - TheSkyBlueTeam - 23.07.2015

Quote:
Originally Posted by Abagail
Посмотреть сообщение
Using ZCMD:
pawn Код:
CMD:command(playerid, params[])
{
      new integer = strval(params);
      if(integer >= 1 && integer < 1001) {
            SendClientMessage(playerid, 0xFF0000FF, "Kicked");
            SetTimerEx("DelayedKick", 1000, false, "i", playerid);
      }

      return 1;
}
Hey, that didn't work. Not sure what I did wrong:

if(strcmp(cmdtext, "/command", true) == 0)
{
CMD:command(playerid, params[])
{
new integer = strval(params);
if(integer >= 1 && integer < 1001) {
SendClientMessage(playerid, 0xFF0000FF, "Kicked");
SetTimerEx("DelayedKick", 1000, false, "i", playerid);
}


AW: Re: AW: /Command *HELP* - Mencent - 23.07.2015

Quote:
Originally Posted by Abagail
Посмотреть сообщение
@Mencent, all of your code uses outdated methods. Strcmp text handling and strok are both very outdated and are no longer the common practice for commands. You should use something such as ZCMD, or atleast sscanf to split the string(which still using strcmp isn't recommended).
Oh, yes. I haven't carefully considered.

- Mencent


Re: AW: /Command *HELP* - TheSkyBlueTeam - 23.07.2015

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hello!

Try this:
PHP код:
//At the top of OnPlayerCommandText
new cmd[128],idx;
cmd strtok(cmdtext,idx);
//The command
if(!strcmp(cmdtext,"/Command",true))
{
    new 
tmp[128];
    
tmp strtok(cmdtext,idx);
    if(
<= tmp <= 1000)
    {
        
//Random Message
        
SendClientMessage(playerid,0xFF0000FF,"Kicked");
        
SetTimerEx("DelayedKDick",1000,false,"i",playerid);
    }
    return 
1;
}
//in the script
stock strtok(const string[], &index//©Jeffry
{
    new 
result[20], length strlen(string), index;
    while ((
length) && (string[i] == ' ')) i++;
    
strmid(result,string,i,((index strfind(string" "falsei)) == -1) ? (index length) : (index) , 20);
    
index++;
    return 
result;

- Mencent
Hey, I get this error: error 033: array must be indexed (variable "tmp")


AW: /Command *HELP* - Mencent - 23.07.2015

PHP код:
if(<= tmp <= 1000
to

PHP код:
if(<= strval(tmp) <= 1000
Sorry for this stupid mistake.

- Mencent


Re: AW: /Command *HELP* - TheSkyBlueTeam - 23.07.2015

Quote:
Originally Posted by Mencent
Посмотреть сообщение
PHP код:
if(<= tmp <= 1000
to

PHP код:
if(<= strval(tmp) <= 1000
Sorry for this stupid mistake.

- Mencent
Alright, I compiled it but it won't work. Server dosen't kick me when I type /command or /command 234.

I put this piece of code on top of the script:

stock strtok(const string[], &index) //©Jeffry
{
new result[20], length = strlen(string), i = index;
while ((i < length) && (string[i] == ' ')) i++;
strmid(result,string,i,((index = strfind(string, " ", false, i)) == -1) ? (index = length) : (index) , 20);
index++;
return result;
}

Not sure if that's correct or not.