Mmmmmiles Posted September 29, 2018 Share Posted September 29, 2018 I'm creating a character mod for Don't Starve Together (all the cosmetic parts are done), and I need some assistance with an ability of his. He's a robotic character, so I'd prefer if he didn't have to eat, and could instead gain hunger and health from killing. If anyone could help me with this, it would be much appreciated! (I accidentally put this same question on the regular don't starve forum before this, whoops.) Link to comment Share on other sites More sharing options...
Ultroman Posted September 30, 2018 Share Posted September 30, 2018 (edited) I have to say, I think there must be a better way than what I'm gonna propose now, but I can't seem to find one. The problem is, the player isn't made aware when he/she kills something. The thing that gets killed, has a "killed" event pushed on it whenever it dies by its combat component's GetAttacked function, but the combat component doesn't push an event when its DoAttack function deals a killing blow. The only way I see of doing this, would be to register to listen for the "killed" event of every monster you attack (by listening to the player's "onattackother" event, and reading the new target from the data sent by the event), so if their "killed" event is pushed, you can react to it. You would have to have a list of all the monsters you're listening to, so you can make sure not to subscribe to listen for the same monster more than once at a time, and you would also have to somehow stop listening to monsters after a while, so you don't keep listening to them forever. I'm kind of baffled that I can't find a better way to do this. Does anyone else have a better idea? See Lumina's answer below. Edited September 30, 2018 by Ultroman I was mistaken Link to comment Share on other sites More sharing options...
Lumina Posted September 30, 2018 Share Posted September 30, 2018 7 hours ago, Ultroman said: The problem is, the player isn't made aware when he/she kills something. There is an event for this. The "killed" event. When a players kills an entity, the event can be used to trigger a function. Here is the function i use for my character : In masterpostinit : inst:ListenForEvent("killed", onkilled) The function itself : local function onkilled(inst, data) if data.victim:HasTag("animal") then inst.components.sanity:DoDelta(-TUNING.SANITY_SMALL) end end The purpose of my function is to remove sanity each time she kills an animal. You can easily adapt it to gain hunger and health each time your character kills something. Remove the tag check if you don't need it (it's also useful to exclude some cases if needed). I don't think that destroying walls or stuff like this count as killing but you should verify it just in case if you want to be sure that stuff like this will not provide too easy healing methods. Link to comment Share on other sites More sharing options...
Ultroman Posted September 30, 2018 Share Posted September 30, 2018 Ah, I see. I misread this line of code: attacker:PushEvent("killed", { victim = self.inst }) I had read it as "this" instead of "attacker", so I thought it notified the killed entity that it had been killed. It was a late night Thanks for the correction. Link to comment 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