05.05.2014, 20:18
Hello folks
I'm trying to make an admin jail command where the admin can choose how long the player has to sit in jail.
After the time expires, the player should get unjailed (The time remaining continues ONLY when the player is in game).
The thing is, I can't seem to find how to save the time remaining..
This is my command and all the additional publics and new's:
Forwards:
New variables:
enum pInfo:
Saving to .ini when the player registers a new account:
Saving the .ini file
Loading from the .ini file
/jail command
/unjail command
Publics:
Help is much appreciated!
Sincerely
Bible
I'm trying to make an admin jail command where the admin can choose how long the player has to sit in jail.
After the time expires, the player should get unjailed (The time remaining continues ONLY when the player is in game).
The thing is, I can't seem to find how to save the time remaining..
This is my command and all the additional publics and new's:
Forwards:
pawn Code:
forward Jail1(playerid);
forward Jail2(playerid);
forward Jail3(playerid);
forward JailPlayer(playerid);
forward JailRelease(playerid);
pawn Code:
new JailTimer[MAX_PLAYERS];
new JailTime[MAX_PLAYERS];
pawn Code:
enum pInfo
{
pAJailed,
pAJailTime,
}
pawn Code:
INI_WriteInt(File,"Ajailed",0); //When the player registers a new account
INI_WriteInt(File,"AjailTime",0); //When the player registers a new account
pawn Code:
INI_WriteInt(File,"Ajailed", PlayerInfo[playerid][pAJailed]); //Save to the .INI file
INI_WriteInt(File,"AjailTime", PlayerInfo[playerid][pAJailTime]); //Save to the .INI file
pawn Code:
INI_Int("Ajailed", PlayerInfo[playerid][pAJailed]); //Loading from the .INI file
INI_Int("AjailTime", PlayerInfo[playerid][pAJailTime]); //Loading from the .INI file
pawn Code:
CMD:jail(playerid, params[])
{
new tID, time, reason[48], jstring[128];
if(!gPlayerLogged[playerid]) return SCM(playerid, COLOR_GREY, NOTLOGGED);
if(PlayerInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_GREY, NOTADMIN);
if(sscanf(params, "uD(9999)S(No Reason)[48]", tID, time, reason)) return SCM(playerid, -1, "[USAGE] /jail [playerid/PartOfName] [Minutes] [Reason]");
else if(tID == INVALID_PLAYER_ID) return SCM(playerid, COLOR_GREY, INVALIDID);
else if(PlayerInfo[tID][pAdmin] > PlayerInfo[playerid][pAdmin]) return SCM(playerid, COLOR_GREY, "[AdmCMD] You can't jail admins who are a higher level than you!");
else if(PlayerInfo[tID][pAJailed] == 1) return SCM(playerid, COLOR_GREY, "[AdmCMD] This player is already in jail!");
else
{
format(jstring, sizeof(jstring), "[AdmCMD] %s has been jailed by Administrator %s for %d minute(s), [Reason: %s]", GetName(tID), GetName(playerid), time, reason);
SCMTA(COLOR_LIGHTRED, jstring);
PlayerInfo[tID][pAJailTime] = time*1000*60;
SetTimerEx("JailPlayer", 5000, false, "d", tID);
SetTimerEx("Jail1", 1000, false, "d", tID);
JailTime[tID] = time*60;
}
return 1;
}
pawn Code:
CMD:unjail(playerid, params[])
{
new tID, jstring[128];
if(!gPlayerLogged[playerid]) return SCM(playerid, COLOR_GREY, NOTLOGGED);
if(PlayerInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_GREY, NOTADMIN);
if(sscanf(params, "u", tID)) return SCM(playerid, -1, "[USAGE] /unjail [playerid/PartOfName]");
else if(tID == INVALID_PLAYER_ID) return SCM(playerid, COLOR_GREY, INVALIDID);
else if(PlayerInfo[tID][pAdmin] > PlayerInfo[playerid][pAdmin]) return SCM(playerid, COLOR_GREY, "[AdmCMD] You can't unjail admins who are a higher level than you!");
else if(PlayerInfo[tID][pAJailed] == 0) return SCM(playerid, COLOR_GREY, "[AdmCMD] This player is not in jail!");
else
{
format(jstring, sizeof(jstring), "[AdmCMD] %s has been unjailed by Administrator %s", GetName(tID), GetName(playerid));
SCMTA(COLOR_LIGHTRED, jstring);
PlayerInfo[tID][pAJailed] = 0;
PlayerInfo[tID][pAJailTime] = 0;
JailRelease(tID);
}
return 1;
}
Publics:
pawn Code:
public Jail1(playerid)
{
TogglePlayerControllable(playerid, 0);
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerCameraPos(playerid, x+10, y, z+10);
SetPlayerCameraLookAt(playerid, x, y, z);
SetTimerEx("Jail2", 1000, false, "d", playerid);
}
public Jail2(playerid)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerCameraPos(playerid, x+7, y, z+5);
SetPlayerCameraLookAt(playerid, x, y, z);
if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
SetPlayerSpecialAction(playerid, SPECIAL_ACTION_HANDSUP);
}
GameTextForPlayer(playerid, "~r~Admin Jailed!", 3000, 0);
SetTimerEx("Jail3", 1000, false, "d", playerid);
}
public Jail3(playerid)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerCameraPos(playerid, x+3, y, z);
SetPlayerCameraLookAt(playerid, x, y, z);
}
public JailPlayer(playerid)
{
TogglePlayerControllable(playerid, 1);
SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
SetPlayerInterior(playerid, 3);
SetCameraBehindPlayer(playerid);
JailTimer[playerid] = SetTimerEx("JailRelease", PlayerInfo[playerid][pAJailTime], 0, "d", playerid);
PlayerInfo[playerid][pAJailed] = 1;
}
public JailRelease(playerid)
{
KillTimer(JailTimer[playerid]);
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, 0.0, 0.0, 0.0);
SpawnPlayer(playerid);
PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
GameTextForPlayer(playerid, "~g~Released!", 3000, 0);
}
Sincerely
Bible