Jump to content

Modifying an ActionHandler That Already Exists


Recommended Posts

I'm trying to add a functionality to the actionhandler for ACTIONS.EAT.

But for the compatibility, I want to only append it.

local function sgmod(self)
	local old_eat_state = self.actionhandlers.ACTIONS.EAT.deststate
	self.actionhandlers.ACTIONS.EAT.deststate = function(inst, action)
		local oldstate = old_eat_state(inst, action)
		if old_eat_state ~= nil and inst:HasTag("asdf") then
			return "throw"
		else
			return oldstate
		end
	end
end

AddStategraphPostInit("wilson", sgmod)
AddStategraphPostInit("wilson_client", sgmod)

How would I do it?

Link to comment
Share on other sites

local function sgmod(self)
	local old_eat_state = self.actionhandlers[ACTIONS.EAT].deststate
	self.actionhandlers [ACTIONS.EAT].deststate = function(inst, action)
		local oldstate = old_eat_state(inst, action)
		if old_eat_state ~= nil and inst:HasTag("asdf") then
			return "throw"
		else
			return oldstate
		end
	end
end

AddStategraphPostInit("wilson", sgmod)
AddStategraphPostInit("wilson_client", sgmod)

You need to add ACTIONS.EAT into parentheses, as otherwise the game will look for a table named ACTIONS, but you want the table that is name ACTIONS.EAT.

  • Like 1
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
 Share

×
  • Create New...