Jump to content

Recommended Posts

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 by kylemery
Link to comment
https://forums.kleientertainment.com/forums/topic/36421-a-quick-coding-question/
Share on other sites

you can do e.g.

local function onchange(inst, data)	local current=inst.components.hunger.current        local currentpercent=data.newpercent-- do something based on valuesend

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

you can do e.g.

So right now I have...

 

local function onchange(inst, data)
 
    local current=inst.components.hunger.current
        local currentpercent = data.50
inst.components.locomotor.walkspeed = 3
end
 
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 by kylemery

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.

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    endend

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

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