Author Topic: Hunger Script not working correctly  (Read 2771 times)

Code: [Select]
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 //you might have used the wrong varible.
%armor IS the player object, idk what the second variable is supposed to be.
It's supposed to be %client = %armor.client and then %armor.hungerloop(100);


Edit: Also, you need to add a check if the armor type is a player. AIPlayers also have client dynamic fields that show their ownership.

EditEdit:
It turns out I was mistaken, my bad. The second parameter in onAdd is indeed the object that was added. So it would be %playerObject.getClassname() and the previous statements I made were wrong.
« Last Edit: December 13, 2015, 10:04:18 AM by Dannu »

Edit: Also, you need to add a check if the armor type is a player. AIPlayers also have client dynamic fields that show their ownership.
how
if(%armor == %playerObject)? or something?

if(%armor.getClassName() $= "Player") Lose the playerobject.

Edit: It turns out I was mistaken, my bad. The second parameter in onAdd is indeed the object that was added. So it would be %playerObject.getClassname() and the previous statements I made were wrong.
« Last Edit: December 13, 2015, 10:03:23 AM by Dannu »

so I put that into the package?

Edit: doesn't work.
Code: [Select]
function Player::HungerLoop(%this, %hunger)
{
%client = %this.client;

    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--;
bottomPrint(%client, "your hunger is" SPC %hunger, 5);
}
   
    %this.hungerLoopSch = %this.schedule(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?
if(%playerObject.getClassName() $= "Player")
%playerObject.HungerLoop(100); //Call it, set their hunger to 100 //you might have used the wrong varible.
    }
};
activatePackage("blah");

Echo some of the variables/echo past some of the returns, to see what's going wrong.

I fixed it.
Thanks to eval.
« Last Edit: December 13, 2015, 07:55:00 PM by Bow »

I fixed it.
Thanks to eval.

That's not a good thing, almost anything that requires eval() can be done in a safer way.
What did you do?

That's not a good thing, almost anything that requires eval() can be done in a safer way.
What did you do?
what do you mean what did I do?
I just downloaded eval and then I re enabled the hunger script and it worked. Well, it used to work, but for some strange reason it broke.
What's the safer way?
« Last Edit: December 14, 2015, 07:02:59 AM by Bow »

what do you mean what did I do?
I just downloaded eval and then I re enabled the hunger script and it worked. Well, it used to work, but for some strange reason it broke.
What's the safer way?
He thought you fixed it by using the eval function.

I've tried to help you fix it. I told you to add echos to it. But I guess you don't want to.

He thought you fixed it by using the eval function.

I've tried to help you fix it. I told you to add echos to it. But I guess you don't want to.
I did echo's and they seem to be good. Hunger has the correct amount.
I don't really see a point in echoing a players object, as it is just a bunch of numbers. (I tried it myself.)
The script worked perfectly. Now all I need to do is make the message look cleaner.
« Last Edit: December 14, 2015, 03:51:15 PM by Bow »