Jump to content

Multipliers not applying when starting server or entering/exiting caves?

Recommended Posts

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

The below line runs in the master postinit.

inst:WatchWorldState("phase", OnPhaseChange)



Link to comment
Share on other sites

Posted (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 by -LukaS-
  • Happy Hazard 1
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

  • Create New...