Freeze Prop

Hi,

I spawn props via lua with this code:



function SpawnProp(position, model)
	local ent1 = ents.Create("prop_physics") 
	local ang = Vector(0,0,1):Angle();
	ent1:SetAngles(ang)
	ent1:SetModel(model)
	local pos = position
	pos.z = pos.z - ent1:OBBMaxs().z
	ent1:SetPos( pos )
	ent1:SetSolid(SOLID_VPHYSICS)
	ent1:SetMoveType(MOVETYPE_NONE)
	ent1:Spawn()
	local l = ent1:GetPhysicsObject()
    if l:IsValid() then
        l:EnableMotion(false)
		l:Sleep(false) 
    end
end


But the prop is still “unfreezeable” with the phys gun, any way to block this?

Thanks

Here’s the structure of what I use for restricting entity interaction with the physgun:

[lua]
hook.Add( “PhysgunPickup”, “PhysgunRestriction”, function( ply, ent )

if ( ent:GetName() == "blah" ) then return false end

end )

hook.Add( “CanPlayerUnfreeze”, “PhysgunRestriction”, function( ply, entity, physobject )

if ( ent:GetName() == "blah" ) then return false end

end )
[/lua]

What you could do is set the entity’s name to something and then in these two hooks check if the entity being interacted with is that name and if so return false. You could also use the Garry’s Mod persistence system and simply add ent1:SetPersistent(true) to your code so you don’t have to do any more with hooks.

Any other possibility ?

You could also set a var on the prop itself:

if ent.ShouldFreezeBeBlocked then

Both of these should work:

[lua]
function SpawnProp(position, model)
local ent1 = ents.Create(“prop_physics”)
ent1:SetName(“StaticProp”)
local ang = Vector(0,0,1):Angle();
ent1:SetAngles(ang)
ent1:SetModel(model)
local pos = position
pos.z = pos.z - ent1:OBBMaxs().z
ent1:SetPos( pos )
ent1:SetSolid(SOLID_VPHYSICS)
ent1:SetMoveType(MOVETYPE_NONE)
ent1:Spawn()
local l = ent1:GetPhysicsObject()
if l:IsValid() then
l:EnableMotion(false)
l:Sleep(false)
end
end

hook.Add(“PhysgunPickup”, “PhysgunRestriction”, function(ply, ent)
if (ent:GetName() == “StaticProp”) then return false end
end)

hook.Add(“CanPlayerUnfreeze”, “PhysgunRestriction”, function(ply, entity, physobject)
if (ent:GetName() == “StaticProp”) then return false end
end)
[/lua]

or

[lua]
function SpawnProp(position, model)
local ent1 = ents.Create(“prop_physics”)
ent1:SetPersistent(true)
local ang = Vector(0,0,1):Angle();
ent1:SetAngles(ang)
ent1:SetModel(model)
local pos = position
pos.z = pos.z - ent1:OBBMaxs().z
ent1:SetPos( pos )
ent1:SetSolid(SOLID_VPHYSICS)
ent1:SetMoveType(MOVETYPE_NONE)
ent1:Spawn()
local l = ent1:GetPhysicsObject()
if l:IsValid() then
l:EnableMotion(false)
l:Sleep(false)
end
end
[/lua]

Thanks the second thing worked well :slight_smile:

Last think, i use a tool to make props indestructible:



function TOOL:LeftClick( trace )
	
	if SERVER then
		local ent = trace.Entity
	
		if ent:IsValid() then
			
			if self:GetOwner():IsAdmin() then
				ent.HealthMade = nil
				ent.org_health = ent:GetMaxHealth()
				ent:SetSaveValue("m_takedamage", 0)
				ent:SetHealth(-1)
			end
			
		end
	end
end



So i tried to include this into my function, but it dosent works. Any idea how bring this to work?
Just a try:



	ent1:SetSolid(SOLID_VPHYSICS)
	ent1:SetMoveType(MOVETYPE_NONE)
	ent1:SetSaveValue("m_takedamage", 0)
        ent1:SetHealth(9999)
	ent1:SetMaxHealth(9999)
	ent1:Spawn()