Soopakoopa Posted March 11, 2014 Share Posted March 11, 2014 (edited) 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 enoughbut whenever I try to enable the mod, it goes to the menu screen and none of the buttons areresponsive. 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 experiencedmodder, but I seriously have absolutely no idea what I'm doing wrong. Edited March 11, 2014 by Soopakoopa Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/ Share on other sites More sharing options...
Dryicefox Posted March 11, 2014 Share Posted March 11, 2014 (edited) 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 enoughbut whenever I try to enable the mod, it goes to the menu screen and none of the buttons areresponsive. 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 experiencedmodder, 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.AlsoDocuments>Klei>DoNotStarve> Log,txtopen it, scroll all the way down to the error, (at bottom) and see what line it is referring to Edited March 11, 2014 by Dryicefox Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-428516 Share on other sites More sharing options...
Soopakoopa Posted March 11, 2014 Author Share Posted March 11, 2014 (edited) 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.AlsoDocuments>Klei>DoNotStarve> Log,txtopen 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 EDIT: nope, still doesn't work. However, there was something odd in the log... ~SimLuaProxy()lua_close took 0.02 secondsOrphaned 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() completeShutting down Edited March 11, 2014 by Soopakoopa Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-428520 Share on other sites More sharing options...
squeek Posted March 11, 2014 Share Posted March 11, 2014 (edited) 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 March 11, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-428548 Share on other sites More sharing options...
Soopakoopa Posted March 11, 2014 Author Share Posted March 11, 2014 Well...it fixed the crashing...but the speed scaling based on hunger doesn't actually seem to work. Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-428568 Share on other sites More sharing options...
squeek Posted March 11, 2014 Share Posted March 11, 2014 (edited) 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))endIf 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 March 11, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-428590 Share on other sites More sharing options...
Soopakoopa Posted March 11, 2014 Author Share Posted March 11, 2014 (edited) 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))endIf 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 secondsOrphaned 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() completeShutting down Edited March 11, 2014 by Soopakoopa Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-428773 Share on other sites More sharing options...
squeek Posted March 11, 2014 Share Posted March 11, 2014 (edited) The SetSpeedBasedOnHunger function should be above the fn function (as it needs to be defined before it is used). Post your prefab file. Those errors/warnings are unrelated. Edited March 11, 2014 by squeek Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-428909 Share on other sites More sharing options...
Soopakoopa Posted March 12, 2014 Author Share Posted March 12, 2014 (edited) Ok, here's the prefab. Don't ask about the name and stuff, it has to dowith a comic I've been dabbling with recently. The coding might be a bit sloppyby this point, since I've tried so many different unsuccessful methods to getthe system working. I've made other mods before, but I'm still at thepoint 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))endlocal fn = function(inst)--speech sound and map iconinst.soundsname = "wolfgang"inst.MiniMapEntity:SetIcon( "wilson.png" )--Statsinst.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 FXinst.components.sanity.night_drain_mult = 0.5inst.components.sanity.neg_aura_mult = 0.5inst.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) Edited March 12, 2014 by Soopakoopa Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-429165 Share on other sites More sharing options...
squeek Posted March 12, 2014 Share Posted March 12, 2014 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. Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-429182 Share on other sites More sharing options...
Soopakoopa Posted March 13, 2014 Author Share Posted March 13, 2014 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. Link to comment https://forums.kleientertainment.com/forums/topic/32611-what-am-i-doing-wrong-here/#findComment-430303 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now