Help with jail time, and jail save
#1

Hey
I am creating a jail command now, and i need some help.
I have created the command, and everything and it work just fine. But...
When i quit the game in jail, and return back i go back in to the jail.
That's fine as well, but i stay in jail forever. The save/spawn is bad, and i tried for like 4 hours to fix it...

OnPlayerSpawn
pawn Код:
IfJail[playerid] = dini_Int(file, "Jail");
    }
    if(IfJail[playerid] == 1)
        {
            new randomcell = random(sizeof(jailcell));
            SetPlayerPos(playerid, jailcell[randomcell][0], jailcell[randomcell][1], jailcell[randomcell][2]);
            SetPlayerInterior(playerid, 10);
            SendClientMessage(playerid, COLOR_RED, "*-SFPD-* {FFFFFF}Still jailtime left{FF0000} *-SFPD-*");
            SetTimerEx("UnJail",JailTime[playerid]*1000*60,false,"d",playerid);
        }
OnPlayerDisconnect
pawn Код:
if(JailTime[playerid]!=0)
    {
        new file[128], pname[MAX_PLAYER_NAME];
        GetPlayerName(playerid, pname, sizeof(pname));
        format(file, sizeof(file), "\\save\\%s.ini", pname);
        if(!dini_Exists(file))
        dini_Create(file);
        dini_IntSet(file, "JailTime", JailTime[playerid]);
    }
Command, and the forward
pawn Код:
COMMAND:jailplayer(playerid, params[])
{
    if(gTeam[playerid] == TEAM_PD)
    {
        new targetid;
        new timer;
        new reason[25];
        if(sscanf(params, "uns",targetid, timer, reason)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /jailplayer [ID] [Min] [Reason]");
        {
            new str[512];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(playerid, name, sizeof(name));
            new target[MAX_PLAYER_NAME];
            GetPlayerName(targetid, target, sizeof(target));
            format(str,sizeof str,"You were jailed by: %s for: %i minute(s), reason: %s",name,timer,reason);
            SendClientMessage(targetid,COLOR_RED,str);
            format(str,sizeof str,"You jailed : %s for: %i minute(s), reason: %s",target,timer,reason);
            SendClientMessage(playerid,COLOR_PDBLUE,str);
            new randomcell = random(sizeof(jailcell));
            SetPlayerPos(targetid, jailcell[randomcell][0], jailcell[randomcell][1], jailcell[randomcell][2]);
            SetPlayerInterior(targetid, 10);
            IfJail[targetid] = 1;
            JailTime[targetid] = SetTimerEx("UnJail",timer*1000*60,false,"d",targetid);
            return 1;
        }
    }
    else SendClientMessage(playerid, COLOR_ERROR, "Your are not outside jail.");
    return 1;
}

forward UnJail(targetid);
public UnJail(targetid)
{
    JailTime[targetid]--;
    if(JailTime[targetid] == 0)
    {
        KillTimer(JailTime[targetid]);
        SetPlayerPos(targetid,217.8000,115.4000,999.0);
        SendClientMessage(targetid, 0xFF0000AA, "You Have Ben Released From Jail!");
        IfJail[targetid] = 0;
        JailTime[targetid] = 0;
    }
    return 1;
}
Thanks!
Reply
#2

Do you want in OnPlayerDisconnect not to save the jail and on the rejoin, spawn a player normal and not inside the jail? Then, in OnPlayerDisconnect set to
pawn Код:
IfJail[targetid] = 0;
save the data and kill timer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)