way to know if a player is holding or not an object

Hi, i’m new on gmoding and on this forum too.

I know the basics but i can’t find a way to know if a player is holding or not an object (using use key).
There is the function Player/DropObject and Player/PickupObject but i found nothing such as “Player/IsHoldingObject”.

Can you help me with this please?
Thanks :slight_smile:

I don’t think a function that you need actually exists. I guess one (hacky) way to check it would be to get the entity the player is looking at and checking if it is picked up with Entity:IsPlayerHolding().

Thanks, I’m gonna try to do it with that function then. Too bad there is no easy way ):

Could also store some variables. It is not flawless as there could be a mod that blocks “AllowPlayerPickup” after it have stored the variables.



hook.Add( "AllowPlayerPickup", "some_unique_name", function( ply, ent )
	ply.LastPickupEnt = ent
	ent.LastPickupPly = ply
end )
function isPlayerHolding(ply)
	if !ply.LastPickupEnt then return false end
	if !IsValid(ply.LastPickupEnt) then return false end
	local ent = ply.LastPickupEnt -- Entity is valid
	if ent.LastPickupPly!=ply then return false end -- Last player to pick the ent up have to match
	return ply.LastPickupEnt:IsPlayerHolding() -- Still holding the ent?
end