Need a example of the command /kick with dcmd and strtok
#1

need a example of the command /kick with parameters, ID and reason, dcmd and strtok.

please
Reply
#2

Код:
dcmd_kick(playerid,params[]) {
   if(IsPlayerAdmin(playerid)) {
		  new tmp[256], tmp2[256], Index;		tmp = strtok(params,Index), tmp2 = strtok(params,Index);
		  if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /kick [playerid] [reason]");
	  	new player1, playername[MAX_PLAYER_NAME], adminname[MAX_PLAYER_NAME], string[128];
			player1 = strval(tmp);

		 	if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID) {
				GetPlayerName(player1, playername, sizeof(playername));		GetPlayerName(playerid, adminname, sizeof(adminname));
				if(!strlen(tmp2)) {
					format(string,sizeof(string),"%s has been kicked by Administrator %s [no reason given] ",playername,adminname); SendClientMessageToAll(grey,string);
				} else {
					format(string,sizeof(string),"%s has been kicked by Administrator %s [reason: %s] ",playername,adminname,params[2]); SendClientMessageToAll(grey,string);
				print(string); return Kick(player1); }
			} else return SendClientMessage(playerid, red, "Player is not connected or is yourself or is the highest level admin");
		} else return SendClientMessage(playerid,red,"ERROR: You are not admin");
}
Reply
#3

Dcmd and strtok are not modern anymore. We use zcmd and sscanf nowadays.

pawn Код:
COMMAND:kick(playerid, params[])
{
    if(IsPlayerAdmin(playerid))
    {
      new targetid,string[128];
      if(sscanf(params,"rs[128]",targetid,params)) SendClientMessage(playerid,0xFFFFFF,"USAGE: /kick [playerid] [reason]");
      else if(targetid == INVALID_PLAYER_ID) SendClientMessage(playerid,0xFFFFFF,"Invlaid player id.");
      else
      {
        format(string,sizeof(string),"KICK: %d was kicked; reason: %s",targetid,params);
        SendClientMessageToAll(0xFFFFFF, string);
        Kick(targetid);
      }
    }
    return 1;
}
PS: Compare above example with dcmd+strtok with my example. I think that difference is obivous.
Reply
#4

is..

Код:
if(sscanf(params,"rs[128]",targetid,params)) SendClientMessage(playerid,0xFFFFFF,"USAGE: /kick [playerid] [reason]");
equal to..

Код:
if(sscanf(params,"rs",targetid,params)) SendClientMessage(playerid,0xFFFFFF,"USAGE: /kick [playerid] [reason]");
?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)