Jump to content

Recommended Posts

I'm kind of new to modding and it's kind of difficult to find things on ListenForEvent and the general way DST runs code. 

For example, if I wanted to have a function that runs when the player's temperature changes, how would I do that?

I know that Delta can check for changes, but how does it work?

Thanks in advance. If someone could suggest a useful guide it would be appreciated too, because I find it hard to search for actually helpful ones.

--Triggers after player initializes
AddPlayerPostInit(function(inst)
	--Temperature test function
	local function TempTest(inst)
		--return if temperature doesnt exist
		if not inst.components.temperature then
			return
		end

		local temp = inst.components.temperature

		--if temperature is above 5 kill player
		if temp > 5 then
			inst.components.heath:DoDelta(-1000)

			--Stops listening to event
			inst:RemoveEventCallback("temperaturedelta", TempTest)
		end
	end

	--player is wilson
	if inst.prefab == "wilson" then
		--ListenForEvent
		inst:ListenForEvent("temperaturedelta", TempTest)
	end
end)

 

Something simple i guess

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