MrDoge124

Need help with health speed boost.

Recommended Posts

MrDoge124    0

I need some help with a perk for my character where there movement speed increases when their health decreases.

All the things I've tried don't work or crash the game.

I'll upload the character's prefab just incase it is needed.

green.lua

Share this post


Link to post
Share on other sites
K1NGT1GER609    95

Huh this code is don't starve together, so i'll do it in don't starve together coding. First off heres a sample of a function that you can put outside the master_postinit:

local function speedadjustment(inst)
    if (inst.components.health:GetPercent() > .9) then
    inst.components.locomotor.walkspeed = 4.8
    inst.components.locomotor.runspeed = 7.2
    elseif (inst.components.health:GetPercent() > .7) then
    inst.components.locomotor.walkspeed = 4.6
    inst.components.locomotor.runspeed = 6.9
    elseif (inst.components.health:GetPercent() > .5) then
    inst.components.locomotor.walkspeed = 4.4
    inst.components.locomotor.runspeed = 6.4
end
end

with that theres three check for percentage of health to do and for the master_postinit put this:

inst:DoPeriodicTask(1, speedadjustment, nil, inst)

Share this post


Link to post
Share on other sites
MrDoge124    0
Posted (edited)

I put the code in the mod and the game seems to close itself at the character select screen. I looked in the client log for errors and this is what I found.

[00:01:23]: [string "../mods/Green/scripts/prefabs/green.lua"]:98: variable 'speedadjustment' is not declared
LUA ERROR stack traceback:
    =[C]:-1 in (global) error (C) <-1--1>
    scripts/strict.lua:23 in () ? (Lua) <21-26>
    ../mods/Green/scripts/prefabs/green.lua:98 in (upvalue) master_postinit (Lua) <85-173>
    scripts/prefabs/player_common.lua:1593 in (field) fn (Lua) <1263-1617>
    scripts/mainfunctions.lua:255 in () ? (Lua) <244-286>
    =[C]:-1 in (method) SendResumeRequestToServer (C) <-1--1>
    scripts/prefabs/world_network.lua:30 in (field) fn (Lua) <19-34>
    scripts/scheduler.lua:177 in (method) OnTick (Lua) <155-207>
    scripts/scheduler.lua:371 in (global) RunScheduler (Lua) <369-377>
    scripts/update.lua:170 in () ? (Lua) <149-228>

For some reason the variable 'speedadjustment' is not declared and I'm not sure how to fix it.

green.lua

Edited by MrDoge124

Share this post


Link to post
Share on other sites
K1NGT1GER609    95
Posted (edited)

You declared the function after its been called by the periodictask so the main(masterpostinit) doesn't know where the speedadjustment function is. Move:

inst:DoPeriodicTask(1, speedadjustment, nil, inst)

all the way to the bottom of the masterpost_init so that the function can be seen and called properly.

Edited by K1NGT1GER609

Share this post


Link to post
Share on other sites
MrDoge124    0
Posted (edited)

The game doesn't crash anymore but when I set my health using the c_sethealth command the character doesn't seem to speed up.

I'm not sure if it's working or not. Is there a better way I can test it?

green.lua

Edited by MrDoge124
Added .lua file

Share this post


Link to post
Share on other sites
K1NGT1GER609    95
Posted (edited)

Seems you haven't taken a closer look at the code(see if your paying attention), it decreases speed as your health lowers. I expected you to modify it to your liking as I can't guess what you want, and testing I wouldn't use certain console commands that alter your stats as they cause strange results that aren't worth looking into or making any logic out of.

Edited by K1NGT1GER609

Share this post


Link to post
Share on other sites
MrDoge124    0
Posted (edited)

Ok I'll see if I can modify it.

I'm not sure what the default walk and run speed values are. Do you know what they are?

I think walking is 4 and running is 6.

Edited by MrDoge124

Share this post


Link to post
Share on other sites
MrDoge124    0
Posted (edited)

I've been using monster meat and healing salves to raise the health up and down but for some reason the character doesn't seem to speed up.

I don't know what i'm doing wrong or if it's something in the code.

Would using green_speed_mod thing work?

I've attached the .lua file down below.

green.lua

Edited by MrDoge124

Share this post


Link to post
Share on other sites
K1NGT1GER609    95

According to the lua file the code only activates when your sanity is less than 65 sanity points. The code:

inst:DoPeriodicTask(1, speedadjustment, nil, inst)

shouldn't be in the sanitylight function if thats what your overseeing.

Share this post


Link to post
Share on other sites
MrDoge124    0
Posted (edited)

It works! But the character doesn't slow down at full health for some reason.

Edited by MrDoge124

Share this post


Link to post
Share on other sites
K1NGT1GER609    95

maybe put a else:

local function speedadjustment(inst)
    if (inst.components.health:GetPercent() < .9) then
    inst.components.locomotor.walkspeed = 7.2
    inst.components.locomotor.runspeed = 9.2
    elseif (inst.components.health:GetPercent() < .7) then
    inst.components.locomotor.walkspeed = 7.4
    inst.components.locomotor.runspeed = 9.4
    elseif (inst.components.health:GetPercent() < .5) then
    inst.components.locomotor.walkspeed = 7.8
    inst.components.locomotor.runspeed = 9.8

else

inst.components.locomotor.walkspeed = 4
    inst.components.locomotor.runspeed = 6
end
end

Share this post


Link to post
Share on other sites

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