------------------------------ Jail ------------------------------
function ulx.jail( calling_ply, target_plys, seconds, should_unjail )
local mdl1 = Model( "models/props_c17/fence01b.mdl" )
local mdl2 = Model( "models/props_c17/fence02b.mdl" )
local jail = {
{ pos = Vector( 35, 0, 60 ), ang = Angle( 0, 0, 0 ), mdl=mdl2 },
{ pos = Vector( -35, 0, 60 ), ang = Angle( 0, 0, 0 ), mdl=mdl2 },
{ pos = Vector( 0, 35, 60 ), ang = Angle( 0, 90, 0 ), mdl=mdl2 },
{ pos = Vector( 0, -35, 60 ), ang = Angle( 0, 90, 0 ), mdl=mdl2 },
{ pos = Vector( 0, 0, 110 ), ang = Angle( 90, 0, 0 ), mdl=mdl1 },
{ pos = Vector( 0, 0, -5 ), ang = Angle( 90, 0, 0 ), mdl=mdl1 },
}
local i = 1
while i <= #target_plys do
local v = target_plys[ i ]
if not should_unjail then
if v.jail then -- They're already jailed
v.jail.unjail()
end
if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
table.remove( target_plys, i )
else
if v:InVehicle() then
local vehicle = v:GetParent()
v:ExitVehicle()
vehicle:Remove()
end
if v:GetMoveType() == MOVETYPE_NOCLIP then -- Take them out of noclip
v:SetMoveType( MOVETYPE_WALK )
end
local pos = v:GetPos()
local walls = {}
for _, info in ipairs( jail ) do
local ent = ents.Create( "prop_physics" )
ent:SetModel( info.mdl )
ent:SetPos( pos + info.pos )
ent:SetAngles( info.ang )
ent:Spawn()
ent:GetPhysicsObject():EnableMotion( false )
ent.jailWall = true
table.insert( walls, ent )
end
local key = {}
local function unjail()
if not v:IsValid() or not v.jail or v.jail.key ~= key then -- Nope
return
end
for _, ent in ipairs( walls ) do
if ent:IsValid() then
ent:DisallowDeleting( false )
ent:Remove()
end
end
if not v:IsValid() then return end -- Make sure they're still connected
v:DisallowNoclip( false )
v:DisallowSpawning( false )
v:DisallowVehicles( false )
ulx.clearExclusive( v )
v.jail = nil
end
if seconds > 0 then
timer.Simple( seconds, unjail )
end
local function newWall( old, new )
table.insert( walls, new )
end
for _, ent in ipairs( walls ) do
ent:DisallowDeleting( true, newWall )
ent:DisallowMoving( true )
end
v:DisallowNoclip( true )
v:DisallowSpawning( true )
v:DisallowVehicles( true )
v.jail = { pos=pos, unjail=unjail, key=key }
ulx.setExclusive( v, "in jail" )
i = i + 1
end
elseif v.jail then
v.jail.unjail()
v.jail = nil
i = i + 1
else
table.remove( target_plys, i )
end
end
return #target_plys > 0
end
local jail = ulx.command( CATEGORY_NAME, "ulx jail", ulx.jail, "!jail" )
jail:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
jail:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="seconds, forever is 0", ULib.cmds.round, ULib.cmds.optional }
jail:addParam{ type=ULib.cmds.BoolArg, invisible=true }
jail:defaultAccess( ULib.ACCESS_ADMIN )
jail:help( "Jails target(s)." )
jail:logString( "#1s jailed #2s for #3i seconds" )
jail:setOpposite( "ulx unjail", {_, _, _, true}, "!unjail" )
jail:oppositeLogString( "#1s unjailed #2s" )
ulx.addToMenu( ulx.ID_MCLIENT, "Jail", "ulx jail" )
ulx.addToMenu( ulx.ID_MCLIENT, "Unjail", "ulx unjail" )
local function jailSpawnCheck( ply )
if ply.jail then
ply:SetPos( ply.jail.pos )
end
end
hook.Add( "PlayerSpawn", "ULXJailSpawnCheck", jailSpawnCheck )
local function jailDisconnectedCheck( ply )
if ply.jail then
ply.jail.unjail()
end
end
hook.Add( "PlayerDisconnected", "ULXJailDisconnectedCheck", jailDisconnectedCheck )
local function jailDamageCheck( ent )
if ent.spawnpointProp then
return false
end
end
hook.Add( "EntityTakeDamage", "ULXJailDamagedCheck", jailDamageCheck, -20 )