Sign in to follow this  
AFS Co.

Modifying an ActionHandler That Already Exists

Recommended Posts

AFS Co.    51

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?

Share this post


Link to post
Share on other sites
Monti18    400
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

Share this post


Link to post
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
Sign in to follow this