Force player to drop physgun'd object

Hi,

Hopefully a quick question here:
How can I find out which player (if any) is holding an object with their physgun, and how can I force them to drop that object?

I know I can stop them from picking the object up in the first place using the PhysgunPickup hook, but I’d like to limit physgun usage to a certain area of a map, and so if a player tries to drag the object out of that area I need to force them to drop it.

Thanks,
Yoshie

[lua]function GM:PhysgunPickup( ply, ent )
return false
end[/lua]

This will basically disable pickup of anything, but you can use a hook aswell.
Posted it here just so you know that doing “return false/true” allows/disallows pickup.

That doesn’t really help me. I need to make the player drop something that they’re already holding.

You could just make it frozen.

Yeah, freeze it and then instantly unfreeze.
It’ll make the prop fall to the ground.

Or if someone is grabbing it, run -attack on him.

Commands like -attack, +duck and such don’t work via Player:ConCommand() or atleast they didn’t the last time I checked (about 4 months ago), but I doubt it has changed.

I took that approach in a gamemode I’m working on, ran -attack and removed their physgun. It created an issue of having to call :Wake() (might have been something else, maybe reset the collision group) on the physobject, otherwise it would drop to the floor and not move anymore.

I’ll try freezing and unfreezing it and see if that is any better.

[editline]4th February 2014[/editline]

They work fine, you can freak people out by randomly running commands on them, make them think they’re computer is possessed (or keyboard broke :P)

Have you actually tried it? I want some proof :3

I actually did it a while ago as well.

If 2 people say so, then it must be true.
Alright.

So what you guys are saying is that doing something like this should work?



function dropObject(ent)
    local movetype = ent:GetMoveType()
    ent:SetMoveType(MOVETYPE_NONE)
    ent:SetMoveType(movetype)
    ent:Wake()
end


It’s an ugly solution but I guess it’s all I’ve got to work with. Is there any way to determine if a player is currently holding the object and if so, whom?

Thanks!