PDA

View Full Version : Textdraw flashing to a un-desired variable.


rangerxxll
07/03/2014, 05:07 PM
Hello. So this is a bit complicated, but I'll try my best to explain.

I have a hunger and thirst system that uses a textdraw. When a player connects, it sets their thirst and hunger variable to 100 automatically, and it also sets the timer to begin lowering the variable. I've also created a stock to update the textdraw's with ease.

Now the problem is quite strange. Every time the textdraw's variable goes down, it flashes a un-desored variable. Example: Current Hunger: 100. It goes down 1%, and it will quickly flash "55" and then turn to 99. I'm not sure if anything is conflicting with each other, that sets the variable differently or what.

Here's some necessary code.


stock updatetd(playerid) //the updatetd stock that updates my td's string. We're focusing on hunger and thirst.
{
format(hungertdstring,sizeof(hungertdstring), "Hunger: %d", hunger[playerid]);
format(thirsttdstring,sizeof(thirsttdstring), "Thirst: %d", thirst[playerid]);
TextDrawSetString(hungertd, hungertdstring);
TextDrawSetString(thirsttd, thirsttdstring);
TextDrawHideForPlayer(playerid, hungertd);
TextDrawShowForPlayer(playerid, hungertd);
TextDrawHideForPlayer(playerid, thirsttd);
TextDrawShowForPlayer(playerid, thirsttd);
if(GameProgress == 0)
{
TextDrawSetString(StatusTD, "Status: In Lobby");
TextDrawHideForPlayer(playerid, StatusTD);
TextDrawShowForPlayer(playerid, StatusTD2);
}
if(GameProgress == 1)
{
TextDrawSetString(StatusTD, "Status: In Game");
TextDrawHideForPlayer(playerid, StatusTD2);
TextDrawShowForPlayer(playerid, StatusTD);
}



//under onplayerconnect. To show the textdraw, and update it.
TextDrawShowForPlayer(playerid, hungertd);
TextDrawShowForPlayer(playerid, thirsttd);
TextDrawShowForPlayer(playerid, StatusTD);
updatetd(playerid);



// The timers that lowers the textdraw's variables.
forward HungerTimer(playerid);
public HungerTimer(playerid)
{
hunger[playerid] --;
updatetd(playerid);
if(hunger[playerid] == 1)
{
SetPlayerHealth(playerid, 0);
SendClientMessage(playerid,COLOR_RED, "You have died of starvation.");
KillTimer(hTimer);
return 1;
}
if(hunger[playerid] < 20)
{
RemovePlayerHealth(playerid, 10);
SendClientMessage(playerid,COLOR_RED, "You're now starving from starvation. Find food.");
return 1;
}
return 1;
}


If you need any other information, let me know. Thank you.

ColeMiner
07/03/2014, 05:35 PM
It looks like you are using a single global TextDraw, which means that all players use the same single one. When you set the data for one player, all others players will see it too. Use multiple TextDraws or PlayerTextDraws.

rangerxxll
07/03/2014, 05:43 PM
Instead of TextDrawShowForPlayer, you're saying use "PlayerTextDrawShow"? I don't understand how TextDrawShowForPlayer is a global if you're showing it to a playerid.

Would this be correct?

PlayerTextDrawShow(playerid, hungertd)

//instead of:
TextDrawShowForPlayer(playerid, hungertd);


Thank you.

ColeMiner
07/03/2014, 05:51 PM
That line shows a global text draw to one player, but the text draw is still global - you only show it to one player but it CAN be shown to more (and eventually you do show it to more). The per-player text draws only exist for one player, it is simply not possible to show them to more than one player.

rangerxxll
07/03/2014, 05:52 PM
Thanks for the help, wiki didn't mention that.

Just to clarify, PlayerTextDrawShow would be the correct function to use?