Automatic unjail - Timer does not save
#1

I'm camping with this problem for a couple of days now.
I have no clue how to save a timer to the database, which is in the case y_ini.

If a player is jailed by an admin and he logs off, I want the time he has left to stay in Jail saved but I don't know how.
Like when the player logs on again the time just continues counting down.

This is what I have:

Enum pInfo
pawn Код:
enum pInfo
{
    pJailed,
    pJailTime,
}
[/PAWNO]

OnPlayerSpawn
[PAWNO]
public OnPlayerSpawn(playerid)
{
    if(PlayerInfo[playerid][pJailed] == 1)
    {
        SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
        SetPlayerInterior(playerid, 3);
        SetCameraBehindPlayer(playerid);
        SendClientMessage(playerid, COLOR_GREY, "[JAIL] You have not served your time yet!");
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        ResetPlayerWeapons(playerid);
        GameTextForPlayer(playerid, "~r~Back To Jail", 2500, 0);
        return 1;
    }
    else
    {
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        SetPlayerPos(playerid, 1685.8979/*X*/, -2330.5691/*Y*/, -2.6797/*Z*/);
        SetPlayerFacingAngle(playerid, 360.0);
        return 1;
    }
}
/jail and /unjail command
pawn Код:
CMD:jail(playerid, params[])
{
    new tID, time, reason[128], 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, "udS(No Reason)[128]", 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][pJailed] == 1) return SCM(playerid, COLOR_GREY, "[NOTE] The player you have specified 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);
        SetTimerEx("JailP1", 1000, false, "i", tID);
        SetTimerEx("Jailer", 5000, false, "i", tID);
    }
    return 1;
}
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][pJailed] == 0) return SCM(playerid, COLOR_GREY, "[NOTE] The player you have specified 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);
        SetTimerEx("Unjail", 1000, false, "i", tID);
    }
    return 1;
}
Additional publics:
pawn Код:
public Jailer(playerid)
{
    TogglePlayerControllable(playerid, 1);
    SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
    SetPlayerInterior(playerid, 3);
    SetCameraBehindPlayer(playerid);
    PlayerInfo[playerid][pJailTime] = SetTimerEx("Unjail", PlayerInfo[playerid][pJailTime], 0, "d", playerid);
    PlayerInfo[playerid][pJailed] = 1;
    SaveAccountInfo(playerid);
}
public Unjail(playerid)
{
    if(--PlayerInfo[playerid][pJailTime] < 1)
    {
        PlayerInfo[playerid][pJailTime] = 0;
        PlayerInfo[playerid][pJailed] = 0;
        SetPlayerInterior(playerid, 0);
        SetPlayerPos(playerid, 1685.8979/*X*/, -2330.5691/*Y*/, -2.6797/*Z*/);
        SetPlayerFacingAngle(playerid, 360.0);
        PlayerPlaySound(playerid, 1057, 0.0, 0.0, 0.0);
        GameTextForPlayer(playerid, "~g~Released!", 3000, 0);
    }
    return 1;
}

Help is much appreciated!

Sincerely,
Bible
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=511491

+

http://forum.sa-mp.com/showpost.php?...51&postcount=2

+

pawn Код:
public JailPlayer(playerid)
{
    KillTimer(JailTimer[playerid]);
    TogglePlayerControllable(playerid, 1);
    SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
    SetPlayerInterior(playerid, 3);
    SetCameraBehindPlayer(playerid);
    JailTimer[playerid] = SetTimerEx("JailRelease", 1000, true, "d", playerid);
    PlayerInfo[playerid][pAJailed] = 1;
}

public OnPlayerSpawn(playerid)
{
    if(PlayerInfo[playerid][pJailed] == 1)
    {
        KillTimer(JailTimer[playerid]);
        SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
        SetPlayerInterior(playerid, 3);
        SetCameraBehindPlayer(playerid);
        SendClientMessage(playerid, COLOR_GREY, "[JAIL] You have not served your time yet!");
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        ResetPlayerWeapons(playerid);
        GameTextForPlayer(playerid, "~r~Back To Jail", 2500, 0);
        JailTimer[playerid] = SetTimerEx("JailRelease", 1000, true, "d", playerid);
    }
    else
    {
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        SetPlayerPos(playerid, 1685.8979/*X*/, -2330.5691/*Y*/, -2.6797/*Z*/);
        SetPlayerFacingAngle(playerid, 360.0);
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
public JailPlayer(playerid)
{
    KillTimer(JailTimer[playerid]);
    TogglePlayerControllable(playerid, 1);
    SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
    SetPlayerInterior(playerid, 3);
    SetCameraBehindPlayer(playerid);
    JailTimer[playerid] = SetTimerEx("JailRelease", 1000, true, "d", playerid);
    PlayerInfo[playerid][pAJailed] = 1;
}

public OnPlayerSpawn(playerid)
{
    if(PlayerInfo[playerid][pJailed] == 1)
    {
        KillTimer(JailTimer[playerid]);
        SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
        SetPlayerInterior(playerid, 3);
        SetCameraBehindPlayer(playerid);
        SendClientMessage(playerid, COLOR_GREY, "[JAIL] You have not served your time yet!");
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        ResetPlayerWeapons(playerid);
        GameTextForPlayer(playerid, "~r~Back To Jail", 2500, 0);
        JailTimer[playerid] = SetTimerEx("JailRelease", 1000, true, "d", playerid);
    }
    else
    {
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        SetPlayerPos(playerid, 1685.8979/*X*/, -2330.5691/*Y*/, -2.6797/*Z*/);
        SetPlayerFacingAngle(playerid, 360.0);
    }
    return 1;
}
pawn Код:
JailTimer[playerid] = SetTimerEx("JailRelease", 1000, true, "d", playerid);
Why did you set it on "repeat"?
And how does it save?
Can you at least give me some information so I can learn something from it?
Reply
#4

its counting in Unjail public

if(--PlayerInfo[playerid][pJailTime] < 1)

so timer must be true
Reply
#5

Right, I understand.
The thing now is when I jail myself for let's say, 5 minutes. I get unjailed 1 second later.

And don't I have to save the timer in my pJailTime for when the player disconnects during his jail time?
Reply
#6

Anyone?
Jeff's code unjails the player 1 second after I jailed him.
Reply
#7

Show 'new' full code
Reply
#8

This?
pawn Код:
new JailTimer[MAX_PLAYERS];
Reply
#9

pawn Код:
enum pInfo
{
    pJailTime,
    JailTimer
}
new PlayerInfo[MAX_PLAYERS][pInfo];

INI_WriteInt(File,"AjailTime",0);   //When the player registers a new account
INI_WriteInt(File,"AjailTime",PlayerInfo[playerid][pJailTime]);      //Save to the .INI file

INI_Int("AjailTime",PlayerInfo[playerid][pJailTime]);              //Loading from the .INI file

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][pJailTime] > 0) 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][pJailTime] = time*60;
        SetTimerEx("JailPlayer", 5000, false, "d", tID);
        SetTimerEx("Jail1", 1000, false, "d", tID);
    }
    return 1;
}

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][pJailTime]  < 1) 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][pJailTime] = 1;
        JailRelease(tID);
    }
    return 1;
}

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)
{
    SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
    SetPlayerInterior(playerid, 3);
    SetCameraBehindPlayer(playerid);
    KillTimer(PlayerInfo[playerid][JailTimer]);
    PlayerInfo[playerid][JailTimer] = SetTimerEx("JailRelease", 1000, true, "d", playerid);
    TogglePlayerControllable(playerid, 1);
}

public JailRelease(playerid)
{
    if(!IsPlayerConnected(playerid))
    {
        KillTimer(PlayerInfo[playerid][JailTimer]);
        return;
    }
    if(--PlayerInfo[playerid][pJailTime] < 1)
    {
        KillTimer(PlayerInfo[playerid][JailTimer]);
        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);
    }
}

public OnPlayerSpawn(playerid)
{
    if(PlayerInfo[playerid][pJailTime] > 0)
    {
        KillTimer(PlayerInfo[playerid][JailTimer]);
        SetPlayerPos(playerid, 197.6661, 173.8179, 1003.0234);
        SetPlayerInterior(playerid, 3);
        SetCameraBehindPlayer(playerid);
        SendClientMessage(playerid, COLOR_GREY, "[JAIL] You have not served your time yet!");
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        ResetPlayerWeapons(playerid);
        GameTextForPlayer(playerid, "~r~Back To Jail", 2500, 0);
        PlayerInfo[playerid][JailTimer] = SetTimerEx("JailRelease", 1000, true, "d", playerid);
    }
    else
    {
        SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
        SetPlayerPos(playerid, 1685.8979/*X*/, -2330.5691/*Y*/, -2.6797/*Z*/);
        SetPlayerFacingAngle(playerid, 360.0);
    }
    return 1;
}
Reply
#10

EDIT:

It works perfectly.
Jeff, thanks for the many help you gave me throughout the process.

+Repped.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)