Prop Ghosting when your PhysGunning it?

I’ve searched endlessly for this script, but I can’t find it.
What I want is, when you physgun a prop, it gets ghosted so you can’t prop minge.

Any solutions? I’ve tried FPP, can’t find the option.

You could use this to change the entity colour, making it translucent and changing it’s collision group:

Then after it has been dropped set it back to what it was:

The option in FPP has just been removed. It was buggy.

This should work, hasn’t been tested. Try both server and client side before saying it doesn’t work.

[lua]
function GM:OnPhysgunPickup(ent, mdl)
if ent:IsWorld() or ent:IsPlayer() then return false end
ent:SetColor(255,255,255,200)
end

function GM:OnPhysgunDrop(ent, mdl)
if ent:IsWorld() or ent:IsPlayer() then return false end
ent:SetColor(255,255,255,255)
end
[/lua]

All that does is change the transparency.



function GM:OnPhysgunPickup(ent, mdl)
     if ent:IsWorld() or ent:IsPlayer() then return false end
     ent:SetColor(255,255,255,150)
     ent:GetPhysicsObject():EnableCollisions(true)
end
 
function GM:OnPhysgunDrop(ent, mdl)
     if ent:IsWorld() or ent:IsPlayer() then return false end
     ent:SetColor(255,255,255,255)
     ent:GetPhysicsObject():EnableCollisions(true)
end


That should work anyway, stole mdews code :slight_smile:

Theres no difference in the lua blocks after the functions at all, shouldn’t the first one be

[lua] ent:GetPhysicsObject():EnableCollisions(false) [/lua]

?



function GM:OnPhysgunPickup(ent, mdl)
     if ent:IsWorld() or ent:IsPlayer() then return false end
     ent:SetColor(255,255,255,150)
     ent:GetPhysicsObject():EnableCollisions(false)
end
 
function GM:OnPhysgunDrop(ent, mdl)
     if ent:IsWorld() or ent:IsPlayer() then return false end
     ent:SetColor(255,255,255,255)
     ent:GetPhysicsObject():EnableCollisions(true)
end
 
There we go!

So do I just put this into a random.lua file and stuff it in autorun?
If it’s a specific lua, could you state that? Thanks alot fp.

[editline]6th November 2010[/editline]

Well adding on, putting it in autorun it can’t index GM, returning as a nil value.

The GM stands for gamemode, if you’re not making a gamemode then you just have to do it like hook.Add(“OnPhysgunDrop”, …

Should work, untested.

[lua]function REQOnPhysgunPickup(ent, mdl)
if ent:IsWorld() or ent:IsPlayer() or ent:IsNpc() or ent:IsBot() then return false end
ent:SetColor(255,255,255,150)
ent:GetPhysicsObject():EnableCollisions(false)
end

function REQOnPhysgunDrop(ent, mdl)
if ent:IsWorld() or ent:IsPlayer() or ent:IsNpc() or ent:IsBot() then return false end
ent:SetColor(255,255,255,255)
ent:GetPhysicsObject():EnableCollisions(true)
end

hook.Add( “OnPhysgunPickup”, “REQOnPhysgunPickup”, REQOnPhysgunPickup)
hook.Add( “OnPhysgunDrop”, “REQOnPhysgunDrop”, REQOnPhysgunDrop) [/lua]

put it in garrysmod/garrysmod/lua/autorun/server/random.lua

As an addon on singleplayer, the above script does not work.

Well I’ve never tested anything in singleplayer before, any errors?

EDIT: my fault for copying the code blocks above, the function was wrong.
EDIT2: the parameters were also wrong, sigh, use the following edited code.
EDIT3: this makes it shorter, really…should be last edit.

[lua]
local valobject = ent:GetPhysicsObject()

function REQPhysgunPickup(ply, ent)
if !valobject:IsValid() then return false end
ent:SetColor(255,255,255,150)
valobject:EnableCollisions(false)
end

function REQPhysgunDrop(ply, ent)
if !valobject:IsValid() then return false end
ent:SetColor(255,255,255,255)
valobject:EnableCollisions(false)
end

hook.Add( “PhysgunPickup”, “REQPhysgunPickup”, REQPhysgunPickup)
hook.Add( “PhysgunDrop”, “REQPhysgunDrop”, REQPhysgunDrop)[/lua]

Just put mine in like cl_init.lua in your gamemodes folder… It’s a lot easier.

Not working for me.

If you had read my post you would know yours wouldn’t have worked, and I’ll tell you why:

OnPhysgunDrop/Pickup is NOT a function.

what you defined as “ent” was actually a player, so you were trying to check if a player was the world or a player, and then if it wasn’t try to set the colour and the collision for that player (I assume player is the one holding the physgun)

@ mdew355
Doesn’t work in cl_init @ single player
@ zeph
Doesn’t work in lua/autorun/server

Then give me the errors that pop up in your console, saying it doesn’t work doesn’t help me as much as the errors would.

Zephilinox you putted valobject outside the hook, and the ‘ent’ object does not exist yet, put it inside the hook.

Just download source dedicated server and install Garry’s Mod in it. If you’re going to code lua scripts server-side you don’t want to do that in shitty single player.