This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.


Need help - Modding

Recommended Posts

25kubalok    1

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. :/ 

Share this post

Link to post
Share on other sites
dahl    40

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.

Share this post

Link to post
Share on other sites
--- -.-    3374


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

local function KilledPrey(inst, data)
	local victim = data.victim
	if IsValidVictim(victim) then
		local health =
		if health >= 300 then -- If 300 or more health give 30 sanity
		elseif health < 300 then -- If less than 300 give 10 sanity


Share this post

Link to post
Share on other sites