BooneBum Posted September 25, 2013 Share Posted September 25, 2013 I usually try coding my own custom character and I only come for help here when I really need it. I was wondering, is there a way to code your character to be slower in rain? Someone on the forums told me I should add this to my character and I have thought of the idea before. I've tried working my best to figure out the coding but it always fails. Could someone here help me out? I would really appreciate it! Link to comment https://forums.kleientertainment.com/forums/topic/28142-how-to-make-a-character-slow-in-rain/ Share on other sites More sharing options...
GraySloth Posted September 25, 2013 Share Posted September 25, 2013 (edited) I can't say that this is the best way of doing it but off the top of my head use this function: local function doslowinrain(inst) --this bit will let you move freely with an umbrella local mitigates_rain = false for k,v in pairs (inst.components.inventory.equipslots) do if v.components.dapperness then if v.components.dapperness.mitigates_rain then mitigates_rain = true end end end --this will check if it is raining and either set your speed to normal if it is not, or reduce it to half if it is raining if GetSeasonManager() and GetSeasonManager():IsRaining() and not mitigates_rain then inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED * 0.5 inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * 0.5 else inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED end end So then just put this line in your characters main function: inst:DoPeriodicTask(1/10, function() doslowinrain(inst) end)I hope this will be a good starting point for you. Edited September 25, 2013 by GraySloth Link to comment https://forums.kleientertainment.com/forums/topic/28142-how-to-make-a-character-slow-in-rain/#findComment-329730 Share on other sites More sharing options...
BooneBum Posted September 25, 2013 Author Share Posted September 25, 2013 I can't say that this is the best way of doing it but off the top of my head use this function: local function doslowinrain(inst) --this bit will let you move freely with an umbrella local mitigates_rain = false for k,v in pairs (inst.components.inventory.equipslots) do if v.components.dapperness then if v.components.dapperness.mitigates_rain then mitigates_rain = true end end end --this will check if it is raining and either set your speed to normal if it is not, or reduce it to half if it is raining if GetSeasonManager() and GetSeasonManager():IsRaining() and not mitigates_rain then inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED * 0.5 inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED * 0.5 else inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED end end So then just put this line in your characters main function: inst:DoPeriodicTask(1/10, function() doslowinrain(inst) end)I hope this will be a good starting point for you.Thanks for the help but I get this error. Any ideas on how to fix or what I did wrong? Link to comment https://forums.kleientertainment.com/forums/topic/28142-how-to-make-a-character-slow-in-rain/#findComment-330175 Share on other sites More sharing options...
Seyph Posted September 26, 2013 Share Posted September 26, 2013 Try putting it in your character prefab, instead of modmain? Link to comment https://forums.kleientertainment.com/forums/topic/28142-how-to-make-a-character-slow-in-rain/#findComment-330189 Share on other sites More sharing options...
GraySloth Posted September 26, 2013 Share Posted September 26, 2013 (edited) Just like this: local function doslowinrain(inst) --this bit will let you move freely with an umbrella local mitigates_rain = false for k,v in pairs (inst.components.inventory.equipslots) do if v.components.dapperness then if v.components.dapperness.mitigates_rain then mitigates_rain = true end end end --this will check if it is raining and either set your speed to normal if it is not, or reduce it to half if it is raining if GetSeasonManager() and GetSeasonManager():IsRaining() and not mitigates_rain then inst.components.locomotor.walkspeed = 6 * 0.5 inst.components.locomotor.runspeed = 7 * 0.5 else inst.components.locomotor.walkspeed = 6 inst.components.locomotor.runspeed = 7 end endlocal fn = function(inst) inst.components.health:SetMaxHealth(TUNING.WILSON_HEALTH * .5 ) inst.components.hunger:SetMax(TUNING.WILSON_HUNGER * 0.4 ) inst.components.combat.damagemultiplier = .65 inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE*0.25) inst.components.sanity:SetMax(TUNING.WILSON_SANITY*1) inst.components.health.fire_damage_scale = 3.5 inst.soundsname = "wilhelm" inst.MiniMapEntity:SetIcon( "wilson.png" ) inst:DoPeriodicTask(1/10, function() doslowinrain(inst) end) -- todo: Add an example special power here. inst.components.locomotor.walkspeed = 6 inst.components.locomotor.runspeed = 7end In Wilhelm\scripts\prefabs\wil.lua EDIT: changed so it takes into account his custom speed settings. Edited September 26, 2013 by GraySloth Link to comment https://forums.kleientertainment.com/forums/topic/28142-how-to-make-a-character-slow-in-rain/#findComment-330190 Share on other sites More sharing options...
BooneBum Posted September 26, 2013 Author Share Posted September 26, 2013 Just like this:THANKS! That did it! You're awesome! Link to comment https://forums.kleientertainment.com/forums/topic/28142-how-to-make-a-character-slow-in-rain/#findComment-330233 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