Grav Gun bug? With simple fix.

I noticed that entities lose all player interaction when the player dies while holding it with their Grav Gun. I checked a bunch of HL2 props and they screw up.

I removed all my addons just in case one was at fault but it still happened. I whipped this up and it fixes it.

[lua]local function GGFix_Death(ply)
local ent = ply.GGFEnt;
if (ValidEntity(ent)) then
DropEntityIfHeld(ent);
ent:SetOwner(nil);
ply.GGFEnt = nil;
end
end
hook.Add(“PlayerDeath”, “GravGunFix_PlayerDeath”, GGFix_Death);

local function GGFix_OnPickedUp(ply, ent)
ply.GGFEnt = ent;
end
hook.Add(“GravGunOnPickedUp”, “GravGunFix_OnPickedUp”, GGFix_OnPickedUp);

local function GGFix_OnDropped(ply, ent)
if (ValidEntity(ply.GGFEnt)) then
ply.GGFEnt = nil;
end
end
hook.Add(“GravGunOnDropped”, “GravGunFix_OnDropped”, GGFix_OnDropped);[/lua]

I wanted to make sure it wasn’t just my GMod.

Nice, this should be fixed in GMod in the next update.

What can’t you make/fix, Aska?

I’ve been looking for a fix for ages. In my gamemode, dieing while holding the flag resulted in nobody being able to pick it up anymore. Thanks :buddy:

I’ve never had (noticed) this issue.

Might as well try the glitch, and then try your script

Dlaor, that would make me rage so hard!!! Honestly, i didn’t know this glitch existed but hey, now it’s fixed!

Will this run in init.lua in a gamemode?

Yes.

Nice catch Aska, I usually notice small things like this but I have never before. I’ve also been seeing you a lot in the lua section recently, I hope you stay!