Jump to content

[SOLVED] Action override firing twice?


Recommended Posts

Hey all,

I am attempting to overwrite the default ACTIONS.PICKUP action in my mod safely. When I try to do this, the action fires twice every time it fires (so all things can still pick things up, but at the same time they get "I cant do that" and the print in my fn below fires twice).

My Code (in modmain.lua, tak is my mod's character):

local function _overrideActionPickupFn(inst)
	
	if ACTIONS and ACTIONS.PICKUP and ACTIONS.PICKUP.fn ~= newPICKUPfn then
		local _actionPickupFn = ACTIONS.PICKUP.fn

		local function newPICKUPfn(act)
			_actionPickupFn(act)
			print("[TAKDEBUG]  NewActionWorking!")
		end
		ACTIONS.PICKUP.fn = newPICKUPfn
	end
end
AddPrefabPostInit("tak", _overrideActionPickupFn)

Any thoughts here? I am sure it's something silly, but I cant figure it out!

Edited by mrboosch
Link to comment
Share on other sites

I'm not that experienced with modding actions yet, but if I did not overlooked bugs, it also should work like this (code is in my questmod api in modmain (so without addprefabpostinit)):

local _LOOKATfn = GLOBAL.ACTIONS.LOOKAT.fn
GLOBAL.ACTIONS.LOOKAT.fn = function(act)
    local targ = act.target or act.invobject
    if targ~= nil then
        targ:PushEvent("questmod:examined",{player=act.doer})
        if targ:HasTag("questgiver") and targ.components and targ.components.talker and targ:GetDistanceSqToInst(act.doer) <= math.pow(10,2) then -- if directly next to a questgiver, not the player should say sth, but the questgiver
            return -- no examination talking
        else
            return _LOOKATfn(act)
        end
    end
    return _LOOKATfn(act)
end

 

Edited by Serpens
Link to comment
Share on other sites

@Serpens Thank you very much for your reply! Going the route you proposed* does give me the 'only call it once' behavior I was looking for!

 

Now evidently I just need to find out what the heck is wrong with my execution logic - haha!

Many thanks for your insight.

Regards,

Mr Boosch

* for others: by this I meant removing the prefabpostinit call and executing all logic as part of modmain

Edited by mrboosch
Link to comment
Share on other sites

OK so, @Serpens @Lumina thank you both for assisting a newer modder :) 

Interesting side point - Firefox browser does not appear to recognize that a user can edit old posts - the edit button only appears next to a post immediately after it has been posted, then upon logging out and back in, will no longer show. Go figure?!  Shows up fine in Chrome, so I've edited the topic.

Many thanks!

Link to comment
Share on other sites

11 minutes ago, mrboosch said:

OK so, @Serpens @Lumina thank you both for assisting a newer modder :) 

Interesting side point - Firefox browser does not appear to recognize that a user can edit old posts - the edit button only appears next to a post immediately after it has been posted, then upon logging out and back in, will no longer show. Go figure?!  Shows up fine in Chrome, so I've edited the topic.

Many thanks!

interesting... you could try to report this in bug section, but not sure if it is the right place...
I also use firefox, but I never log out :D I think I'm logged in since months :D

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