Jump to content

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

@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 by Blueberrys

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)

 

Edited by jjdamstra

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...