Jump to content

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)

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

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

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

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

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

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

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