Help with commands
#1

As an example, If I want to do a /kick command (/kick <id> <reason>) I can do

id = strval(cmdtext[9]);

As for the <reason> param of the command I am unsure. I have tried this (untested). Is the correct way?

pawn Код:
if((pos = strfind(cmdtext, " ", 6)) != -1) return pos = strfind(cmdtext, " ", 6)) != -1);
Then
pawn Код:
if(strval[pos] >= 0) return The number cannot be a number!
Im just using an example. Would that work?
Reply
#2

Why are you using strfind? O_o

Reply
#3

Quote:
Originally Posted by » Pawnst★r «
Why are you using strfind? O_o

Well, my friend made the code and he sent it to me O_o
Reply
#4

Oooh, well .. here is an example. This is from "base.pwn" which is shipped with the 0.3 scripting package:

pawn Код:
if(strcmp("/kick", cmd, true) == 0)
    {
      if(IsPlayerAdmin(playerid)) {
            tmp = strtok(cmdtext,idx);
            if(!strlen(tmp) || strlen(tmp) > 5) {
                return SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"Usage: /kick (id) [reason]");
            }
           
            new id = strval(tmp);

            if(!IsPlayerConnected(id)) {
                SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : Bad player ID");
                return 1;
            }
           
            gMessage = strrest(cmdtext,idx);
           
            GetPlayerName(id,iName,sizeof(iName));
            SendClientMessage(id,ADMINFS_MESSAGE_COLOR,"-- You have been kicked from the server.");

            if(strlen(gMessage) > 0) {
                format(Message,sizeof(Message),"Reason: %s",gMessage);
                SendClientMessage(id,ADMINFS_MESSAGE_COLOR,Message);
            }
           
            format(Message,sizeof(Message),">> %s(%d) has been kicked.",iName,id);
            SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,Message);
           
            Kick(id);
            return 1;
        } else {
      SendClientMessage(playerid,ADMINFS_MESSAGE_COLOR,"/kick : You are not an admin");
            return 1;
        }
    }

Reply
#5

Im not using strtok.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)