public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[128], idx;
cmd = strtok(cmdtext, idx);
if(strcmp(cmd, "/kick", true) == 0)
{
new tmp[128];
tmp = strtok(cmdtext, idx);
if(strlen(tmp) == 0)
{
SendClientMessage(playerid, 0xFFFFFFFF, "USAGE: /kick [playerid]");
}
Kick(strval(tmp));
return 1;
}
return 0;
}
if(strcmp(cmd, "/Kick", true) == 0)
{
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_RED,"Usage: /Kick [playerid]!");
new id;
id = strval(tmp);
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Invaild id!");
Kick(id);
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256];
new idx;
cmd = strtok(cmdtext, idx);
new playername[MAX_PLAYER_NAME];
new pname[18];
new target[18];
new targetid = strval(tmp);
new string[128];
new reason[128];
new ipvar1[16];
new ipvar[16];
GetPlayerName(playerid, pname, sizeof(pname));
GetPlayerName(targetid, target, sizeof(target));
if(strcmp(cmd, "/kick",true) == 0)
{
if(PlayerInfo[playerid][pAdmin] > 1)
{
new tmp[65];
tmp = strtok(cmdtext, idx);
reason = bigstrtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /kick [playerid] [reason]");
return 1;
}
if(targetid == playerid)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Selecting your Own ID might be messy");
}
else if(IsPlayerConnected(targetid) == 0)
{
SendClientMessage(playerid, COLOR_LIGHTRED, "Player is not connected");
}
else
{
GetPlayerIp(playerid, ipvar1, 16);
GetPlayerIp(targetid, ipvar, 16);
format(string, sizeof(string), "%s(%d) has been kicked by administrator %s | Reason: %s", target, targetid, pname, reason);
SendClientMessageToAll(COLOR_YELLOW, string);
format(string, sizeof(string), "You kicked %s", target);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
SendClientMessage(targetid, COLOR_LIGHTRED, "You were kicked!");
printf("%s(%d)[%d] kicked %s(%d)[%d] | Reason: %s", pname, playerid, ipvar1, target, targetid, ipvar, reason);
Kick(targetid);
}
}
}
new targetid = strval(tmp);
new targetid = strval(strtok(cmdtext, idx));
|
Originally Posted by [LorD
bAr[Sp] ]
You Most To Do every commands the var commands like tmp! you cannot do this Globlay! and i suggest you to do your Command like this: Код:
if(strcmp(cmd, "/Kick", true) == 0)
{
new tmp[256];
tmp = strtok(cmdtext, idx);
if(!strlen(tmp)) return SendClientMessage(playerid,COLOR_RED,"Usage: /Kick [playerid]!");
new id;
id = strval(tmp);
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Invaild id!");
Kick(id);
return 1;
}
|
|
Originally Posted by /^We(stie|z+[e|a
r)$/ ]
Just so you know, the maximum input and input string length is 128, which means in basically every example is wasting half of its memory on unallocated/unused cells. Because SA-MP (or rather PAWN) is event driven scripting (IE, the OnCommandText callback), you can effectively make every single variable global without the risk of the variables overwriting one another. |
if(!strcmp(cmd,"/kick",true))
{
new cmd[128];
cmd=strtok(cmdtext,idx);
if(!strlen(cmd))
return SendClientMessage(playerid,color,"usage: /kick [id]");
new id=ReturnUser(cmd);
if(!IsPlayerConnected(id))
return SendClientMessage(playerid,color,"invalid playerid");
return Kick(id);
}