MrDoge124 Posted May 25, 2018 Share Posted May 25, 2018 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 Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 26, 2018 Share Posted May 26, 2018 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 More sharing options...
MrDoge124 Posted May 26, 2018 Author Share Posted May 26, 2018 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 More sharing options...
K1NGT1GER609 Posted May 26, 2018 Share Posted May 26, 2018 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 More sharing options...
MrDoge124 Posted May 26, 2018 Author Share Posted May 26, 2018 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 Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 26, 2018 Share Posted May 26, 2018 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 More sharing options...
MrDoge124 Posted May 26, 2018 Author Share Posted May 26, 2018 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. Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 26, 2018 Share Posted May 26, 2018 Yeah the default is: inst.components.locomotor.walkspeed = 4 inst.components.locomotor.runspeed = 6 Link to comment Share on other sites More sharing options...
MrDoge124 Posted May 26, 2018 Author Share Posted May 26, 2018 Thanks for your help. Hopefully I won't run into anymore problems. Link to comment Share on other sites More sharing options...
MrDoge124 Posted May 27, 2018 Author Share Posted May 27, 2018 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 More sharing options...
K1NGT1GER609 Posted May 28, 2018 Share Posted May 28, 2018 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. Link to comment Share on other sites More sharing options...
MrDoge124 Posted May 28, 2018 Author Share Posted May 28, 2018 Where exactly is the bottom of the masterpost_init? i can't seem to find it. Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 28, 2018 Share Posted May 28, 2018 Line 149, move it to line 168. Link to comment Share on other sites More sharing options...
MrDoge124 Posted May 28, 2018 Author Share Posted May 28, 2018 It works! But the character doesn't slow down at full health for some reason. Link to comment Share on other sites More sharing options...
K1NGT1GER609 Posted May 29, 2018 Share Posted May 29, 2018 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 More sharing options...
MrDoge124 Posted May 29, 2018 Author Share Posted May 29, 2018 It works now! Thanks for your help now the mod is complete! Link to comment Share on other sites More sharing options...
Recommended Posts
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.