ChubbyBacon Posted August 13, 2024 Share Posted August 13, 2024 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. Link to comment https://forums.kleientertainment.com/forums/topic/159016-how-do-listenforevent-and-related-things-work-in-lua/ Share on other sites More sharing options...
Cliffford W. Posted August 14, 2024 Share Posted August 14, 2024 --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 Link to comment https://forums.kleientertainment.com/forums/topic/159016-how-do-listenforevent-and-related-things-work-in-lua/#findComment-1740678 Share on other sites More sharing options...
ChubbyBacon Posted August 16, 2024 Author Share Posted August 16, 2024 Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/159016-how-do-listenforevent-and-related-things-work-in-lua/#findComment-1741005 Share on other sites More sharing options...
ChubbyBacon Posted August 16, 2024 Author Share Posted August 16, 2024 Sorry, when I run my mod, Don't Starve says that "AddPlayerPostInit" is not declared. Does this have to do with the placement of the script in my character prefab? Link to comment https://forums.kleientertainment.com/forums/topic/159016-how-do-listenforevent-and-related-things-work-in-lua/#findComment-1741010 Share on other sites More sharing options...
ChubbyBacon Posted August 16, 2024 Author Share Posted August 16, 2024 Never mind, I got it solved. (I didn't realize to put it in modmain) Link to comment https://forums.kleientertainment.com/forums/topic/159016-how-do-listenforevent-and-related-things-work-in-lua/#findComment-1741047 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