So, viso made a hunger script for my hopefully upcoming hunger games server. When the code was executed, the jet bar showed up like it was supposed to, however, it didn't go down. Also, when I killed my self, the bar wasn't there anymore. I tried to fix/find the problem my self, but I couldn't find it. Please help.
function Player::HungerLoop(%this, %hunger)
{
if(!isObject(%this)) //Return the function if nothing exists, usually happens when you call your client's player to use this function that doesn't exist or something like that
return;
//This runs on a schedule, this helps prevent multiple schedules running on an object, this is always recommended to do.
cancel(%this.hungerLoopSch);
if(%this.getState() $= "dead") //If it is dead do not continue the code (return it)
return;
if(%hunger <= 0)
%this.addHealth(-1);
else
%hunger--; //Subtract the health by 1
%this.hungerLoopSch = %this.schedule(1 * 5000, "HungerLoop", %hunger);
}
//Done.
//Because we don't have it called yet, it won't work, so we need to make a way for it to work.
package blah
{
//This happens when a player spawns
function Armor::onAdd(%armor, %playerObject)
{
Parent::onAdd(%armor, %playerObject);
if(isObject(%client = %playerObject.client) && isObject(%minigame = %client.minigame)) //Do they have a client and a minigame?
%playerObject.HungerLoop(100); //Call it, set their hunger to 100
}
};
activatePackage("blah");