Problem with /ban - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with /ban (
/showthread.php?tid=253501)
Problem with /ban -
BizzyD - 06.05.2011
Hello, I got a problem with my /ban cmd. When i do /ban, And dont write a name/id and a reason.
It says: 65923(Some Random Number) Is not a active player.
This is my /ban cmd!
pawn Код:
CMD:ban(playerid,params[])
{
new string[128];
new sendername[MAX_PLAYER_NAME];
new tmp[256];
new idx;
new giveplayerid;
new giveplayer[MAX_PLAYER_NAME];
if(IsPlayerConnected(playerid))
{
tmp = strtok(params, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, RED, "[LOST:RP] /ban [ID] [REASON]");
return 1;
}
giveplayerid = ReturnUser(tmp);
if(IsPlayerNPC(giveplayerid)) return 1;
if(PlayerInfo[playerid][pAdmin] >= 2)
{
if(IsPlayerConnected(giveplayerid))
{
if(giveplayerid != INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(params);
while ((idx < length) && (params[idx] <= ' '))
{
idx++;
}
new offset = idx;
new result[96];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = params[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, RED, "[LOST:RP] /ban [ID] [REASON]");
return 1;
}
format(string, 128, "[LOST:RP] [ADMIN]: %s has banned %s! Reason: %s", sendername, giveplayer, (result));
SendClientMessageToAll(RED, string);
Ban(giveplayerid);
new Hour, Minute, Second;
gettime(Hour, Minute, Second);
format(string,sizeof(string),"[%02d:%02d:%02d]%s has banned %s! Reason:%s",Hour,Minute,Second,sendername,giveplayer, (result));
SaveIn("BanLog.txt",string);
}
}
else
{
format(string, sizeof(string), "[LOST:RP] %d is not a active player", giveplayerid);
SendClientMessage(playerid, RED, string);
}
}
else
{
SendClientMessage(playerid, RED, "[LOST:RP] You are not a admin, Or you are a to low one");
}
}
return 1;
}
How can i fix this?
Regards, Alex
EDIT: This is what happends:
Re: Problem with /ban -
Calgon - 06.05.2011
You shouldn't be using strtok in zcmd.
pawn Код:
CMD:ban(playerid, params[]) {
new
giveplayerid,
szReason[32];
if(sscanf(params, "us[32]", giveplayerid, szReason))
return SendClientMessage(playerid, -1, "Syntax: /ban [playerid] [reason]");
if(IsPlayerNPC(giveplayerid))
return 1;
if(PlayerInfo[playerid][pAdmin] >= 2) {
if(giveplayerid != INVALID_PLAYER_ID) {
new
sendername[MAX_PLAYER_NAME],
string[128],
giveplayer[MAX_PLAYER_NAME];
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, 128, "[LOST:RP] [ADMIN]: %s has banned %s! Reason: %s", sendername, giveplayer, szReason);
SendClientMessageToAll(RED, string);
Ban(giveplayerid);
new Hour, Minute, Second;
gettime(Hour, Minute, Second);
format(string,sizeof(string),"[%02d:%02d:%02d]%s has banned %s! Reason:%s",Hour,Minute,Second,sendername,giveplayer, szReason);
SaveIn("BanLog.txt",string);
}
}
return 1;
}
Untested.
Re: Problem with /ban -
Vince - 06.05.2011
65535 = 0xFFFF = INVALID_PLAYER_ID. Just so you know ..
pawn Код:
#define INVALID_PLAYER_ID (0xFFFF)
Re: Problem with /ban -
BizzyD - 06.05.2011
works :P Thanks