Jump to content

Need help - Modding

Recommended Posts

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 by dahl
Link to comment
Share on other sites


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 :D!

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
	and victim.components.health ~= nil
	and victim.components.combat ~= nil

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
		elseif health < 300 then -- If less than 300 give 10 sanity


Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...