/Command *HELP*
#1

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.
Reply
#2

Anyone?
Reply
#3

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;
}
Reply
#4

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
Reply
#5

@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).
Reply
#6

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);
}
Reply
#7

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
Reply
#8

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")
Reply
#9

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

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

- Mencent
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)