Physgunned = CollisionGroup 20

Hello.

I need help writing a script that sets the physgunned player to a specific Collision Group. It’s probably really simple for you who are good with LUA. I appreciate all help, thanks!

Run SetCollisionGroup on the entity in a

GM:PhysgunPickup hook

This is my current script I thought would work:
function PlayerPickup1( ply, ent )
if ent:IsPlayer() then ent:SetCollisionGroup(10)
end
hook.Add( “PhysgunPickup”, “Allow Player Pickup”, PlayerPickup1 )

What is wrong?

You are missing an end. Also, use local functions, and enums for SetCollisionGroup. Ex.


hook.Add("PhysgunPickup", "PickupCollision", function(_, ent)
   if (ent:IsPlayer()) then
      ent:SetCollisionGroup(COLLISION_GROUP_IN_VEHICLE)
   end
end)

I think I posted too little information.

I want to create a script that makes physgunned player able to be moved through WORLD and props. So when I grab someone and noclip, I can go through stuff instead of over. Is that possible?
Your script worked in the way I firstly described it though, thanks.

I’m not sure if there’s a collision group for that – you can try playing around with them and see the different effects.

Wouldn’t it be possible to make the physgunned player put in noclip state once grabbed, so the one who is physgunning is techinally controlling the noclip?

Oh yeah, you can do ent:SetMoveType(MOVETYPE_NOCLIP)

This is my current script:


local oldgroups = {}

hook.Add("PhysgunPickup", "TSE_PhysgunPickup", function(ply, ent)
    if ent and IsValid(ent) and ent:IsPlayer() then
        oldgroups[ply] = ent:GetCollisionGroup()
        ent:SetCollisionGroup(some group here)
    end
end)

hook.Add("PhysgunDrop", "TSE_PhysgunDrop", function(ply, ent)
    if ent and oldgroups[ent] then
        ent:SetCollisionGroup(oldgroups[ent])
    end
end)

Would the new script then be:


local oldgroups = {}

hook.Add("PhysgunPickup", "TSE_PhysgunPickup", function(ply, ent)
    if ent and IsValid(ent) and ent:IsPlayer() then
        oldgroups[ply] = ent:GetMoveType()
        ent:SetMoveType(MOVETYPE_NOCLIP)
    end
end)

hook.Add("PhysgunDrop", "TSE_PhysgunDrop", function(ply, ent)
    if ent and oldgroups[ent] then
        ent:SetMoveType(MOVETYPE_NONE)
    end
end)



?

For checking if the ent is a player, you can just do ent:IsPlayer() – the hooks won’t ever provide you with an invalid entity. In PhysgunPickup, you are using the physgun-weilding player as the key entity for the oldgroups table when you should be using the target entity. Lastly, you are storing the movetype in oldgroups, but you are resetting it to MOVETYPE_NONE in PhysgunDrop instead of the previous movetype. Also, this code will cause issues if multiple people are physgunning one person.