Jump to content

Recommended Posts

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! 

 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 by GraySloth

 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? 

 

cqVHi5n.jpg

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 by GraySloth

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