PDA

View Full Version : Command works for all ID's except ID 0


HondaCBR
24/11/2011, 03:11 PM
Basically you can do /adminjail ANYID time reason, apart from /adminjail 0 time reason.
If you do it for ID 0, you get a message: SendClientMessage(playerid, COLOR_GREY, " Time needs to be between 1 and 120 min !");


if(strcmp(cmd, "/adminjail", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "Użyj: /adminjail [ID] [TIME] [REASON]");
return 1;
}
giveplayerid = ReturnUser(tmp);
if (PlayerInfo[playerid][pAdmin] >= 2000)
{
if(IsPlayerConnected(giveplayerid))
{
if(giveplayerid != INVALID_PLAYER_ID)
{
GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
new length = strlen(cmdtext);
while ((idx < length) && (cmdtext[idx] <= ' '))
{
idx++;
}

new time = strval(tmp);
if(time <= 1 || time >= 120) { SendClientMessage(playerid, COLOR_GREY, " Time needs to be between 1 and 120 min !"); return 1; }
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_GRAD2, "Użyj: /adminjail [ID] [TIME] [REASON]");
return 1;
}

new offset = idx;
new result[64];
while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
{
result[idx - offset] = cmdtext[idx];
idx++;
}
result[idx - offset] = EOS;
if(!strlen(result))
{
SendClientMessage(playerid, COLOR_GRAD2, "Użyj: /adminjail [ID] [TIME] [REASON]");
return 1;
}
format(string, sizeof(string), "USER: %s has been taken in to Admin Jail by admin: %s. For %d min. Reason: %s ", giveplayer, sendername, time, (result));
SendClientMessageToAll(COLOR_LIGHTRED, string);

SetPlayerPos(giveplayerid,1478.5525,-1365.3551,125.9121);
SetPlayerFacingAngle(giveplayerid, 90);
PlayerInfo[giveplayerid][pAJTime] = time * 60;
PlayerInfo[giveplayerid][pAJ] = 1;

return 1;
}
}
}
else
{
format(string, sizeof(string), "%d is not active.", giveplayerid);
SendClientMessage(playerid, COLOR_GRAD1, string);
}
}
return 1;
}

MP2
24/11/2011, 03:42 PM
Players can't type commands if they aren't on the server; IsPlayerConnected is unnecessary.

Use sscanf.

HondaCBR
24/11/2011, 07:58 PM
it doesnt matter about isplayerconnected im on about id 0, you cant put id 0 in jail it comes up that the time needs to be betwin 1 and 120, it doesnt matter what time you choose

Vince
24/11/2011, 08:00 PM
new time = strval(tmp);
At this point, the target playerid is still stored in this variable. As said, use sscanf to make these kind of commands with ease.

HondaCBR
24/11/2011, 08:12 PM
could you just edit mine command so it works for all ID's?