chaosdc123 Posted February 27, 2019 Share Posted February 27, 2019 (edited) So im trying to make it so a "pet" says something when its low on hp and this is what im trying if inst.components.health.currenthealth < 0.9 then inst.components.talker:Say("O0of my BonES!") end but sadly nothing is happening Edited February 27, 2019 by chaosdc123 Link to comment https://forums.kleientertainment.com/forums/topic/103342-need-help/ Share on other sites More sharing options...
Ultroman Posted February 27, 2019 Share Posted February 27, 2019 (edited) That code alone won't do anything. You need to be listening to an event pushed by its health-component when its health changes. Put something like this in the initialization function of the pet prefab (usually called fn or master_postinit): inst:ListenForEvent("healthdelta", function(inst, data) -- You can now access both the old percentage (before the change) and the new percentage (after the change), -- using the data in the data-parameter, respectively data.oldpercent and data.newpercent if data.oldpercent > data.newpercent then -- The pet was hurt, not healed, since oldpercent was higher than the new percentage... if data.newpercent < 0.9 then inst.components.talker:Say("O0of my BonES! Only "..inst.components.health.currenthealth.." HP left!") end end end) You might not want it to say the line every time its health goes down while it's below your threshold, so to combat that you need some kind of system to determine how often it says that. I have not included that in the example code above. If the pet is burning or something else is dealing damage to it over time, the pet will say this line every time the damage ticks in. But who knows? It might not be a problem. Try it out. Note: Your current percentage is set to 0.9 (90%), which I'm guessing is just for testing purposes. A better value for when it's low on health would probably be 0.3 (30%) or lower. Edited April 22, 2019 by Ultroman Link to comment https://forums.kleientertainment.com/forums/topic/103342-need-help/#findComment-1159798 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