Jump to content

Custom action not appearing


Lillyth

Recommended Posts

Hello all,

I'm trying to add a custom action to my mod. I've ran into a bunch of errors, but I've finally managed to have the game boot up and not crash. The problem is however, it doesn't actually bring up the prompt to perform said action; only the default ones such as Examine, Attack and Walk To.

local MYACTION = GLOBAL.Action({}, 3)
	MYACTION.id = "MYACTION"
	MYACTION.str = "Perform Action"
	MYACTION.fn = function(act)
		print("Action performed!")
end

AddStategraphActionHandler("wilson", GLOBAL.ActionHandler(MYACTION, "dolongaction"))
AddAction(MYACTION)

This is my current code. I've seen other posts bring up stuff like AddComponentAction, but I don't think that exists in DS (undeclared error). Besides, it's not mentioned anywhere in modutils or actions.lua.

Does anyone know why the action isn't coming up in game? I'm really not sure what else to try.
Thank you in advance.

Link to comment
Share on other sites

Update: Fixed it a day or so after posting. I added a component to my custom item which the action was on- turns out there's a method to check whether or not you're hovering over an entity, and then you can insert the action there. Here's an example:

local customcomponent = Class(function(self, inst)
	self.inst = inst
end)

function customcomponent:CollectEquippedActions(doer, target, actions, right)
		table.insert(actions, ACTIONS.MYACTION)
	end
end

return customcomponent

If anyone's interested, I believe this came from playeractionpicker.lua; there's a couple more like it that handle if you're hovering over an item, for instance.

Link to comment
Share on other sites

Archived

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.

×
  • Create New...