Saving a jail timer??
#1

Hello samp forums members,

Earlier i was following a tutorial by 'Twisted_Insane' [link]:https://sampforum.blast.hk/showthread.php?tid=322311

And i created the jail command just as they did. It works as it should but if somebody disconnects from the server and joins again then they will be freed from jail. What i am looking for is a way to save the jail timer so that when a player that is in jail leaves, their jail time will resume when they join again. If anyone knows how to do this i would really appreciate it.

Here is the code that i have for the jail command:

Defines,
Код:
new JailTimer[MAX_PLAYERS], //the timer for the releasing of the player from jail
bool:inJail[MAX_PLAYERS]; //this boolean-variable checks whether a play is in jail or not
The Command,
Код:
CMD:jail(playerid, params[])
    {
        if(PlayerInfo[playerid][pAdmin] >= 4)
        {
            new targetid, minutes; //define the player's name and the minutes of jailing
            if(sscanf(params, "ri", targetid, minutes)) return SendClientMessage(playerid, COLOR_RED,"Usage: /jail <playerid> <minutes>"); //detects the wrong params and show the usage
            if(minutes <= 0 || minutes > 60) return SendClientMessage(playerid, COLOR_RED, "Minutes can't be less than 0 or more than 60!"); //we won't let a player suffer more than 1 hour, and not less than 1 minute
            if(targetid == playerid) return SendClientMessage(playerid, COLOR_RED, "You can't jail yourself!"); //comment this line out, if you wanna test this command on yourself!
            if(PlayerInfo[targetid][pAdmin] > PlayerInfo[playerid][pAdmin]) return SendClientMessage(playerid, COLOR_RED, "You can't jail higher level admins!"); //the performer can't jail higher admins!
            else
            {
                new str[128]; //create a new string
                format(str, sizeof(str), "Administrator %s has jailed %s for %d minutes!", Name(playerid), Name(targetid), minutes); //get the admin's name, the player's and show the minutes
                SendClientMessageToAll(COLOR_LIGHTBLUE,str); //let everybody know what you did, this will send the message to everyone
                JailTimer[targetid] = SetTimer("Unjail", minutes*60*1000, false); //now HERE we're setting the jailtimer from the variable created, it will calculate the milliseconds to seconds, multiplicated with the amount of minutes we gave
                SetPlayerPos(targetid, 264.4176, 77.8930, 1001.0391); //Sets the player's position to the jail in LS
        SetPlayerInterior(playerid, 6); //this will set the player's interior to an jail-interior
        inJail[targetid] = true; //now, here we'll check, if the player's in jail, we'll set the value to "true", means that he IS in jail
        GameTextForPlayer(playerid, "~p~JAILED", 10000, 6); //this is for decorating and writing a big "JAILED" for the player
        PlayerPlaySound(targetid,1057,0.0,0.0,0.0); //that's also a small sound, for decoration
        }
    }
        else return SendClientMessage(playerid, COLOR_RED, "You have to be level 4 to use this command!"); //if he isn't allowed to use this command, send him this message
        return 1;
    }
Forward for jail timer,
Код:
forward Unjail(playerid);
public Unjail(playerid) //this was the name of the timer (Unjail), if you remember
{
    SpawnPlayer(playerid); //spawn the player normally again
    SetPlayerInterior(playerid, 0); //we'll set the interior to "0", which means to the normal world
    inJail[playerid] = false; //we'll set the value of the variable to "false" here, that means he isn't in jail anymore
    KillTimer(JailTimer[playerid]); //execute the timer, so it'll stop counting
    GameTextForPlayer(playerid, "~g~Unjailed", 5000, 6); //this is for decoration again, will display "UNJAILED"
    PlayerPlaySound(playerid,1057,0.0,0.0,0.0); //a smart "success-sound" again
}
The stock function,
Код:
stock PlayerName(playerid)
{
    new pName[25];
    GetPlayerName(playerid, pName, sizeof(pName));
    return pName;
}
I use DINI as my saving system if that helps at all and my Playerinfo enum is PlayerInfo[playerid][//TimerVarHere]
Reply
#2

You cannot do that unless you save the actual minutes that are left. And like, who in their right mind would sit in a four by four space for an entire hour doing absolutely nothing? Way to scare people away.
Reply
#3

Ok thanks, and 1 hour is a little crazy but i didnt make the script i would have changed it anyway
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)