Help - 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: Help (
/showthread.php?tid=521962)
Help -
Fjclip99 - 25.06.2014
I have food system that is taking every minute 1 % of food and textdraw to show how many % you have...
Now when i am the only player in the server all works fine, but when there are multiple players then it dont show player HIS hunger, but somone elses... i think that is showing the last players hunger to everyone(player with the highest ID)
Here is the script:
Код:
forward TimerMin(); //This is a 1 minute timer...
public TimerMin()
{
for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i))
{
if(pInfo[i][Hunger] >= 1) // If player have more than 1% of hunger.
{
pInfo[i][Hunger] --;
TextDrawHideForPlayer(i,hrana);
new hranastr[124];
format(hranastr, sizeof(hranastr), "Hrana: %i %", pInfo[i][Hunger]); // Textdraw for display % of hunger.
TextDrawSetString(hrana, hranastr);
TextDrawShowForPlayer(i, hrana);
if(pInfo[i][Hunger] == 1)
{
SendClientMessage(i, COLOR_YELLOW, "Lačni ste. Morate jesti!"); // Warns the player if he have 1% of hunger.
}
}
else if(pInfo[i][Hunger] == 0) // If player have 0% of hunger...
{
new Float:health;
GetPlayerHealth(i,health);
SetPlayerHealth(i, health - 9); // Take 9 players health...
}
}
return 1;
}
Re: Help -
luis_mendoza - 25.06.2014
Try using playerid instead of i(MAX_PLAYERS) ?
Re: Help -
Jack_Leslie - 25.06.2014
You need to assign the textdraw to a player id.
Example:
pawn Код:
new Text:welcomeText[MAX_PLAYERS];
And instead of creating it under OnGameModeInit, you create it under OnPlayerConnect, like:
pawn Код:
welcomeText[playerid] = TextDrawCreate(240.0,580.0,"Welcome to my SA-MP server");
Then from there, instead of using just "welcomeText", you would use "welcomeText[playerid]".
Re: Help -
Fjclip99 - 25.06.2014
Thanks that works...