SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/02/2013, 01:03 AM   #1
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Countdown TextDraw bugged.

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;
}
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Old 16/02/2013, 02:13 AM   #2
Luis-
High-roller
 
Luis-'s Avatar
 
Join Date: Jan 2010
Location: England
Posts: 3,933
Reputation: 415
Default Re: Countdown TextDraw bugged.

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.
__________________
Luis- is offline   Reply With Quote
Old 16/02/2013, 04:02 AM   #3
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Respuesta: Re: Countdown TextDraw bugged.

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
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Old 16/02/2013, 04:12 AM   #4
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,177
Reputation: 320
Default Re: Countdown TextDraw bugged.

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.
RajatPawar is offline   Reply With Quote
Old 16/02/2013, 04:17 AM   #5
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Respuesta: Re: Countdown TextDraw bugged.

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"
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Old 16/02/2013, 04:30 AM   #6
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,177
Reputation: 320
Default Re: Countdown TextDraw bugged.

Alright. You are trying to use a player variable (MAX_PLAYERS) as a Textdraw. Use a PlayerTextDraw.
RajatPawar is offline   Reply With Quote
Old 16/02/2013, 04:43 AM   #7
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Respuesta: Re: Countdown TextDraw bugged.

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?
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Old 16/02/2013, 04:51 AM   #8
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,177
Reputation: 320
Default Re: Countdown TextDraw bugged.

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);
RajatPawar is offline   Reply With Quote
Old 16/02/2013, 05:01 AM   #9
Dex007HLH
Big Clucker
 
Dex007HLH's Avatar
 
Join Date: Nov 2010
Location: Somewhere infront of a computer.
Posts: 121
Reputation: 2
Default Respuesta: Re: Countdown TextDraw bugged.

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?
__________________
This signature was made in 5.706 seconds
Dex007HLH is offline   Reply With Quote
Old 16/02/2013, 05:04 AM   #10
RajatPawar
High-roller
 
RajatPawar's Avatar
 
Join Date: Aug 2011
Location: ヽ༼ຈل͜ຈ༽ノ
Posts: 2,177
Reputation: 320
Default Re: Countdown TextDraw bugged.

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);
RajatPawar is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Textdraw Countdown KingyKings Scripting Help 2 02/12/2012 05:25 PM
Countdown textdraw newbienoob Scripting Help 3 05/07/2012 09:27 PM
Countdown in textdraw Face9000 Help Archive 1 05/06/2011 08:05 PM
COuntDown Textdraw DragonBlaster50 Help Archive 10 27/07/2010 04:38 PM
60 Second Textdraw countdown. [mad]MLK Help Archive 1 14/08/2009 09:22 AM


All times are GMT. The time now is 05:38 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.