jjdamstra Posted February 18, 2015 Share Posted February 18, 2015 I'm trying to set it so than my max health = starting health + the day number so my health will increase everyday i stay alive Link to comment https://forums.kleientertainment.com/forums/topic/51143-max-health/ Share on other sites More sharing options...
Mobbstar Posted February 18, 2015 Share Posted February 18, 2015 You need a function that updates the max health, and fire it every new day. My suggestion: local function SetHealth(inst) inst.components.health.maxhealth = BASE_VALUE + PER_DAY * GetClock().numcycles --change the capitalised valuesendlocal function fn() --you already have this line[...] --some stuff inst:ListenForEvent("daytime",SetHealth)end Link to comment https://forums.kleientertainment.com/forums/topic/51143-max-health/#findComment-614362 Share on other sites More sharing options...
Blueberrys Posted February 18, 2015 Share Posted February 18, 2015 (edited) @jjdamstra inst:ListenForEvent("daytime",SetHealth)The "daytime" event is only sent to prefabs that have the clock component. I don't think it's sent to the player.(clock.lua)self.inst:PushEvent("daytime", {day=self.numcycles}) Use GetWorld() in place of inst. Edited February 18, 2015 by Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/51143-max-health/#findComment-614376 Share on other sites More sharing options...
jjdamstra Posted February 18, 2015 Author Share Posted February 18, 2015 (edited) How do I setup that function to do the listenevent. This is what I have just for testing the event. local GetClock = GLOBAL.GetClocklocal GetWorld = GLOBAL.GetWorld local function SetHealth(inst) inst.components.health.maxhealth = 200end local function test( inst )inst.components.health.maxhealth = 150GetWorld():ListenForEvent("daytime",SetHealth)end AddPrefabPostInit("wilson", test) But can't get it to work. I get this error ../mods/1TESTING/modmain.lua:5: attempt to index field 'health' (a nil value)LUA ERROR stack traceback: ../mods/1TESTING/modmain.lua(5,1) in function 'fn' scripts/entityscript.lua(631,1) in function 'PushEvent' scripts/components/clock.lua(439,1) in function 'StartDay' scripts/components/clock.lua(233,1) in function 'NextPhase' scripts/components/clock.lua(309,1) in function 'OnUpdate' scripts/update.lua(104,1) Edited February 19, 2015 by jjdamstra Link to comment https://forums.kleientertainment.com/forums/topic/51143-max-health/#findComment-614421 Share on other sites More sharing options...
jjdamstra Posted February 19, 2015 Author Share Posted February 19, 2015 Ok I got it working thanks for help Mobbstar and Blueberrys Link to comment https://forums.kleientertainment.com/forums/topic/51143-max-health/#findComment-614508 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