TheMinno01 Posted March 22, 2023 Share Posted March 22, 2023 Hi all i need some help, i want to make my modded character: faster at tasks (aka mining, chopping ect.) during the day. But i also want him to have slower movement speed during night. Does anyone have any code that could help me? cus i have no idea, ty all Link to comment https://forums.kleientertainment.com/forums/topic/146688-character-slower-at-night/ Share on other sites More sharing options...
Merkyrrie Posted March 22, 2023 Share Posted March 22, 2023 (edited) 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 March 24, 2023 by Merkyrrie Fixed syntax in the OnPhaseChange code 2 Link to comment https://forums.kleientertainment.com/forums/topic/146688-character-slower-at-night/#findComment-1626808 Share on other sites More sharing options...
TheMinno01 Posted March 23, 2023 Author Share Posted March 23, 2023 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! Link to comment https://forums.kleientertainment.com/forums/topic/146688-character-slower-at-night/#findComment-1626877 Share on other sites More sharing options...
TheMinno01 Posted March 23, 2023 Author Share Posted March 23, 2023 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 Link to comment https://forums.kleientertainment.com/forums/topic/146688-character-slower-at-night/#findComment-1626882 Share on other sites More sharing options...
Merkyrrie Posted March 23, 2023 Share Posted March 23, 2023 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 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' 1 Link to comment https://forums.kleientertainment.com/forums/topic/146688-character-slower-at-night/#findComment-1626906 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