Jump to content
Pudge

Lose a "random" Hunger ammount

Recommended Posts

Hellow, thanks for read, thats the problem... i was trying to do something like that. 

any idea about how to do that? 

 

function Itemcool()


local inv = getPlayer():getInventory();


it = inv:FindAndReturn("Base.Apple");
   if it then
        inv:Remove("Apple");


        A = random number between (0 to 100)                                                  

-- Roll a number between 0 and 100

        if A <= 30 then { Player Hunger-10} else {Player Hunger -20}              

 -- 30% chance of lose 10 of hunger and 70% chance of lose 20 Hunger


   end
end

 

Events.OnPlayerUpdate.Add(Itemcool);

 

Solution ---> 

 

function Itemcool()
local inv = getPlayer():getInventory();

local player = getPlayer();
it = inv:FindAndReturn("Base.Apple");
   if it then
        inv:Remove("Apple");

if ZombRand( 100 ) <= 30 then

player:getStats():setThirst (player:getStats():getThirst() + 0.05);                                 

else

player:getStats():setThirst (player:getStats():getThirst() + 0.15);      

end
   end
end

--//  30% chance of get 0.05 thirst and 70% of get 0.15%

 

Events.OnPlayerUpdate.Add(Itemcool);

Edited by Pudge
solved

Share this post


Link to post
Share on other sites

You want to do something like this
 


    if ZombRand( 100 ) <= 30 then
        ...
    end

If you need to check multiple values simply store the returned value in a local variable.

Share this post


Link to post
Share on other sites
4 hours ago, RoboMat said:

    if ZombRand( 100 ) <= 30 then
        ...
    end

Work perfectly :D thanks! RoboMat.

Edited by Pudge

Share this post


Link to post
Share on other sites

Unfortunately I can't really help you with the hunger value. I know it's stored in the character health system or something like that (it's been ages since I looked into that). Sorry :)

 

You could look through the vanilla lua files or even the java files and it should be fairly easy to find.

Share this post


Link to post
Share on other sites

There is a get method that can be called. I don't know method whether this is right.

 

If it is right, it will return player's hunger level.

getMoodleLevel(MoodleType.Hungry);

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...