Chirpidi Posted August 9, 2020 Share Posted August 9, 2020 (edited) Hello again. sorry for all the questions..! this time Its not Giggabyte I need help with. I'm making a character for my friend, and she wants her character to have a small sanity boost when killing things. not just monsters but even passive creatures like bunnies and birds. I have googled solutions and came across: https://forums.kleientertainment.com/forums/topic/51989-gain-sanity-during-day-and-gain-sanity-on-kill/ https://forums.kleientertainment.com/forums/topic/67456-gain-sanity-from-killing-monsters-lose-sanity-from-attacking-people/ https://forums.kleientertainment.com/forums/topic/57033-character-gain-sanity-upon-kill-not-working/ though none of these worked. I have also copied the code directly from Wathgrithr's(?) .lua but Im not really sure exactly what bits did what I was wanting and/or what i didnt need to copy and I got lost. I thought about copying the code: inst:ListenForEvent("onattackother", function(inst, data) if data.target.prefab == "spider" then inst.components.sanity:DoDelta(TUNING.SANITY_TINY) end end) (from the third link) and just copying this for every creature in the game but that would take forever and would probably cause problems. Ive tried putting code in the masters_postinit spot, above that, under the line "local prefabs = FlattenTree(start_inv, true)" but nothing Im doing is working. I really just need to know what code I need and where I put it. any help is greatly appreciated! thank you in advance!! Edited August 9, 2020 by Chirpidi Link to comment Share on other sites More sharing options...
-LukaS- Posted August 10, 2020 Share Posted August 10, 2020 You can add a listener for the "killed" event to your character and make a function that increases the sanity every time it happens. inst inst:ListenForEvent("killed", OnKill) -- an example OnKill function can look something like this: local function OnKill(inst, data) local victim = data.victim if victim and not victim:HasTag("player") and inst.components.sanity then inst.components.sanity:DoDelta(TUNING.SANITY_TINY) end end . 2 Link to comment Share on other sites More sharing options...
Chirpidi Posted August 10, 2020 Author Share Posted August 10, 2020 5 hours ago, IThatGuyI said: You can add a listener for the "killed" event to your character and make a function that increases the sanity every time it happens. inst inst:ListenForEvent("killed", OnKill) -- an example OnKill function can look something like this: local function OnKill(inst, data) local victim = data.victim if victim and not victim:HasTag("player") and inst.components.sanity then inst.components.sanity:DoDelta(TUNING.SANITY_TINY) end end . Thank you!! I used that and referenced Warthgritr's code again and got it working, thank you so much!! 1 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