Jump to content

Recommended Posts

I was wondering if there was any way to make a character faster the lower sanity they have and what lua file it would go under. I found a speed changer already for time of day (found below) is there maybe any way I could change it to be based on sanity? If not, what would I need to insert to make it work?

local day_speed = 5
local dusk_speed = 2.5
local night_speed = 1

local function onphase(inst, phase)
	local speed = 1
	
	if phase == "day" then speed = day_speed
	elseif phase == "dusk" then speed = dusk_speed
	else speed = night_speed
	end
	
	inst.components.locomotor:SetExternalSpeedMultiplier( inst, "Acceleration", speed )

end

Hey-hey!

I actually have this exact perk in my Wolemorm mod. You have to place this in your character's lua file, somewhere above local common_postinit:

Spoiler

 

-- Speed function
local function UpdateSpeed(inst)
local sanity = inst.components.sanity.current

if inst:HasTag("playerghost") then return end
if inst.components.health:IsDead() then return end

    if sanity <= 3 then
        inst.components.locomotor.runspeed = 9.5
    end
    
    if sanity >= 4 and sanity <= 20 then
        inst.components.locomotor.runspeed = 8.5
    end
    
    if sanity >= 21 and sanity <= 40 then
        inst.components.locomotor.runspeed = 7.75
    end
    
    if sanity >= 41 and sanity <= 60 then
        inst.components.locomotor.runspeed = 7
    end
    
    if sanity >= 61 and sanity <= 80 then
        inst.components.locomotor.runspeed = 6
    end
    
    if sanity >= 81 then
        inst.components.locomotor.runspeed = 5.85
    end
end

 

Put this inside the master_postinit to make the function trigger whenever your sanity changes:

Spoiler

inst:ListenForEvent("sanitydelta", UpdateSpeed)

Feel free to change the values as you wish and, please, change the name (UpdateSpeed) to something else. If by some coincidence someone has my and your mod activated in the same server, it might cause some silliy interactions if they're named the same.

Cheers!

Edited by C_Thun
  • Thanks 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...