TheShadeofTheNorth Posted July 10, 2015 Share Posted July 10, 2015 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.8endI 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 More sharing options...
Mobbstar Posted July 10, 2015 Share Posted July 10, 2015 When does that fire? You need to check it every now and then. Link to comment https://forums.kleientertainment.com/forums/topic/56041-checking-stats/#findComment-653197 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 10, 2015 Author Share Posted July 10, 2015 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 = 6endMaybe if i use a boolean value like the wolfgang prefab it'll work? Link to comment https://forums.kleientertainment.com/forums/topic/56041-checking-stats/#findComment-653304 Share on other sites More sharing options...
Mobbstar Posted July 10, 2015 Share Posted July 10, 2015 (edited) 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 endend) Edited July 10, 2015 by Mobbstar Link to comment https://forums.kleientertainment.com/forums/topic/56041-checking-stats/#findComment-653311 Share on other sites More sharing options...
Blueberrys Posted July 10, 2015 Share Posted July 10, 2015 (edited) @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 July 10, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/56041-checking-stats/#findComment-653357 Share on other sites More sharing options...
TheShadeofTheNorth Posted July 10, 2015 Author Share Posted July 10, 2015 (edited) 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 July 10, 2015 by TheShadeofTheNorth Link to comment https://forums.kleientertainment.com/forums/topic/56041-checking-stats/#findComment-653410 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now