I need some help with GameTextForPlayer
#1

I need help to show a message to the player about how long time they have left in jail..
Reply
#2

Well, Best way to do this is set a variable of "secondsleft" and start a timer to tick every second, reduce timeleft by 1 and then display the text:

Simple example:
pawn Код:
jailPlayer(playerid, jailtime) {
    if (jailtime <=0) //Can't jail them for <= 0 seconds
        return 0;

    if (GetPVarInt(playerid, "plJailTime") > 0) //Already in jail
        return 0;
       
    KillTimer(GetPVarInt(playerid, "plJailTimer")); //Kill the timer, just in case its still going
   
    // Code to move them to jail here!
   
    SetPVarInt(playerid, "plJailTime", jailtime);
    SetPVarInt(playerid, "plJailTimer", SetTimerEx("jailPlayerTimer", 1000, false, "i", playerid));
}

unjailPlayer(playerid) {
    SetPVarInt(playerid, "plJailTime", 0);
    KillTimer(GetPVarInt(playerid, "plJailTimer"));

    // Code to move them out of jail here!
}

forward jailPlayerTimer(playerid);
public jailPlayerTimer(playerid) {
    new jailTime = GetPVarInt(playerid, "plJailTime");
    if (jailTime > 0) {
       
        new msg[64];
        format(msg, 64, "You are in jail for %i seconds", jailTime);
        GameTextForPlayer(playerid, msg, 1200, 4);
       
        SetPVarInt(playerid, "plJailTime", jailTime-1);
       
        KillTimer(GetPVarInt(playerid, "plJailTimer"));
        SetPVarInt(playerid, "plJailTimer", SetTimerEx("jailPlayerTimer", 1000, false, "i", playerid));
    } else {
        unjailPlayer(playerid);
    }
}


public OnPlayerDisconnect(playerid, reason) {
    KillTimer(GetPVarInt(playerid, "plJailTimer")); //Kill the timer, just incase its still going
    return 1;
}
I have not tested this, but should work
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)