SA-MP Forums Archive
Jail system - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Jail system (/showthread.php?tid=465725)



Jail system - Isolated - 23.09.2013

Hello,

I'm working on a jail system which doesn't allow players to quit during the time of there jail. However, for some reason my function SendPlayerToJail doesn't work correctly, I've tried tickcount, gettickcount and gettime, could someone please have a look? When switching operators, the code is rather ineffective or, releases the player immediately, I do have debug results if anyone needs to see them.

pawn Код:
public SendPlayerToJail(playerid, seconds)
{
    TogglePlayerControllable(playerid, 0);
    new rand = random(3);
    switch(rand)
    {
        case 0: SetPlayerPos(playerid, 262.9825,77.4500,1001.0391);
        case 1: SetPlayerPos(playerid, 193.6294,161.8236,1003.2417);
        case 2: SetPlayerPos(playerid, 190.8504,161.0375,1003.2417);
    }
    SetPlayerInterior(playerid, 7);
    GameTextForPlayer(playerid, "~r~JAILED", 3000, 6);
    PlayerInfo[playerid][pJailed] = 1;
    PlayerInfo[playerid][pJailSeconds] = gettime()+seconds;
    print(PlayerInfo[playerid][pJailSeconds]);
    new String[70];
    format(String, sizeof(String), "%s (ID: %d) has been jailed.", ReturnPlayerName(playerid), playerid);
    SendClientMessageToAll(COLOR_YELLOW, String);
    TogglePlayerControllable(playerid, 1);
    return 1;
}
pawn Код:
public OnPlayerUpdate(playerid)
{
    if(PlayerInfo[playerid][pJailed] == 1)
    {
        printf("Player Jailed, time remaining: %d", PlayerInfo[playerid][pJailSeconds]);
        if(gettime() - PlayerInfo[playerid][pJailSeconds] < PlayerInfo[playerid][pJailSeconds])
        {
            ReleasePlayer(playerid);
            print("Releasing Player\n");
            return 1;
        }
    }
    return 1;
}

Thanks in advance.


Re: Jail system - Vrag - 23.09.2013

Nice +REP


Re: Jail system - Isolated - 23.09.2013

So you obviously didn't read this thread. Seeing as you rep+ me for a "damn good" jail system. Please read before post/rep whoring.


Re: Jail system - Dragonsaurus - 23.09.2013

Instead of gettime() use GetTickCount().
And multiply the seconds variable with 1000.
Note: You were also using gettime() wrong. It needs three parameters as far as I know.


Re: Jail system - Isolated - 23.09.2013

I've tried GetTickCount.


Re: Jail system - Dragonsaurus - 23.09.2013

Quote:
Originally Posted by Dragonsaurus
Посмотреть сообщение
And multiply the seconds variable with 1000.
What about this?
Edit: Here is the script:
pawn Код:
public SendPlayerToJail(playerid, seconds)
{
    TogglePlayerControllable(playerid, 0);
    new rand = random(3);
    switch(rand)
    {
        case 0: SetPlayerPos(playerid, 262.9825,77.4500,1001.0391);
        case 1: SetPlayerPos(playerid, 193.6294,161.8236,1003.2417);
        case 2: SetPlayerPos(playerid, 190.8504,161.0375,1003.2417);
    }
    SetPlayerInterior(playerid, 7);
    GameTextForPlayer(playerid, "~r~JAILED", 3000, 6);
    PlayerInfo[playerid][pJailed] = 1;
    PlayerInfo[playerid][pJailSeconds] = seconds * 1000;
    print(PlayerInfo[playerid][pJailSeconds]);
    new String[70];
    format(String, sizeof(String), "%s (ID: %d) has been jailed.", ReturnPlayerName(playerid), playerid);
    SendClientMessageToAll(COLOR_YELLOW, String);
    TogglePlayerControllable(playerid, 1);
    SetTimerEx("UnjailPlayer", PlayerInfo[playerid][pJailSeconds], false, "d", playerid);
    return 1;
}
forward UnjailPlayer(playerid);
public UnjailPlayer(playerid)
{
    ReleasePlayer(playerid);
    return 1;
}



Re: Jail system - Isolated - 23.09.2013

I'm avoiding timers completely within my script.


Re: Jail system - Isolated - 24.09.2013

bump.


Re: Jail system - RajatPawar - 24.09.2013

pawn Код:
public SendPlayerToJail(playerid, seconds)
{
    new name[24]; GetPlayerName(playerid, name, 24);
    printf("%s (%d) player has been jailed for %d seconds.", name, playerid, seconds);
    new rand = random(3);
    printf("Random is %d.", rand);
    switch(rand)
    {
        case 0:{ SetPlayerPos(playerid, 262.9825,77.4500,1001.0391); print("Case 0 selected."); }
        case 1:{ SetPlayerPos(playerid, 193.6294,161.8236,1003.2417); print("Case 1 selected."); }
        case 2:{ SetPlayerPos(playerid, 190.8504,161.0375,1003.2417); print("Case 2 selected."); }
    }
    SetPlayerInterior(playerid, 7);
    GameTextForPlayer(playerid, "~r~JAILED", 3000, 6);
    PlayerInfo[playerid][pJailed] = 1;
    PlayerInfo[playerid][pJailSeconds] = gettime()+ seconds;
    printf("Player jailed status: %d", PlayerInfo[playerid][pJailed]);
    printf("Player jailed time: %d seconds", PlayerInfo[playerid][pJailSeconds]);
    new String[70];
    format(String, sizeof(String), "%s (ID: %d) has been jailed.", ReturnPlayerName(playerid), playerid);
    SendClientMessageToAll(COLOR_YELLOW, String);
    return 1;
}

public OnPlayerUpdate(playerid)
{
    if(PlayerInfo[playerid][pJailed] == 1)
    {
        new CURR_time = gettime();
        if(CURR_time > PlayerInfo[playerid][pJailedSeconds])
        {
            ReleasePlayer(playerid);
            print("Releasing Player\n");
            return 1;
        }
    }
    return 1;
}
Seems to work? Please let me know! Whatever reason you have for not using timers, OPU really sucks for this type of checking.


Re: Jail system - Isolated - 24.09.2013

You are my hero sir, this worked perfectly with a minor change.