SA-MP Forums Archive
Textdraw Sometimes gets "Stuck" on on old number - 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: Textdraw Sometimes gets "Stuck" on on old number (/showthread.php?tid=322377)



Textdraw Sometimes gets "Stuck" on on old number - milanosie - 01.03.2012

Hi there! I made a hunger system and it works perfectly, Just one lil bug that sometimes appears.
Every 2 minuts your hunger goes up by 1 point, but sometimes it keeps stuck on one number but it still keeps counting!

So it would then show like 10 and 12 together at the same time, and 2 minuts later it would show "10 and 13" together at the same time,

Any idea what is going wrong?


OnPlayerSpawn(playerid)
pawn Код:
FoodText[playerid] = TextDrawCreate(246, 350, "");
    TextDrawFont(FoodText[playerid],1); //font type of textdraw
    TextDrawLetterSize(FoodText[playerid],0.799999,1.900000); //size...
    TextDrawColor(FoodText[playerid],COLOR_ORANGE); //color
    format(string54, sizeof(string54), "Hunger: %d", PlayerInfo[playerid][Food]);
    TextDrawSetString(FoodText[playerid],string54);
    KillTimer(FoodTimer[playerid]);
    FoodTimer[playerid] = SetTimerEx("Food_Down", 120000, true, "i", playerid);
    TextDrawShowForPlayer(playerid, FoodText[playerid]);
pawn Код:
forward Food_Down(playerid);
public Food_Down(playerid)
{
    if(PlayerInfo[playerid][Food] < 100)
    {
        PlayerInfo[playerid][Food] = PlayerInfo[playerid][Food] + 1;
        new string[64];
        format(string,sizeof(string), "Hunger: %d", PlayerInfo[playerid][Food]);
        TextDrawSetString(FoodText[playerid],string);
        return 1;
    }
    if(PlayerInfo[playerid][Food] > 90 && PlayerInfo[playerid][Food] < 100)
    {
              //Not need to be shown
        return 1;
    }
    if(PlayerInfo[playerid][Food] >= 100)
    {
               //Not need to be shown
    }
    return 1;
}

thanks for the help and please dont use the script


Re: Textdraw Sometimes gets "Stuck" on on old number - Psymetrix - 02.03.2012

It sounds like your creating the textdraw several times. Make sure you only create the textdraw once for each player.


Re: Textdraw Sometimes gets "Stuck" on on old number - milanosie - 02.03.2012

Quote:
Originally Posted by Psymetrix
Посмотреть сообщение
It sounds like your creating the textdraw several times. Make sure you only create the textdraw once for each player.
This is the only code that has something to do with this textdraw, I don't see multiple creations here right?


Re: Textdraw Sometimes gets "Stuck" on on old number - Psymetrix - 02.03.2012

Quote:
Originally Posted by milanosie
Посмотреть сообщение
This is the only code that has something to do with this textdraw, I don't see multiple creations here right?
Yes, you do. OnPlayerSpawn is called every time a player spawns (duh). You create the textdraw again each time the player spawns. Use another variable to track weather or not the player has the textdraw or not and create the text accordingly.


Re: Textdraw Sometimes gets "Stuck" on on old number - milanosie - 02.03.2012

Quote:
Originally Posted by Psymetrix
Посмотреть сообщение
Yes, you do. OnPlayerSpawn is called every time a player spawns (duh). You create the textdraw again each time the player spawns. Use another variable to track weather or not the player has the textdraw or not and create the text accordingly.
ugh, Why did I not see that -.-

I will just place it to "OnPlayerConnect"

Thanks for noticing, I feel really blind now...


Re: Textdraw Sometimes gets "Stuck" on on old number - ricardo178 - 02.03.2012

Quote:
Originally Posted by milanosie
Посмотреть сообщение
ugh, Why did I not see that -.-

I will just place it to "OnPlayerConnect"

Thanks for noticing, I feel really blind now...
Or delete it when player die, so it wont double on creating again.


Re: Textdraw Sometimes gets "Stuck" on on old number - milanosie - 02.03.2012

I found a better solution already