Jump to content

Need help with health speed boost.


Recommended Posts

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...