Timer / Textdraw bug
#1

Okay, so basically, when the player gets arrested 2 timers start, the UnJail timer (working) and the Text draw timer showing time left (semi-working)
The JailTime timer counts down from 30 sucesfully but when it reaches 1 the text draw doesnt hide and it stays at "time remaining: 1"
then when the next player is arrested it shows the timer for the previous arrest player but the timer is going faster. it counts down from 30, id say about in 10-15 seconds.

pawn Код:
SetTimerEx("JailTimer", 999, true, "i", targetid);
pawn Код:
public JailTimer(targetid)
{
    jailtime--;
    if(jailtime > 0 && jailed[targetid] == 1)
    {
        new string[10];
        format(string,sizeof(string), "%i", jailtime);
        TextDrawSetString(JailTime[1], string);
        TextDrawShowForPlayer(targetid, JailTime[0]); //message saying Time Remaining
        TextDrawShowForPlayer(targetid, JailTime[1]); //the actual time being shown
    }
    else if (jailtime == 0)
    {
        TextDrawHideForPlayer(targetid, JailTime[0]);
        TextDrawHideForPlayer(targetid, JailTime[1]);
    }
    return 1;
}
Reply
#2

pawn Код:
JailTimer[targetid] = SetTimerEx("JailTimer", 999, true, "i", targetid);//timer wherever you place it in your gamemode.
pawn Код:
public JailTimer(targetid)
{
    jailtime--;
    if(jailtime > 0 && jailed[targetid] == 1)
    {
        new string[10];
        format(string,sizeof(string), "%i", jailtime);
        TextDrawSetString(JailTime[1], string);
        TextDrawShowForPlayer(targetid, JailTime[0]); //message saying Time Remaining
        TextDrawShowForPlayer(targetid, JailTime[1]); //the actual time being shown
    }
    else if (jailtime == 0)
    {
        TextDrawHideForPlayer(targetid, JailTime[0]);
        TextDrawHideForPlayer(targetid, JailTime[1]);
        KillTimer(JailTimer[targetid]);//killing the timer when the jailtime reaches 0
        jailed[targetid] = 0;//saying that the player has been unjailed
    }
    return 1;
}
You need to give the timer an ID and kill it when the jail time reaches 0 so it stops decrementing. Also you would want to set the "jailed" variable to it's null value (0 I assume) to say that he's out of jail.
Reply
#3

pawn Код:
(3016) : error 028: invalid subscript (not an array or too many subscripts): "JailTimer"
(3016) : warning 215: expression has no effect
(3016) : error 001: expected token: ";", but found "]"
(3016) : error 029: invalid expression, assumed zero
(3016) : fatal error 107: too many error messages on one line
3016
pawn Код:
KillTimer(JailTimer[targetid]);
is [targetid] really needed in JailTimer[targetid] ? If it doesnt have targetid will it kill the timer for everyone in jail?
Reply
#4

Yes. You need to put [MAX_PLAYERS] after 'new JailTimer;'.
Reply
#5

Quote:
Originally Posted by SnG.Scot_MisCuDI
Посмотреть сообщение
pawn Код:
(3016) : error 028: invalid subscript (not an array or too many subscripts): "JailTimer"
(3016) : warning 215: expression has no effect
(3016) : error 001: expected token: ";", but found "]"
(3016) : error 029: invalid expression, assumed zero
(3016) : fatal error 107: too many error messages on one line
3016
pawn Код:
KillTimer(JailTimer[targetid]);
is [targetid] really needed in JailTimer[targetid] ? If it doesnt have targetid will it kill the timer for everyone in jail?
Yes, seeing that you want to create the timer for an individual player and not one player, you'd have to make the variable an array. So it would be "new JailTimer[MAX_PLAYERS];" as MP2 said.
Reply
#6

forward JailTimer(targetid);

i cant add it after that so i made a new Jail;
and did Jail[targetid] = CreateTimerEx(...)
and KillTimer(Jail[targetid]

Thats the same right?
Reply
#7

it's new JailTimer[MAX_PLAYERS]; not new JailTimer(targetid); and it has to be on the top of your script.
Reply
#8

Sorry, I forgot to mention that the function's name and variable name would conflict with each other and it has to be a global variable so having "new Jail[MAX_PLAYERS];" then "Jail[targetid] = SetTimerEx(..." would work. Also make sure you kill the timer with that ID. Another thing, go to your OnPlayerDisconnect and put this:
pawn Код:
if(jailed[playerid] == 1)KillTimer(Jail[playerid]);
So if the player disconnects while in jail, it would automatically kill the timer.
Reply
#9

its not new JailTimer(targetid); its forward JailTimer(targetid);
and when i do new JailTimer[MAX_PLAYERS]; i get Symbol already defined


@tee, testing now thanks
Reply
#10

Ah to kill the Sym already defined error you have to either change the var name or the forwared public name.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)