Countdown TextDraw bugged.
#1

I've got this, and it works fine for player id 0 but when somebody else enters the server the textdraw gets stuck in 5:00.
Code:
new Minutes =4;
new Seconds =59;
new Text:Timeleft [MAX_PLAYERS];
forward GameTime(playerid);
Code:
OnGameModeInit()
    SetTimer("GameTime",1000,1);

    Timeleft[playerid] = TextDrawCreate(59.000000, 320.000000, "5:00");
    TextDrawBackgroundColor(Timeleft[playerid], 255);
    TextDrawFont(Timeleft[playerid], 1);
    TextDrawLetterSize(Timeleft[playerid], 0.509999, 1.900000);
    TextDrawColor(Timeleft[playerid], -1);
    TextDrawSetOutline(Timeleft[playerid], 1);
    TextDrawSetProportional(Timeleft[playerid], 1);
Code:
OnPlayerSpawn
   	TextDrawShowForPlayer(playerid, Timeleft[playerid]);
Code:
public GameTime(playerid)
{
    if(Seconds || Minutes) {
        Seconds--;
        if(Seconds <= -1) {
            Minutes--;
            Seconds=59;
        }
        new TimeString[128];
        format(TimeString,sizeof(TimeString),"%02d:%02d",Minutes,Seconds);
        TextDrawSetString(Timeleft[playerid],TimeString);
    }

    return 1;
}
Reply
#2

Could be because of this Timeleft[playerid] if it's meant to be a global textdraw you should remove the [playerid] part and just have it as Timeleft.
Reply
#3

Quote:
Originally Posted by -Luis
View Post
Could be because of this Timeleft[playerid] if it's meant to be a global textdraw you should remove the [playerid] part and just have it as Timeleft.
For some reason textdraws without the [playerid] thingie are not showing up in my server
Reply
#4

pawn Code:
new Text:Yourtextdraw
CMD:countdown(playerid, params[])
{
    new number;
    if(sscanf(params,"d",start)) return SCM(...)
    YourTextdraw = TextdrawCreate( .... number)
    TextDrawShowForAll(...);
    SetTimerEx("Countdown",1000,1,"d",number);
    return 1;
}
forward public Countdown(number);
public Countdown(number)
{
TextDrawSetString(YourTextDraw, number - 1);
TextDrawShowForAll(..);
number -= 1;
return 1;
}
Try a code like this? I don't know if it may work, check it out.
Reply
#5

Quote:
Originally Posted by -Luis
View Post
Could be because of this Timeleft[playerid] if it's meant to be a global textdraw you should remove the [playerid] part and just have it as Timeleft.
Quote:
Originally Posted by Rajat_Pawar
View Post
pawn Code:
new Text:Yourtextdraw
CMD:countdown(playerid, params[])
{
    new number;
    if(sscanf(params,"d",start)) return SCM(...)
    YourTextdraw = TextdrawCreate( .... number)
    TextDrawShowForAll(...);
    SetTimerEx("Countdown",1000,1,"d",number);
    return 1;
}
forward public Countdown(number);
public Countdown(number)
{
TextDrawSetString(YourTextDraw, number - 1);
TextDrawShowForAll(..);
number -= 1;
return 1;
}
Try a code like this? I don't know if it may work, check it out.
That's not what I'm looking for, that's a countdown command, mine is some kind of "watch"
Reply
#6

Alright. You are trying to use a player variable (MAX_PLAYERS) as a Textdraw. Use a PlayerTextDraw.
Reply
#7

Quote:
Originally Posted by Rajat_Pawar
View Post
Alright. You are trying to use a player variable (MAX_PLAYERS) as a Textdraw. Use a PlayerTextDraw.
What's the point of replacing it with PlayerTextDraw if the effects are the same?
Reply
#8

LOL, I got your problem. Sorry I didn't get it first.
You are trying to set a timer with a playerid argument in it with SetTimer, which is impossible.
For setting a timer with a function which has it's arguments/parameters, the format is:
pawn Code:
SetTimerEx("MyFunction", Time, Repeating, "Specifier of the argument", Argument name...);
//In your case, it would be:
SetTimerEx("Gametime", 1000, 1, "d", playerid);
Reply
#9

Quote:
Originally Posted by Rajat_Pawar
View Post
LOL, I got your problem. Sorry I didn't get it first.
You are trying to set a timer with a playerid argument in it with SetTimer, which is impossible.
For setting a timer with a function which has it's arguments/parameters, the format is:
pawn Code:
SetTimerEx("MyFunction", Time, Repeating, "Specifier of the argument", Argument name...);
//In your case, it would be:
SetTimerEx("Gametime", 1000, 1, "d", playerid);
There is not "playerid" on "ongamemodeinit" so how do I do that?
Reply
#10

You are telling the compiler that a function called 'Gametime' should be executed every second. But to show it to a player, there needs to be a 'playerid' parameter. So:
Instead of "SetTimer("GameTime", 1000, 1) under OnGameModeInIt,
replace it with:
Quote:

SetTimerEx("Gametime", 1000, 1, "d", playerid);

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)