Reason
#1

Well, for somereason when I kick someone it just doesn't write the reason, the reason is just empty.

PHP код:
CMD:kick(playeridcmdtext[], reason[])
{
    new
        
idx 0,
        
idx2 0,
        
tmp[256],
        
tmp2[256],
        
string[128];
    
tmp strtok(cmdtextidx);
    
tmp2 strtok(reasonidx2);
    new 
id strval(tmp);
    if(
GetPVarInt(playerid"Admin") != 1) return 0;
    if(!
strlen(tmp)) return SendClientMessage(playeridCOLOR_WHITE"[USAGE:] /kick [playerid] [reason]");
    
format(stringsizeof(string), "AdmCmd: %s was kicked by %s, reason: %s"GetName(id), GetName(playerid), tmp2);
    
SendClientMessageToAll(COLOR_REDstring);
    
Kick(id);
    return 
1;

Reply
#2

I'd recommend you to use ZCMD with sscanf 2.6;

https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#3

I already use ZCMD, and I also use sscanf sometimes but I want to know both strtok and sscanf to expand my knowledge.
Reply
#4

pawn Код:
CMD:kick(playerid, params[])
{
     new name[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], id, reason, string[128];
     if(GetPVarInt(playerid, "Admin") != 1) return 0;
     if(sscanf(params, "ui", id, reason)) return SendClientMessage(playerid, -1, "USAGE: /kick [playerid] [reason]");
     GetPlayerName(playerid, name, MAX_PLAYER_NAME);
     GetPlayerName(id, targetname, MAX_PLAYER_NAME);
     if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, -1, "Player not connected!");
     Kick(id);
     format(string, 128, "Administrator %s(%d) kicked player: %i Reason: %i", name, playerid, targetname, reason);
     SendClientMessageToAll(-1, string);
     format(string, 128, "You kicked player: %s(%d) reason: %i", targetname, id, reason);
     SendClientMessage(playerid, -1, string);
     return 1;
}
NOT TESTED
Reply
#5

Couldn't you read what I wrote, I want it to use strtok, and I do not need a new function, just to fix mine. Thanks.
Reply
#6

pawn Код:
CMD:kick(playerid, params[])
{
if(GetPVarInt(playerid, "Admin") != 1) return 0;
{
new string[128];
format(string, sizeof(string), "You cant use that command you are not that level");
SendClientMessage(playerid, COLOR_ORANGE, string);
}
else
{
new tmp[256], tmp2[256], index, id;
tmp = strtok(params, index);
tmp2 = strtok(params, index);

if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_ORANGE, "[KICK] Usage: /kick [ID] [REASON]");
}
else if(!strlen(tmp2))
{
SendClientMessage(playerid, COLOR_ORANGE, "[KICK] Usage: /kick [ID] [REASON]");
}
else
{
id = strval(tmp);
if(!IsPlayerConnected(id))
{
SendClientMessage(playerid, COLOR_ORANGE, "[KICK] That player is not connected.");
}
else if(id == playerid)
{
SendClientMessage(playerid, COLOR_ORANGE, "[KICK] You can't kick yourself.");
}
else if(gPlayerInfo[id][PLAYER_LEVEL] > gPlayerInfo[playerid][PLAYER_LEVEL])
{
SendClientMessage(playerid, COLOR_ORANGE, "[KICK] That player has a higher level than you.");
}
else
{
new string[256], name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
if(id >= 0 && id <= 9)
{
format(string, sizeof(string), "[KICK] You have been kicked. Reason: %s.", params[2]);
SendClientMessage(id, COLOR_ORANGE, string);
Kick(id);
format(string, sizeof(string), "[KICK] Player %s has been kicked. Reason: %s.", name, params[2]);
SendClientMessageToAll(COLOR_ORANGE, string);
}
else if(id >= 10 && id <= 99)
{
format(string, sizeof(string), "[KICK] You have been kicked. Reason: %s.", params[3]);
SendClientMessage(id, COLOR_ORANGE, string);
Kick(id);
format(string, sizeof(string), "[KICK] Player %s has been kicked. Reason: %s.", name, params[3]);
SendClientMessageToAll(COLOR_ORANGE, string);
}
}
}
}
return 1;
}
NOT TESTED
Reply
#7

Never mind, solved. I was dumb enough to forget that I can easily use strrest.
Reply
#8

btw look up ):

EDIT: Atleast give us rep
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)