Textdraw Sometimes gets "Stuck" on on old number
#1

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
Reply
#2

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

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?
Reply
#4

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.
Reply
#5

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...
Reply
#6

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.
Reply
#7

I found a better solution already
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)