ghost910 Posted February 19, 2015 Share Posted February 19, 2015 Friends, I am in trouble. For my mod should come up with a way to lower the sanity when you kill rabbits and birds are NOT in inventory and on the hands. This is possible or not? Link to comment https://forums.kleientertainment.com/forums/topic/51186-help-character-lower-the-sanity/ Share on other sites More sharing options...
DarkXero Posted February 19, 2015 Share Posted February 19, 2015 You should add a condition for the function that lowers the sanity. For example:if bird.components.inventoryitem.owner == nil then lowersanity()end Link to comment https://forums.kleientertainment.com/forums/topic/51186-help-character-lower-the-sanity/#findComment-614630 Share on other sites More sharing options...
ghost910 Posted February 19, 2015 Author Share Posted February 19, 2015 Sorry friend, I do not understand. Link to comment https://forums.kleientertainment.com/forums/topic/51186-help-character-lower-the-sanity/#findComment-614673 Share on other sites More sharing options...
DarkXero Posted February 19, 2015 Share Posted February 19, 2015 local innocents = { rabbit = true, crow = true, robin = true, robin_winter = true}AddPrefabPostInitAny(function(inst) if inst and innocents[inst.prefab] and inst.components.inventoryitem then inst.wasininventory = false local old1 = inst.components.inventoryitem.ondropfn local old2 = inst.components.inventoryitem.onputininventoryfn inst.components.inventoryitem:SetOnDroppedFn(function(inst) if old1 then old1(inst) end inst.wasininventory = false end) inst.components.inventoryitem:SetOnPutInInventoryFn(function(inst) if old2 then old2(inst) end inst.wasininventory = true end) endend)AddPrefabPostInit("MyCharacter", function(inst) inst:ListenForEvent("killed", function(inst, data) if data and data.victim and innocents[data.victim.prefab] then if not data.victim.wasininventory and inst.components.sanity then inst.components.sanity:DoDelta(-15) end end end)end)In modmain.lua, replace MyCharacter for your character's name. You can try to implement parts of this inside your character's lua file. This takes sanity away from you when what you kill is not in your inventory.This was tricky because if you check for owner after the push event, the owner is nil because the creature is dead, and the only argument given is victim. Link to comment https://forums.kleientertainment.com/forums/topic/51186-help-character-lower-the-sanity/#findComment-614723 Share on other sites More sharing options...
ghost910 Posted February 19, 2015 Author Share Posted February 19, 2015 Many thanks to your friend. I had no doubt in this forum. He has me 2 solve the problem, and I would not say that they are easily Link to comment https://forums.kleientertainment.com/forums/topic/51186-help-character-lower-the-sanity/#findComment-614726 Share on other sites More sharing options...
DarkXero Posted February 20, 2015 Share Posted February 20, 2015 I looked at the combat component and noticed other things I could use.local innocents = { rabbit = true, crow = true, robin = true, robin_winter = true}AddPrefabPostInit("MyCharacter", function(inst) inst.components.combat.onhitotherfn = function(attacker, target, damage) if innocents[target.prefab] and attacker.components.sanity then if target.components.health and target.components.health:IsDead() then attacker.components.sanity:DoDelta(-15) end end endend)This is more simple. And it affects things you kill without using the "Murder" option in the inventory. Link to comment https://forums.kleientertainment.com/forums/topic/51186-help-character-lower-the-sanity/#findComment-614752 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