Jump to content

Recommended Posts

How can I check player press CTRL key ?

I've tried doer.components.playercontroller:IsControlPressed(GLOBAL.CONTROL_FORCE_STACK) but it's not work in GLOBAL.ACTIONS.DROP.fn but it's work in GLOBAL.ACTIONS.DROP.strfn.

Here is my code:

local oldactiondrop = GLOBAL.ACTIONS.DROP.fn
GLOBAL.ACTIONS.DROP.fn = function(act)
	if act.invobject:HasTag("trap") and act.doer.components.playercontroller:IsControlPressed(GLOBAL.CONTROL_FORCE_STACK) then
		-----------------NOT WORK-----------------
		return act.doer.components.inventory ~= nil and act.doer.components.inventory:DropItem(act.invobject,true,false,act.pos) or nil		
	end
	return oldactiondrop(act)
end	

local oldactiondropstr = GLOBAL.ACTIONS.DROP.strfn   
GLOBAL.ACTIONS.DROP.strfn = function(act)
	if act.invobject:HasTag("trap") and act.doer.components.playercontroller:IsControlPressed(GLOBAL.CONTROL_FORCE_STACK) then
        -----------------WORK-----------------
		return "DROPALL"
	end	
	return oldactiondropstr(act)
end

 

 

 

I'd guess that's because actions (i.e. their fn) run on the server (thus don't have access to player's controller), but actions' descriptions (i.e. their strfn) run on the client.

If am I not mistaken, widgets/invslot does this modifier key distinguishing on the client as well and then sends different RPCs based on what should be done (see prefabs/container_classified.lua).

If you are creating you own actions+component actions, you could try checking for pressed CTRL in component action and based on CTRL status add different action into the actions table.

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