forward AjailCount(playerid);
public AjailCount(playerid)
{
if(pInfo[playerid][pJailed] != 0)
{
pInfo[playerid][pJailed]--;
if(pInfo[playerid][pJailed] == 0)
{
SendClientMessage(playerid, COLOR_RED, "Your time in Ajail is over..");
SetPlayerInterior(playerid, 0);//You can change interior
SetPlayerVirtualWorld(playerid, 0); //You can change virtual world
SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
}
}
return 1;
}
CMD:ajail(playerid, params[])
{
new targetid, time, reason[64];
new string[128], adminname[64], targetname[64];
if(pInfo[playerid][pAdminLevel] < 1) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not Admin");
if(sscanf(params, "uds[64]", targetid, time, reason)) return SendClientMessage(playerid, -1, "USAGE: /ajail <playerid> <time> <reason>");
if(time == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: Minimum 1 minute !");
GetPlayerName(targetid, targetname, MAX_PLAYER_NAME);
GetPlayerName(playerid, adminname, MAX_PLAYER_NAME);
pInfo[playerid][pJailed] = 1;
SetPlayerPos(targetid, 346.870025, 309.259033, 999.155700);
SetPlayerVirtualWorld(targetid, 2);
SetPlayerInterior(targetid,6);
pInfo[playerid][pJailed] = time;
format(string, sizeof(string), "Administrator %s ajailed %s for %d minutes. Reason: %s", adminname, targetname, time, reason);
SendClientMessageToAll(COLOR_RED, string);
playertimer[targetid] = SetTimerEx("AjailCount", 60000, 1, "i", playerid);
return 1;
}
CMD:unjail(playerid, params[])
{
new targetid, string[128], adminname[64], targetname[64];
if(pInfo[playerid][pAdminLevel] < 1) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not admin!");
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE: /unajail <playerid>");
if(pInfo[targetid][pJailed] == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player not in ajail right now!");
GetPlayerName(playerid, adminname, MAX_PLAYER_NAME);
GetPlayerName(targetid, targetname, MAX_PLAYER_NAME);
format(string, sizeof(string), "Administrator %s took %s out of Admin Jail.", adminname, targetname);
SendClientMessage(targetid,-1,string);
SendMessageToAllAdmins(string, -1);
SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
pInfo[playerid][pJailed] = 0;
return 1;
}
|
Why do you create your arrays/strings before checking for the admin stuff and the syntax (sscanf)?
You're wasting a lot of memory if the command returns something before even using them... |
|
Try using this system in seconds instead of using minutes.
And also don't forget to kill the timer in AjailCount function. |
public AjailCount(playerid)
{
if(pInfo[playerid][pJailed] != 0)
{
pInfo[playerid][pJailed]--;
if(pInfo[playerid][pJailed] == 0)
{
KillTimer(playertimer[playerid]);
SendClientMessage(playerid, COLOR_RED, "Your time in Ajail is over..");
SetPlayerInterior(playerid, 0);//You can change interior
SetPlayerVirtualWorld(playerid, 0); //You can change virtual world
SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
}
}
return 1;
}
CMD:unjail(playerid, params[])
{
new targetid, string[128], adminname[64], targetname[64];
if(pInfo[playerid][pAdminLevel] < 1) return SendClientMessage(playerid, COLOR_RED, "ERROR: You are not admin!");
if(sscanf(params, "u", targetid)) return SendClientMessage(playerid, -1, "USAGE: /unajail <playerid>");
if(pInfo[targetid][pJailed] == 0) return SendClientMessage(playerid, COLOR_RED, "ERROR: Player not in ajail right now!");
GetPlayerName(playerid, adminname, MAX_PLAYER_NAME);
GetPlayerName(targetid, targetname, MAX_PLAYER_NAME);
format(string, sizeof(string), "Administrator %s took %s out of Admin Jail.", adminname, targetname);
SendClientMessage(targetid,-1,string);
SendMessageToAllAdmins(string, -1);
KillTimer(playertimer[targetid]);
SetPlayerPos(playerid, 1529.6,-1691.2,13.3);
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
pInfo[playerid][pJailed] = 0;
return 1;
}
|
Correct me if I am wrong, but wouldn't the local variables get destroyed once the function exits returning a value? Even tho I do the same as you just stated. But just wondering, because there are some people who use if-else instead of directly returning error/syntax in the command and I doubt they have any memory problem with it.
|
if (!IsPlayerAdmin(playerid))
return SendClientMessage(...);
new string[64];
format(string...);
or
if (!IsPlayerAdmin(playerid))
{
SendClientMessage(...);
}
else
{
new string[64];
format(string...);
}
new sting[64];
if (!IsPlayerAdmin(playerid))
return SendClientMessage(...);
format(string...);
or
new string[64];
if (!IsPlayerAdmin(playerid))
{
SendClientMessage(...);
}
else
{
format(string...);
}
|
Because, you used [pJailed] to hold the jail time. Look at your code again, first you are setting it's value to 1 then again setting the jail's time in it.
Plus, you do not really need to set it's value to either 0 or 1 to indicate that the player is jailed. Just simply check with a logic: If the time value that it holds is higher than 0, player is still in jail. If the value is 0 then the player is not jailed. Simple. I would recommend you to use gettime() instead of timer if you are not showing the estimated jail time in a textdraw/gametext. |