YCMD help with /jail command
#1

As title say's i did jail command with unjail timer all is saved. Problem is after i jail for test 1 minute timer wont unjail me.

pawn Код:
YCMD:jail(playerid, params[],help)
{
    new targetid, timer,reason[64],string[512];
    if(!(PlayerInfo[playerid][pFaction] == 1)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You are not authorized to use this command!");
    if(!(IsPlayerInRangeOfPoint(playerid, 15.0, 1492.7723,-1763.2980,3285.2859))) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You must be in LSPD cell area to jail somewone!");
    if(playerid == targetid) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot jail yourself!");
    {
        if(sscanf(params, "uds[64]",targetid, timer, reason)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /jail [ID] [Minutes] [Reason]");
        {
            new str[512];
            format(str,sizeof str,"You were jailed by: %s for: %i minute(s), reason: %s",GetName(playerid),timer,reason);
            SendClientMessage(targetid,COLOR_RED,str);
            format(str,sizeof str,"You jailed : %s for: %i minute(s), reason: %s",GetName(targetid),timer,reason);
            SendClientMessage(playerid,COLOR_BLUE,str);
            ResetPlayerWeapons(targetid);
            GivePlayerMoney(targetid, -5000);
            GivePlayerMoney(playerid, 5000);
            format(string, sizeof(string), "You have earned $5000 for your hard work.",string);
            ShowDescriptionText(playerid, string);
            PlayerInfo[targetid][pJailed] = 1;
            PlayerInfo[targetid][pJailTime] = timer*1000;
            unjailtimer[targetid]= SetTimerEx("UnJail",PlayerInfo[targetid][pJailTime]*60,false,"d",targetid);
            SavePlayer(targetid);
            return 1;
        }
    }
}




forward UnJail(playerid);
public UnJail(playerid)
{
    if(PlayerInfo[playerid][pJailTime] == 0)
    {
        KillTimer(unjailtimer[playerid]);
        SetPlayerInterior(playerid, 0);
        SetPlayerVirtualWorld(playerid, 0);
        SetPlayerPos(playerid, 1552.6873,-1673.5428,16.1953);
        SendClientMessage(playerid, 0xFF0000AA, "You Have Been Released From Jail!");
        PlayerInfo[playerid][pJailed] = 0;
        PlayerInfo[playerid][pJailTime] = 0;
        SavePlayer(playerid);
    }
    return 1;
}
And when player connects again timer is started again
pawn Код:
if(PlayerInfo[playerid][pJailed] == 1)
        {
        new string[512];
        unjailtimer[playerid]= SetTimerEx("UnJail",PlayerInfo[playerid][pJailTime]*60,false,"d",playerid);
        format(string, sizeof(string), "You didn't serve your sentence.Returning you back to the jail.",string);
        ShowDescriptionText(playerid, string);
        }
So how to fix the timer so it release jailed player when jail time is done...
Reply
#2

still need help with this....
Reply
#3

Why
pawn Код:
unjailtimer[targetid]= SetTimerEx("UnJail",PlayerInfo[targetid][pJailTime]*60,false,"d",targetid);
Why not
pawn Код:
SetTimerEx("UnJail",PlayerInfo[targetid][pJailTime]*60,false,"d",targetid);
The timer kills itself.

EDIT:
pawn Код:
if(PlayerInfo[playerid][pJailTime] == 0)                // HERE YOU CHECK IF IT'S 0
    {
        KillTimer(unjailtimer[playerid]);
        SetPlayerInterior(playerid, 0);
        SetPlayerVirtualWorld(playerid, 0);
        SetPlayerPos(playerid, 1552.6873,-1673.5428,16.1953);
        SendClientMessage(playerid, 0xFF0000AA, "You Have Been Released From Jail!");
        PlayerInfo[playerid][pJailed] = 0;
        PlayerInfo[playerid][pJailTime] = 0;                // HERE YOU SET IT TO 0...
        SavePlayer(playerid);
    }
The player JailTime cannot be 0 because you set to 0 after the condition, so it won't take you out of jail.
Reply
#4

pawn Код:
YCMD:jail(playerid, params[],help)
{
    new targetid, timer,reason[64];
    if(!(PlayerInfo[playerid][pFaction] == 1)) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You are not authorized to use this command!");
    if(!(IsPlayerInRangeOfPoint(playerid, 15.0, 1492.7723,-1763.2980,3285.2859))) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You must be in LSPD cell area to jail somewone!");
    if(playerid == targetid) return SendClientMessage(playerid, 0xFF0000FF, "ERROR: You cannot jail yourself!");
    {
        if(sscanf(params, "uds[64]",targetid, timer, reason)) return SendClientMessage(playerid, COLOR_RED, "USAGE: /jail [ID] [Minutes] [Reason]");
        {
            new str[512];
            format(str,sizeof str,"You were jailed by: %s for: %i minute(s), reason: %s",GetName(playerid),timer,reason);
            SendClientMessage(targetid,COLOR_RED,str);
            format(str,sizeof str,"You jailed : %s for: %i minute(s), reason: %s",GetName(targetid),timer,reason);
            SendClientMessage(playerid,COLOR_BLUE,str);
            ResetPlayerWeapons(targetid);
            GivePlayerMoney(targetid, -5000);
            GivePlayerMoney(playerid, 5000);
            ShowDescriptionText(playerid, "You have earned $5000 for your hard work.");
            PlayerInfo[targetid][pJailed] = 1;
            PlayerInfo[targetid][pJailTime] = timer*60000;
            SetTimerEx("UnJail",PlayerInfo[targetid][pJailTime],false,"i",targetid);
            SavePlayer(targetid);
            return 1;
        }
    }
}

forward UnJail(playerid);
public UnJail(playerid)
{
    SetPlayerInterior(playerid, 0);
    SetPlayerVirtualWorld(playerid, 0);
    SetPlayerPos(playerid, 1552.6873,-1673.5428,16.1953);
    SendClientMessage(playerid, 0xFF0000AA, "You Have Been Released From Jail!");
    PlayerInfo[playerid][pJailed] = 0;
    PlayerInfo[playerid][pJailTime] = 0;
    SavePlayer(playerid);
    return 1;
}
JailTime was not being reduced anywhere in this code, so how would it be possible to get JailTime from 1000 to 0 for example, when there is nothing being taken from JailTime, therefore making it impossible to reach 0 for JailTime.

"The player JailTime cannot be 0 because you set to 0 after the condition, so it won't take you out of jail."
That doesn't really make sense, because setting it to 0 after the condition has nothing to do with the condition not working. The fact that JailTime can never be 0, or the condition can never be met is the reason.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)