Jump to content

Run code after player character loaded.


Recommended Posts

How would I run code after a player loaded in, for example setting max health?

The api example shows this, but it seems to be outdated.

function ModifyStartStats(player)
	player.components.health:SetMaxHealth(333)
end

AddSimPostInit(ModifyStartStats)

I tried this, but got the same issue of nil value for player.

function ModifyStartStats()
	GLOBAL.ThePlayer.components.health:SetMaxHealth(333)
end

AddGamePostInit(ModifyStartStats)

Thank.

Link to comment
Share on other sites

Use PlayerPostInit instead of AddSimPostInit:

AddPlayerPostInit(function(player)
	player.components.health:SetMaxHealth(50) -- all players
	if player.prefab = "wendy" then -- specific characters
		inst.components.combat.damagemultiplier = 1 
	end
end)

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...