Reason -
Tomer!.$ - 28.04.2012
Well, for somereason when I kick someone it just doesn't write the reason, the reason is just empty.
PHP код:
CMD:kick(playerid, cmdtext[], reason[])
{
new
idx = 0,
idx2 = 0,
tmp[256],
tmp2[256],
string[128];
tmp = strtok(cmdtext, idx);
tmp2 = strtok(reason, idx2);
new id = strval(tmp);
if(GetPVarInt(playerid, "Admin") != 1) return 0;
if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_WHITE, "[USAGE:] /kick [playerid] [reason]");
format(string, sizeof(string), "AdmCmd: %s was kicked by %s, reason: %s", GetName(id), GetName(playerid), tmp2);
SendClientMessageToAll(COLOR_RED, string);
Kick(id);
return 1;
}
Re: Reason -
Twisted_Insane - 28.04.2012
I'd recommend you to use ZCMD with sscanf 2.6;
https://sampforum.blast.hk/showthread.php?tid=120356
Re: Reason -
Tomer!.$ - 28.04.2012
I already use ZCMD, and I also use sscanf sometimes but I want to know both strtok and sscanf to expand my knowledge.
Re: Reason -
James Coral - 28.04.2012
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
Re: Reason -
Tomer!.$ - 28.04.2012
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.
Re: Reason -
James Coral - 28.04.2012
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
Re: Reason -
Tomer!.$ - 28.04.2012
Never mind, solved. I was dumb enough to forget that I can easily use strrest.
Re: Reason -
James Coral - 28.04.2012
btw look up ):
EDIT: Atleast give us rep