25kubalok Posted November 7, 2019 Share Posted November 7, 2019 Hello I want to make my character lose 20 sanity when golden items broke. I'm new to modding and it's pretty difficult for me to do. Can somebody help? Cause i have no idea how to do this. :/ Link to comment https://forums.kleientertainment.com/forums/topic/113391-need-help-modding/ Share on other sites More sharing options...
dahl Posted November 10, 2019 Share Posted November 10, 2019 (edited) Obvious way to do so is to listen for this event inst:ListenForEvent("percentusedchange", PercentChanged) inside your golden items prefabs (axe,lua for example). Add this listener to a function local function onequipgold(inst, owner) and add to your custom character some custom tag (see in other .lua files) like "goldlover". Then the last thing you should do is decrease sanity of an owner which should have your custom tag when percent of an item go below 0 (i.e. it is broken now). Bad solution, but come on, it's simple. Edited November 10, 2019 by dahl Link to comment https://forums.kleientertainment.com/forums/topic/113391-need-help-modding/#findComment-1282211 Share on other sites More sharing options...
. . . Posted November 22, 2019 Share Posted November 22, 2019 @25kubalok For now I don't know how to do the gold tool breaking thing, but here is code for gaining sanity from killing creatures. Hopefully it works ! Inside your character.lua put this inside the master_postinit inst:ListenForEvent("killed", KilledPrey) then above the master_postinit put -- What stuff won't count as a "valid victim" so you don't get sanity from killing them -- for example if you add " victim:HasTag("butterfly") or " you won't get sanity from killing butterflies local function IsValidVictim(victim) return victim ~= nil and not (victim:HasTag("veggie") or victim:HasTag("wall") or victim:HasTag("structure") or victim:HasTag("groundspike") or victim:HasTag("smashable")) and victim.components.health ~= nil and victim.components.combat ~= nil end local function KilledPrey(inst, data) local victim = data.victim if IsValidVictim(victim) then local health = victim.components.health.maxhealth if health >= 300 then -- If 300 or more health give 30 sanity inst.components.sanity:DoDelta(30) elseif health < 300 then -- If less than 300 give 10 sanity inst.components.sanity:DoDelta(10) end end end Link to comment https://forums.kleientertainment.com/forums/topic/113391-need-help-modding/#findComment-1285706 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