Jump to content

Recommended Posts

I'm trying to make a constant check of the current hunger of my character like  : 

 

if  inst.components.hunger.current  < 100 theninst.components.health.maxhealth =  TUNING.WATHGRITHR_HEALTH * 0.8end

I don't get crashes, but it just doesn't work. What am i doing wrong?

Link to comment
https://forums.kleientertainment.com/forums/topic/56041-checking-stats/
Share on other sites

When does that fire? You need to check it every now and then.

So to make the constant check i need to make a loop?  With do while? This is where the code is located:

 

 

local fn = function(inst)-- 1inst.soundsname = "wolfgang"-- 2inst.MiniMapEntity:SetIcon( "wilson.png" )-- 3inst.components.health:SetMaxHealth(200)inst.components.hunger:SetMax(150)inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE*1.25)inst.components.sanity:SetMax(100)inst.components.combat.damagemultiplier = TUNING.WATHGRITHR_DAMAGE_MULTinst.components.locomotor.walkspeed = 5inst.components.locomotor.runspeed = 7if  inst.components.hunger.current  < 100 theninst.components.health.maxhealth =  TUNING.WATHGRITHR_HEALTH * 0.8inst.components.locomotor.walkspeed = 4inst.components.locomotor.runspeed = 6end

Maybe if i use a boolean value like the wolfgang prefab it'll work?

So to make the constant check i need to make a loop?  With do while? This is where the code is located:

 

EDIT: Snip

 

Maybe if i use a boolean value like the wolfgang prefab it'll work?

 

Do NOT make a while loop. That will run indefinitely, effectively freezing the game.

 

Use this instead (period of 1 second for example purposes):

 

inst:DoPeriodicTask(1, function()

    if  inst.components.hunger.current  < 100 then

    inst.components.health.maxhealth =  TUNING.WATHGRITHR_HEALTH * 0.8

    inst.components.locomotor.walkspeed = 4

    inst.components.locomotor.runspeed = 6

    end

end)

 

Edited by Mobbstar

@TheShadeofTheNorth You can use an eventlistener, which will execute every time hunger is changed.

inst:ListenForEvent("hungerdelta", function(inst, data)	if (data.newpercent < 100) then -- current hunger percent		-- ...	else -- when it becomes more than or equal to 100		-- ...	endend)
Edited by Blueberrys

OOOOH , now i understood  .I made something similar to what you did BlueBerrys  with  a local function  and i put  the eventlistener in local fn = function(inst) . 

 

The only problem is , apparently , it only checks one time and the "else" part of the code doesn't work.  The code mobbstar showed worked  like  a charm , i never knew that  inst:DoPeriodicTask  existed.  Sorry for  my bad english, not my first language.

Edited by TheShadeofTheNorth

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...