Jump to content

Recommended Posts

I suggest using 'inst:WatchWorldState("phase", function)' for detecting when it becomes day/dusk/night. Making your character faster at working can be done with 'inst.components.workmultiplier:AddMultiplier' and RemoveMultiplier, and speed can be done with 'inst.components.locomotor:SetExternalSpeedMultiplier' and RemoveExternalSpeedMultiplier

-- in your master_postinit
inst:WatchWorldState("phase", OnPhaseChange)


-- Somewhere outside and above master_postinit function
local function OnPhaseChange(inst)
  local phase = TheWorld.state.phase
  if phase == "day" then
    -- Code
  elseif phase == "dusk" then
    -- Code
  elseif phase == "night" then
    -- Code
  end
end

The workmultiplier and locomotor are used like this as an example

inst.components.workmultiplier:AddMultiplier(ACTIONS.CHOP, 1.5, inst) -- This needs to be done for each action, so CHOP, MINE, and HAMMER. 1.5 can be anything, higher than 1 is better
inst.components.workmultiplier:RemoveMultiplier(ACTIONS.CHOP, inst) -- This needs to be removed for each action


inst.components.locomotor:SetExternalSpeedMultiplier(inst, "character_night_speed", .8) -- "character_night_speed" can be any string, its just the key for the specific speed multiplier and needs to be unique. .8 can be anything, lower than 1 is slower and can't go below 0
inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_night_speed")

Keep in mind that SetExternalSpeedMultiplier will stack with any other speed multipliers on your character

Edited by Merkyrrie
Fixed syntax in the OnPhaseChange code
  • Like 2
15 hours ago, Merkyrrie said:

I suggest using 'inst:WatchWorldState("phase", function)' for detecting when it becomes day/dusk/night. Making your character faster at working can be done with 'inst.components.workmultiplier:AddMultiplier' and RemoveMultiplier, and speed can be done with 'inst.components.locomotor:SetExternalSpeedMultiplier' and RemoveExternalSpeedMultiplier

-- in your master_postinit
inst:WatchWorldState("phase", OnPhaseChange)


-- Somewhere outside and above master_postinit function
local function OnPhaseChange(inst)
  local phase = TheWorld.state.phase
  if phase == "day"
    -- Code
  elseif phase == "dusk"
    -- Code
  elseif phase == "night"
    -- Code
  end
end

The workmultiplier and locomotor are used like this as an example

inst.components.workmultiplier:AddMultiplier(ACTIONS.CHOP, 1.5, inst) -- This needs to be done for each action, so CHOP, MINE, and HAMMER. 1.5 can be anything, higher than 1 is better
inst.components.workmultiplier:RemoveMultiplier(ACTIONS.CHOP, inst) -- This needs to be removed for each action


inst.components.locomotor:SetExternalSpeedMultiplier(inst, "character_night_speed", .8) -- "character_night_speed" can be any string, its just the key for the specific speed multiplier and needs to be unique. .8 can be anything, lower than 1 is slower and can't go below 0
inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_night_speed")

Keep in mind that SetExternalSpeedMultiplier will stack with any other speed multipliers on your character

YOU ARE A GEM THANK YOU!

16 hours ago, Merkyrrie said:

I suggest using 'inst:WatchWorldState("phase", function)' for detecting when it becomes day/dusk/night. Making your character faster at working can be done with 'inst.components.workmultiplier:AddMultiplier' and RemoveMultiplier, and speed can be done with 'inst.components.locomotor:SetExternalSpeedMultiplier' and RemoveExternalSpeedMultiplier

-- in your master_postinit
inst:WatchWorldState("phase", OnPhaseChange)


-- Somewhere outside and above master_postinit function
local function OnPhaseChange(inst)
  local phase = TheWorld.state.phase
  if phase == "day"
    -- Code
  elseif phase == "dusk"
    -- Code
  elseif phase == "night"
    -- Code
  end
end

The workmultiplier and locomotor are used like this as an example

inst.components.workmultiplier:AddMultiplier(ACTIONS.CHOP, 1.5, inst) -- This needs to be done for each action, so CHOP, MINE, and HAMMER. 1.5 can be anything, higher than 1 is better
inst.components.workmultiplier:RemoveMultiplier(ACTIONS.CHOP, inst) -- This needs to be removed for each action


inst.components.locomotor:SetExternalSpeedMultiplier(inst, "character_night_speed", .8) -- "character_night_speed" can be any string, its just the key for the specific speed multiplier and needs to be unique. .8 can be anything, lower than 1 is slower and can't go below 0
inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "character_night_speed")

Keep in mind that SetExternalSpeedMultiplier will stack with any other speed multipliers on your character

hay i, im getting an error msg and i dont know what it means, if anyone could help that would be great image.png

4 hours ago, TheMinno01 said:

hay i, im getting an error msg and i dont know what it means, if anyone could help that would be great image.png

I will keep helping people while forgetting an important piece of syntax somehow and no one can stop me. This is purely my bad, I wrote over that code like 3 times because I kept accidentally clicking out of the coding block so I forgot something the third time through.

add a 'then' at the end of each line with an if or elseif, so 'if phase == "day" then'

  • Like 1

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