zvxaxvz Posted December 20, 2021 Share Posted December 20, 2021 Hello! I've been browsing the forums and found some useful code lines, but when I try to implement them, nothing happens. I want my character to lose 5 sanity per hit against anything that isn't a monster, boss, structure or wall. Here's what I've got. local master_postinit = function(inst) inst:ListenForEvent("onattackother", combatdrain) end local function IsValidVictim(victim) return victim ~= nil and not (victim:HasTag("epic") or victim:HasTag("monster") or victim:HasTag("structure") or victim:HasTag("wall")) and victim.components.health ~= nil and victim.components.combat ~= nil end local function combatdrain(inst, data) local victim = data.victim if IsValidVictim(victim) then inst.components.sanity:DoDelta(-5) end end However, it isn't working. I'm sure I must have done something stupid, like put it in the wrong place. It is currently in my character's .lua file in scripts/prefabs. Could someone help me get this to work? Link to comment https://forums.kleientertainment.com/forums/topic/136357-sanity-loss-perk-help/ Share on other sites More sharing options...
jekart021 Posted January 6, 2022 Share Posted January 6, 2022 local function master_postinit(inst) ... inst:ListenForEvent("onattackother", combatdrain) ... local function combatdrain(inst, data) -- to other functions if data ~= nil and data.target ~= nil then if not data.target:HasTag("epic") or data.target:HasTag("structure") or data.target:HasTag("wall") or data.target:HasTag("monster") and data.target.components.health ~= nil and data.target.components.combat ~= nil then inst.components.sanity:DoDelta(-5) end end end 1 Link to comment https://forums.kleientertainment.com/forums/topic/136357-sanity-loss-perk-help/#findComment-1531015 Share on other sites More sharing options...
zvxaxvz Posted January 17, 2022 Author Share Posted January 17, 2022 Thanks, worked like a charm, with a few edits! Link to comment https://forums.kleientertainment.com/forums/topic/136357-sanity-loss-perk-help/#findComment-1533277 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