ViridianCrown Posted June 2, 2023 Share Posted June 2, 2023 Hello! I am new to coding and wanted to build a character that would be weaker during the day, evening out at dusk, and growing stronger at night. However, when I coded it to do this, the game would not run checks for world time when starting the server. It would also miss checks whenever I entered a cave, with the character having default speed/strength stats when underground, carrying over to when I went above-ground. The stat changes would only take effect the next world check (when day turned to dusk, dusk to night, etc.) and would miss completely if underground when the world time was checked. If someone could help iron out the code to run checks during server start/leaving caves, that would be very appreciated! local function OnPhaseChange(inst) local phase = TheWorld.state.phase if phase == "day" then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "character_day_speed", 0.75) inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_night_speed") inst.components.combat.damagemultiplier = 0.75 elseif phase == "dusk" then inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_day_speed") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_night_speed") inst.components.combat.damagemultiplier = 1 elseif phase == "night" then inst.components.locomotor:SetExternalSpeedMultiplier(inst, "character_night_speed", 1.25) inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_day_speed") inst.components.combat.damagemultiplier = 1.25 end end The below line runs in the master postinit. inst:WatchWorldState("phase", OnPhaseChange) Link to comment https://forums.kleientertainment.com/forums/topic/148101-multipliers-not-applying-when-starting-server-or-enteringexiting-caves/ Share on other sites More sharing options...
-LukaS- Posted June 4, 2023 Share Posted June 4, 2023 (edited) Simply run OnPhaseChange(inst) right after inst:WatchWorldState("phase", OnPhaseChange). That should fix any issues with entering/exiting caves and starting the server. Edited June 4, 2023 by -LukaS- 1 Link to comment https://forums.kleientertainment.com/forums/topic/148101-multipliers-not-applying-when-starting-server-or-enteringexiting-caves/#findComment-1638497 Share on other sites More sharing options...
ViridianCrown Posted June 4, 2023 Author Share Posted June 4, 2023 It's alive! Thank you so much for helping! Couldn't have done it without you. Link to comment https://forums.kleientertainment.com/forums/topic/148101-multipliers-not-applying-when-starting-server-or-enteringexiting-caves/#findComment-1638605 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