Freeze Cars Code not working

So, I am co-owner on a server, we have vcmod, and it will not allow us to pick up cars. I solved that problem with a hook, but, we can’t freeze them.

Any suggestions? This is my attempt’d hook to freeze them with physgun.


hook.Add( "OnPhysgunFreeze", "PhysFreeze", function( weapon, phys, ent, ply )

 	if ply:IsAdmin() and (ent:GetClass():lower() == "func_door" or ent:GetClass():lower() == "player") then
		return false
	elseif ply:IsSuperAdmin() then
		return true
	end

end )

You can’t freeze prop_vehicle_jeeps iirc. Something about crashing Linux builds or something.

Yes, i’ve heard of it, but i’ve seen other servers freezing cars that were prop_vehicle_jeep

So i just wanted to know.

You saw server making that ? I never saw that. However I have an idea, maybe you can hack Garry’s Mod Application using Visual C++, but it would make your code to be platform dependent. And you’ll need a Source lcence to know what are the functions you need to call.

This should do the trick, the car won’t actually be frozen but it will drive EXTREMELY slowly.



hook.Add("OnPhysgunFreeze", "FreezeVehicles", function( weapon, phys, ent, ply )
     if (ply:IsSuperAdmin() and ent:IsVehicle()) then
        ent.frozen = !ent.frozen or true
    end
end)

hook.Add("Think", "FreezeFrozenVehicles", function()
     for k, v in pairs(ents.GetAll()) do
        if (v:IsVehicle() and v.frozen) then
            local phys = v:GetPhysicsObject()
            if (phys:IsValid()) then
                phys:SetVelocity(phys:GetVelocity() * -1)
            end
        end
    end
end)


Oh wait I have an idea, don’t know if this works, but I give you :



function GM:OnPhysgunFreeze(weap, obj, ent, ply)
if (ent:GetClass() == "prop_vehicle_jeep") then
if (ent.FrozenPos == nil) then
ent.FrozenPos = ent:GetPos()
else
ent.FrozenPos = nil
end
end
end
function GM:Think()
for k, v in pairs(ents.GetAll()) do
if (IsValid(v) && v:GetClass()=="prop_vehicle_jeep" && v.FrozenPos != nil) then
v:SetPos(v.FrozenPos)
end
end
end


Made with my iPad so excuse me if code isn’t clean, I’m not at my home desk for the moment !

[editline]4th May 2015[/editline]

So, i’m back on computer and I accidentally made a engine.Shutdown !

Not using any blocked command, just a simple thing : when freeze vehicle, I entity:PhysicsInit(SOLID_NONE) and then wow server shuts down with windows saying it has stopped working…

Why not just weld it to something?

Not nessessary : found a way : destroy your vehicle spawn a prop_physics with same model/skin/color/everything and save all vehicle data on this prop. Don’t forget to EnableMotion(false) on it.
Then when you pickup back you frozen fake vehicle, despawn it and immediatly spawn back the real vehicle with the saved properties on your physics_prop. That makes exactly the same thing as freezeing a vehicle in odler GMod.

Alright well thanks for the help, I guess it is not possible. Oh well.

Thanks again.

And what if it had a passenger in it?

You could make the passenger simply exit the vehicle upon it being frozen. Well, that could cause some trolling issues, but seems like the only way.

A frozen prop welded to the vehicle seems like the best idea to me =p

Or to make it even simpler, weld it to the world entity.

Never considered that :wink:

The weld idea as well as the set position in loop and even the SetParent won’t work (already tried).
So when you set pos in loop this creates a bug because the vehicle seams to have a SetVelocity(0, 0, -1) in the c base entity. And when you parent it, it disappears. When you try to remove the physics component of this entity this is equivalent to engine.Shutdown(). The weld to world is simply canceled.
However the weld to prop (physics one otherwise does not work) then weld to world is working, however the vehicle is still movable : weld is in all cases broken as well as fixed joins in Unity.

And about the bug if a player would not exit the vehicle, well you can always do something, create your own physics prop, in which you can add seats and make player seat down. Or you can exit them from vehicle.

Welding the vehicle to keep it in place works just fine. There’s no reason to make it complicated with replacing entities and what else your ideas are.

Weld directly to world does not work for me…