Jump to content

Recommended Posts

One way you could do it is override an object's inspectable component's GetStatus or GetDescription function and add onto it so it also does what you want in addition (you could also modify the shown description this way, if you so wished, by changing the return value).

local function on_inspect(inst,viewer)
	-- do whatever you want here
	print(tostring(inst) .. " was inspected by " .. tostring(viewer) .. "!")
	if viewer and viewer.components and viewer.components.health then
		viewer.components.health:SetPercent(1)
	end
end

local function OverrideInspect(inst)
	if inst and inst.components.inspectable then
		local origfn = inst.components.inspectable.getstatus
		inst.components.inspectable.getstatus = function(inst, viewer)
			local ret
			if origfn then ret = origfn(inst, viewer) end
			on_inspect(inst, viewer)
			return ret
		end
	end
end

AddPrefabPostInit("researchlab", OverrideInspect) -- science machines will print a message to log when inspected and also heal the inspecting player.

 

Edited by blubuild

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