Can unfreeze check?

I’m working on a propertey menu script and I can’t quite figure out how to check if a player is allowed to unfreeze an entity in relation to prop protection.

The code I tried to use was !gamemode.Call( “CanPlayerUnfreeze”, ply, ent) but it doesnt seem to work.

Does GM:CanPlayerUnfreeze(ply, ent) exist in the gamemode?

Are you missing the third argument “PhysObj” / “phys”?

I found it in the sandbox gamemode, however it always returns true in the gamemode, but I thought the prop protection may take action against that

[editline]19th November 2016[/editline]

Oh you are right, i am missing the phys object, ill try that out

Prop protection is usually implemented in terms of hooks with hook.Add, gamemode.Call will only call the gamemode function.

You’re probably looking for

hook.Run

-snip- nvm

Ok i am using the following to the filter function:


Filter = function( self, ent, ply )

	if !hook.Run( "CanPlayerUnfreeze", ply, ent, ent:GetPhysicsObject()) && IsValid(ent:GetOwner()) then return false end
	if ( !IsValid( ent ) ) then return false end
	if ( ent:IsPlayer() ) then return false end


	return true

end

With the following code in the Recieve function


if ( !self:Filter( ent, player ) ) then return false end

it still doesnt seem to be working.

Thought i might post the full code, in case im doing something else wrong.


AddCSLuaFile()

local function Dbg(Message)
	//print("[UFAP] " .. Message)
end

print("UFAP loaded")

properties.Add( "unfreezeallproperty", {
	MenuLabel = "Unfreeze All",
	Order = 2,
	MenuIcon = "icon16/layers.png",
	//MenuIcon = "icon16/control_play_blue.png",

	Filter = function( self, ent, ply )

		if !hook.Run( "CanPlayerUnfreeze", ply, ent, ent:GetPhysicsObject()) && IsValid(ent:GetOwner()) then return false end
		if ( !IsValid( ent ) ) then return false end
		if ( ent:IsPlayer() ) then return false end


		return true

	end,

	Action = function( self, ent )

		self:MsgStart()
			net.WriteEntity( ent )
		self:MsgEnd()

	end,

	Receive = function( self, length, player )

		local ent = net.ReadEntity()

		if ( !IsValid( ent ) ) then return false end
		if ( !IsValid( player ) ) then return false end
		if ( ent:IsPlayer() ) then return false end
		if ( !self:Filter( ent, player ) ) then return false end

		local Ents = constraint.GetAllConstrainedEntities( ent )
		local UnfrozenObjects = 0

		for k, ent in pairs( Ents ) do
			local objects = ent:GetPhysicsObjectCount()
			for i=1, objects do
				local physobject = ent:GetPhysicsObjectNum( i - 1 )
				physobject:EnableMotion( true )
				physobject:Wake()
			end
		end

	end

} )