Jump to content

Max Health


jjdamstra

Recommended Posts

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 values
end


local function fn() --you already have this line
[...] --some stuff

    inst:ListenForEvent("daytime",SetHealth)

end

Link to comment
Share on other sites

How do I setup that function to do the listenevent. This is what I have just for testing the event. 

 

local GetClock = GLOBAL.GetClock
local GetWorld = GLOBAL.GetWorld
 
local function SetHealth(inst)
    inst.components.health.maxhealth = 200
end
 
local function test( inst )
inst.components.health.maxhealth = 150
GetWorld():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)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...