Jump to content

Recommended Posts

    I'm working on a character who runs faster the more hunger points they have.

I decided the best way would be to set their movespeed stat to TUNING_WILSON_WALKSPEED

+ (current hunger points times 0.005). That seems like it should have been simple enough

but whenever I try to enable the mod, it goes to the menu screen and none of the buttons are

responsive.

 

Here's the code I'm using.

inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_WALKSPEED))inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_RUNSPEED))

Whatever mistake I'm making here is probably painfully obvious to a somewhat more experienced

modder, but I seriously have absolutely no idea what I'm doing wrong.

Edited by Soopakoopa

    I'm working on a character who runs faster the more hunger points they have.

I decided the best way would be to set their movespeed stat to TUNING_WILSON_WALKSPEED

+ (current hunger points times 0.005). That seems like it should have been simple enough

but whenever I try to enable the mod, it goes to the menu screen and none of the buttons are

responsive.

 

Here's the code I'm using.

inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_WALKSPEED))inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_RUNSPEED))

Whatever mistake I'm making here is probably painfully obvious to a somewhat more experienced

modder, but I seriously have absolutely no idea what I'm doing wrong.

inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_WALKSPEED))

inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_RUNSPEED))

You had both set to walkspeed. This could fix it possibly.

Also

Documents>Klei>DoNotStarve> Log,txt

open it, scroll all the way down to the error, (at bottom) and see what line it is referring to

 

Edited by Dryicefox

inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_WALKSPEED))

inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_RUNSPEED))

You had both set to walkspeed. This could fix it possibly.

Also

Documents>Klei>DoNotStarve> Log,txt

open it, scroll all the way down to the error, (at bottom) and see what line it is referring to

 

I already know about the log, and have been making good use of it in the development of this mod.

However, sometimes it doesn't exactly give those most terribly useful information.

 

Thank you though, i'll try that. I'm very good at making dumb mistakes :razz:

 

EDIT: nope, still doesn't work.

 

However, there was something odd in the log...

 

 
~SimLuaProxy()
lua_close took 0.02 seconds
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
HttpClient::ClientThread::Main() complete
Shutting down
Edited by Soopakoopa

Is this just in the character's fn function? If so, it'll only set the speed one time (right when the game loads) and never change again. You need to set the speed every time the hunger changes.

 

-- somewhere in the prefab filelocal function SetSpeedBasedOnHunger(inst)    inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_WALKSPEED))    inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.005 +(TUNING_WILSON_RUNSPEED))end-- in the prefab's fn function:    inst:ListenForEvent("hungerdelta", SetSpeedBasedOnHunger)
Edited by squeek

Whoops, you were using TUNING_WILSON_RUNSPEED/TUNING_WILSON_WALKSPEED which don't exist. They should be TUNING.WILSON_RUN_SPEED/TUNING.WILSON_WALK_SPEED.

Try this:

local function SetSpeedBasedOnHunger(inst)    inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING.WILSON_WALK_SPEED))    inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.005 +(TUNING.WILSON_RUN_SPEED))end
If you want to make sure it works, you can add these lines to the bottom of the SetSpeedBasedOnHunger function:

print("set walk speed to "..inst.components.locomotor.walkspeed.." (default: "..TUNING.WILSON_WALK_SPEED..")")print("set run speed to "..inst.components.locomotor.runspeed.." (default: "..TUNING.WILSON_RUN_SPEED..")")
and then check the console log (CTRL+L) to see if it's modifying the runspeed. Edited by squeek

Whoops, you were using TUNING_WILSON_RUNSPEED/TUNING_WILSON_WALKSPEED which don't exist. They should be TUNING.WILSON_RUN_SPEED/TUNING.WILSON_WALK_SPEED.

Try this:

local function SetSpeedBasedOnHunger(inst)    inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.005 +(TUNING.WILSON_WALK_SPEED))    inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.005 +(TUNING.WILSON_RUN_SPEED))end
If you want to make sure it works, you can add these lines to the bottom of the SetSpeedBasedOnHunger function:

print("set walk speed to "..inst.components.locomotor.walkspeed.." (default: "..TUNING.WILSON_WALK_SPEED..")")print("set run speed to "..inst.components.locomotor.runspeed.." (default: "..TUNING.WILSON_RUN_SPEED..")")
and then check the console log (CTRL+L) to see if it's modifying the runspeed.

 

 

You also originally mentioned that the listenforevent should go within the fn function, and the speed-setting function should go 'somewhere' in the prefab. Whenever I attempt to move it out of the fn function, it crashes the game similarly, but when it IS in the fn function it doesn't seem to actually do its job.

 

Once again the console gives me its hyper-usefulistic information:

 

~SimLuaProxy()
lua_close took 0.02 seconds
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
Orphaned unnamed resource. This resource must have used Add( resource ) to insert itself into the manager. 
HttpClient::ClientThread::Main() complete
Shutting down
Edited by Soopakoopa

Ok, here's the prefab. Don't ask about the name and stuff, it has to do

with a comic I've been dabbling with recently. The coding might be a bit sloppy

by this point, since I've tried so many different unsuccessful methods to get

the system working. I've made other mods before, but I'm still at the

point where making one is a rather rough, bumpy ride.

 

local MakePlayerCharacter = require "prefabs/player_common"


local assets = {

Asset( "ANIM", "anim/player_basic.zip" ),
Asset( "ANIM", "anim/player_idles_shiver.zip" ),
Asset( "ANIM", "anim/player_actions.zip" ),
Asset( "ANIM", "anim/player_actions_axe.zip" ),
Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
Asset( "ANIM", "anim/player_actions_shovel.zip" ),
Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
Asset( "ANIM", "anim/player_actions_eat.zip" ),
Asset( "ANIM", "anim/player_actions_item.zip" ),
Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
Asset( "ANIM", "anim/player_actions_fishing.zip" ),
Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
Asset( "ANIM", "anim/player_bush_hat.zip" ),
Asset( "ANIM", "anim/player_attacks.zip" ),
Asset( "ANIM", "anim/player_idles.zip" ),
Asset( "ANIM", "anim/player_rebirth.zip" ),
Asset( "ANIM", "anim/player_jump.zip" ),
Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
Asset( "ANIM", "anim/player_teleport.zip" ),
Asset( "ANIM", "anim/wilson_fx.zip" ),
Asset( "ANIM", "anim/player_one_man_band.zip" ),
Asset( "ANIM", "anim/shadow_hands.zip" ),
Asset( "SOUND", "sound/sfx.fsb" ),
Asset( "SOUND", "sound/willow.fsb" ),
Asset( "ANIM", "anim/beard.zip" ),

-- Don't forget to include your character's custom assets!
Asset( "ANIM", "anim/ornie.zip" ),
}
local prefabs = {}


local function SetSpeedBasedOnHunger(inst)
inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.01 +(TUNING.WILSON_WALK_SPEED))
inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.01 +(TUNING.WILSON_RUN_SPEED))
end

local fn = function(inst)
--speech sound and map icon
inst.soundsname = "wolfgang"
inst.MiniMapEntity:SetIcon( "wilson.png" )



--Stats
inst.Transform:SetScale(2, 2, 2)inst.components.health:SetMaxHealth(300)
inst.components.hunger:SetMax(300)
inst.components.sanity:SetMax(80)



inst:ListenForEvent("hungerdelta", SetSpeedBasedOnHunger)

end

--Sanity FX
inst.components.sanity.night_drain_mult = 0.5
inst.components.sanity.neg_aura_mult = 0.5
inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.5 )

end



STRINGS.CHARACTER_TITLES.ornie = "The Alien Bird Thing"
STRINGS.CHARACTER_NAMES.ornie = "Ornie"
STRINGS.CHARACTER_DESCRIPTIONS.ornie = " "
STRINGS.CHARACTER_QUOTES.ornie = "\" \""
STRINGS.CHARACTERS.ornie = require "speech_ornie"

return MakePlayerCharacter("ornie", prefabs, assets, fn)
Edited by Soopakoopa

Looks alright to me except you have one too many end's after your fn. Try this:

local MakePlayerCharacter = require "prefabs/player_common"local assets = {	Asset( "ANIM", "anim/player_basic.zip" ),	Asset( "ANIM", "anim/player_idles_shiver.zip" ),	Asset( "ANIM", "anim/player_actions.zip" ),	Asset( "ANIM", "anim/player_actions_axe.zip" ),	Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),	Asset( "ANIM", "anim/player_actions_shovel.zip" ),	Asset( "ANIM", "anim/player_actions_blowdart.zip" ),	Asset( "ANIM", "anim/player_actions_eat.zip" ),	Asset( "ANIM", "anim/player_actions_item.zip" ),	Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),	Asset( "ANIM", "anim/player_actions_bugnet.zip" ),	Asset( "ANIM", "anim/player_actions_fishing.zip" ),	Asset( "ANIM", "anim/player_actions_boomerang.zip" ),	Asset( "ANIM", "anim/player_bush_hat.zip" ),	Asset( "ANIM", "anim/player_attacks.zip" ),	Asset( "ANIM", "anim/player_idles.zip" ),	Asset( "ANIM", "anim/player_rebirth.zip" ),	Asset( "ANIM", "anim/player_jump.zip" ),	Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),	Asset( "ANIM", "anim/player_teleport.zip" ),	Asset( "ANIM", "anim/wilson_fx.zip" ),	Asset( "ANIM", "anim/player_one_man_band.zip" ),	Asset( "ANIM", "anim/shadow_hands.zip" ),	Asset( "SOUND", "sound/sfx.fsb" ),	Asset( "SOUND", "sound/willow.fsb" ),	Asset( "ANIM", "anim/beard.zip" ),	-- Don't forget to include your character's custom assets!	Asset( "ANIM", "anim/ornie.zip" ),}local prefabs = {}local function SetSpeedBasedOnHunger(inst)	inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.01 +(TUNING.WILSON_WALK_SPEED))	inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.01 +(TUNING.WILSON_RUN_SPEED))	print("set walk speed to "..inst.components.locomotor.walkspeed.." (default: "..TUNING.WILSON_WALK_SPEED..")")	print("set run speed to "..inst.components.locomotor.runspeed.." (default: "..TUNING.WILSON_RUN_SPEED..")")endlocal fn = function(inst)	--speech sound and map icon	inst.soundsname = "wolfgang"	inst.MiniMapEntity:SetIcon( "wilson.png" )	--Stats	inst.Transform:SetScale(2, 2, 2)	inst.components.health:SetMaxHealth(300)	inst.components.hunger:SetMax(300)	inst.components.sanity:SetMax(80)	inst:ListenForEvent("hungerdelta", SetSpeedBasedOnHunger)	--Sanity FX	inst.components.sanity.night_drain_mult = 0.5	inst.components.sanity.neg_aura_mult = 0.5	inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.5 )endSTRINGS.CHARACTER_TITLES.ornie = "The Alien Bird Thing"STRINGS.CHARACTER_NAMES.ornie = "Ornie"STRINGS.CHARACTER_DESCRIPTIONS.ornie = " "STRINGS.CHARACTER_QUOTES.ornie = "\" \""STRINGS.CHARACTERS.ornie = require "speech_ornie"return MakePlayerCharacter("ornie", prefabs, assets, fn)
It will print to the console whenever the speed gets set. If it still doesn't work, post your log.txt after playing for a bit.

Looks alright to me except you have one too many end's after your fn. Try this:

 

local MakePlayerCharacter = require "prefabs/player_common"local assets = {	Asset( "ANIM", "anim/player_basic.zip" ),	Asset( "ANIM", "anim/player_idles_shiver.zip" ),	Asset( "ANIM", "anim/player_actions.zip" ),	Asset( "ANIM", "anim/player_actions_axe.zip" ),	Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),	Asset( "ANIM", "anim/player_actions_shovel.zip" ),	Asset( "ANIM", "anim/player_actions_blowdart.zip" ),	Asset( "ANIM", "anim/player_actions_eat.zip" ),	Asset( "ANIM", "anim/player_actions_item.zip" ),	Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),	Asset( "ANIM", "anim/player_actions_bugnet.zip" ),	Asset( "ANIM", "anim/player_actions_fishing.zip" ),	Asset( "ANIM", "anim/player_actions_boomerang.zip" ),	Asset( "ANIM", "anim/player_bush_hat.zip" ),	Asset( "ANIM", "anim/player_attacks.zip" ),	Asset( "ANIM", "anim/player_idles.zip" ),	Asset( "ANIM", "anim/player_rebirth.zip" ),	Asset( "ANIM", "anim/player_jump.zip" ),	Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),	Asset( "ANIM", "anim/player_teleport.zip" ),	Asset( "ANIM", "anim/wilson_fx.zip" ),	Asset( "ANIM", "anim/player_one_man_band.zip" ),	Asset( "ANIM", "anim/shadow_hands.zip" ),	Asset( "SOUND", "sound/sfx.fsb" ),	Asset( "SOUND", "sound/willow.fsb" ),	Asset( "ANIM", "anim/beard.zip" ),	-- Don't forget to include your character's custom assets!	Asset( "ANIM", "anim/ornie.zip" ),}local prefabs = {}local function SetSpeedBasedOnHunger(inst)	inst.components.locomotor.walkspeed = (inst.components.hunger.current * 0.01 +(TUNING.WILSON_WALK_SPEED))	inst.components.locomotor.runspeed = (inst.components.hunger.current * 0.01 +(TUNING.WILSON_RUN_SPEED))	print("set walk speed to "..inst.components.locomotor.walkspeed.." (default: "..TUNING.WILSON_WALK_SPEED..")")	print("set run speed to "..inst.components.locomotor.runspeed.." (default: "..TUNING.WILSON_RUN_SPEED..")")endlocal fn = function(inst)	--speech sound and map icon	inst.soundsname = "wolfgang"	inst.MiniMapEntity:SetIcon( "wilson.png" )	--Stats	inst.Transform:SetScale(2, 2, 2)	inst.components.health:SetMaxHealth(300)	inst.components.hunger:SetMax(300)	inst.components.sanity:SetMax(80)	inst:ListenForEvent("hungerdelta", SetSpeedBasedOnHunger)	--Sanity FX	inst.components.sanity.night_drain_mult = 0.5	inst.components.sanity.neg_aura_mult = 0.5	inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.5 )endSTRINGS.CHARACTER_TITLES.ornie = "The Alien Bird Thing"STRINGS.CHARACTER_NAMES.ornie = "Ornie"STRINGS.CHARACTER_DESCRIPTIONS.ornie = " "STRINGS.CHARACTER_QUOTES.ornie = "\" \""STRINGS.CHARACTERS.ornie = require "speech_ornie"return MakePlayerCharacter("ornie", prefabs, assets, fn)
It will print to the console whenever the speed gets set. If it still doesn't work, post your log.txt after playing for a bit.

 

Thanks, it's working now, I've completed the mod and gave you some special thanks on the workshop page.

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