kylemery Posted May 13, 2014 Share Posted May 13, 2014 (edited) I was just wondering how to make my character's attributes change along with different values oh hunger. I'm pretty sure this is possible, and thought one of you kind people might be willing to help me out a bit. Also, I thought it would be cool to have a sound play on his hunger reaching a certain point, and already have the sound in the correct folder, so how would I trigger that sound to play? And would it be possible for this sound to attract creatures? Thank you so much to whoever takes the time to responds to this! Edited May 14, 2014 by kylemery Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/ Share on other sites More sharing options...
DeathDisciple Posted May 13, 2014 Share Posted May 13, 2014 you can do e.g.local function onchange(inst, data) local current=inst.components.hunger.current local currentpercent=data.newpercent-- do something based on valuesendthen add inst:ListenForEvent("hungerdelta", onchange) in the prefab function of your char, and it will trigger whenever hunger changes. In general, to call sound playback you use something like inst.SoundEmitter:PlaySound("dontstarve/ghost/ghost_howl_LP") of course you need to tell the game to load your sound files etc, path will depend on how you set up your fmod project. Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-480291 Share on other sites More sharing options...
kylemery Posted May 14, 2014 Author Share Posted May 14, 2014 (edited) you can do e.g.So right now I have... local function onchange(inst, data) local current=inst.components.hunger.current local currentpercent = data.50inst.components.locomotor.walkspeed = 3end Which I'm sure is completely wrong. How do I format the hunger percentage and am I supposed to add attributes just like in the prefab? Edited May 14, 2014 by kylemery Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-480316 Share on other sites More sharing options...
JackSlender Posted May 14, 2014 Share Posted May 14, 2014 Could you clarify what you're trying to do exactly? I'm not quite sure what it is you're trying to accomplish. Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-480351 Share on other sites More sharing options...
kylemery Posted May 14, 2014 Author Share Posted May 14, 2014 Could you clarify what you're trying to do exactly? I'm not quite sure what it is you're trying to accomplish.Sorry for the confusion. My goal is for my character to be weaker depending on his hunger. Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-480357 Share on other sites More sharing options...
JackSlender Posted May 14, 2014 Share Posted May 14, 2014 Like Wolfgang or is it always running? Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-480416 Share on other sites More sharing options...
kylemery Posted May 14, 2014 Author Share Posted May 14, 2014 Like Wolfgang or is it always running?Yeah I was trying to model it off of wolfgang's "mightiness" feature. Basically the character's statistics would be different based off of like 4 levels of hunger such as full, content, hungry, and starving. Sorry if I'm not making any sense. I understand it in my head, but it's hard to convey through words. Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-480848 Share on other sites More sharing options...
JackSlender Posted May 14, 2014 Share Posted May 14, 2014 No, you're fine. Another question, though, what are you exactly changing? Health, strength, speed, or unique? Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-480946 Share on other sites More sharing options...
kylemery Posted May 14, 2014 Author Share Posted May 14, 2014 No, you're fine. Another question, though, what are you exactly changing? Health, strength, speed, or unique?Only speed and strength. So he would walk a little slower and do less damage when hungry. Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-481018 Share on other sites More sharing options...
JackSlender Posted May 15, 2014 Share Posted May 15, 2014 Okay, so what you want to do is:local function onchange(inst) local currenthunger = inst.components.hunger.current local full = 150 local content = 110 local hungry = 70 if currenthunger >= full then inst.components.locomotor.runspeed = 10 inst.components.locomotor.walkspeed = 8 inst.components.combat.damagemultiplier = 2 elseif (currenthunger < full) and (currenthunger >= content) then inst.components.locomotor.runspeed = 8 inst.components.locomotor.walkspeed = 6 inst.components.combat.damagemultiplier = 1.4 elseif (currenthunger < content) and (currenthunger >= hungry) then inst.components.locomotor.runspeed = 6 inst.components.locomotor.walkspeed = 4 inst.components.combat.damagemultiplier = 1 elseif (currenthunger < hungry) then inst.components.locomotor.runspeed = 4 inst.components.locomotor.walkspeed = 2 inst.components.combat.damagemultiplier = 0.7 endendThis code will be seriously wonky, so you'll have to mess with the values a little. By the way, each of the full, content and hungry values are the minimums for each of these stages. For example, if you are above 150 health then you are in your full state. Feel free to tell me if you need additional help, and I'll try to give as much as possible. Link to comment https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/#findComment-481228 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