27.07.2014, 07:46
How to make Hunger System with Progress bar ?
Have a timer decrease a variable that holds the player's hunger. Here's a progress bar include, which you can set with the hunger variable.
|
You ask how to make it and Jstylezzz told you. If you need someone to script it for you go here.
|
new Bar:bar = CreateProgressBar(495.00, 131.00, 119.50, 11.19, -16776961, 100.0);
new Bar:hungerbar[MAX_PLAYERS];
public OnPlayerConnect(playerid) //When a player connects
{
hungerbar[playerid] = CreateProgressBar(495.00, 131.00, 119.50, 11.19, -16776961, 100.0); //Create a separate progress bar for each player when they join
}
public OnGameModeInit() //When the gamemmode loads
{
SetTimer("HungerCallback",300000,1); //Set a timer that calls the hunger function (300000 milliseconds is 5 minutes. Note that without the fixes plugin that fixes the timers, it could be a little less than 5 minutes)
}
public HungerCallback() //Hunger function
{
for(new i=0; i < MAX_PLAYERS; i++) //Loop through players
{
pInfo[i][Hunger] -= random(3); //Say that you start with 100 (meaning that stomach is full), each time this callback is called it takes away a value between 0 - 3 ( 1 or 2 )
SetProgressBarValue(hungerbar[i], pInfo[i][Hunger]); //Sets the progress bar to the hunger value
}
}
CMD:eat(playerid,params[]) //Example eat command
{
SendClientMessage(playerid, -1, "Hmmmm.. that was some good food!"); //Send message to let the player know they're full again
pInfo[playerid][Hunger] = 100; // 'fill the stomach'
SetProgressBarValue(hungerbar[playerid], pInfo[playerid][Hunger]); //Sets the progress bar to the hunger value
return 1;
}
Here's an example, and note, it's not copy paste code.
pawn Код:
And again, this was written pretty fast, and probably won't work. It's just to give you an example of how it *could* be done. |