Well here's the code i made, replaces every jail string with a cage one, don't know if it works, im going to start making it to addon form.
What do you think ? Give me tips how to get it working/improve it.
Notice: My first ever LUA, and my second leeched from another LUAs.
------------------------------ Jail ------------------------------
function ulx.cage( calling_ply, target_plys, seconds, should_uncage ) --Renamed to ulx.cage from ulx.jail and should_unjail to should_uncage
local mdl1 = Model( "models/props_wasteland/interior_fence002d.mdl" ) --Changed mdl1 "models/props_c17/fence01b.mdl" to models/props_wasteland/interior_fence002d.mdl
local mdl2 = Model( "models/props_wasteland/interior_fence002d.mdl" ) --Changed mdl1 "models/props_c17/fence01b.mdl" to models/props_wasteland/interior_fence002d.mdl
local cage = {
{ pos = Vector( 0, 0, 0 ), ang = Angle( -0.032495182007551, -90.190528869629, 0.156479626894 ), mdl=mdl2 }, --All vectors and angles changed, will need to add 2 mroe if these work
{ pos = Vector( 129.97778320313, -127.38626098633, -0.13224792480469 ), ang = Angle( 0.12636932730675, 179.84873962402, 0.025045685470104 ), mdl=mdl2 },
{ pos = Vector( 2.905517578125, -258.35272216797, -0.79289245605469 ), ang = Angle( -3.4093172871508, -90, 5.7652890973259 ), mdl=mdl2 },
{ pos = Vector( -123.9228515625, -127.88626098633, -1.0640182495117 ), ang = Angle( -0.00059019651962444, 179.99681091309, 359.99996948242 ), mdl=mdl2 },
{ pos = Vector( -63.728271484375, -129.30960083008, -63.381893157959 ), ang = Angle( -89.999015808105, -179.42805480957, 180 ), mdl=mdl1 },
{ pos = Vector( 62.65771484375, -131.56051635742, -63.381889343262 ), ang = Angle( -89.999015808105, 179.91276550293, 180 ), mdl=mdl1 },
}
local i = 1
while i <= #target_plys do
local v = target_plys[ i ]
if not should_uncage then
if v.cage then -- They're already jailed
v.cage.uncage()
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( cage ) 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.cageWall = true
table.insert( walls, ent )
end
local key = {}
local function uncage() --Changed unjail to -cage
if not v:IsValid() or not v.cage or v.cage.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 )
ulx.setNoDie( v, false )
v.cage = nil
end
if seconds > 0 then
timer.Simple( seconds, uncage ) --Changed unjail to -cage
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.cage = { pos=pos, uncage=uncage, key=key }
ulx.setExclusive( v, "in cage" )
ulx.setNoDie( v, true )
i = i + 1
end
elseif v.cage then
v.cage.uncage()
v.cage = nil
i = i + 1
else
table.remove( target_plys, i )
end
end
return #target_plys > 0
end
local cage = ulx.command( CATEGORY_NAME, "ulx cage", ulx.cage, "!cage" )
cage:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
cage:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="seconds, forever is 0", ULib.cmds.round, ULib.cmds.optional }
cage:addParam{ type=ULib.cmds.BoolArg, invisible=true }
cage:defaultAccess( ULib.ACCESS_ADMIN )
cage:help( "Cages target(s)." )
cage:logString( "#1s caged #2s for #3i seconds" )
cage:setOpposite( "ulx uncage", {_, _, _, true}, "!uncage" )
cage:oppositeLogString( "#1s uncaged #2s" )
ulx.addToMenu( ulx.ID_MCLIENT, "Cage", "ulx cage" )
ulx.addToMenu( ulx.ID_MCLIENT, "Uncage", "ulx uncage" )
local function cageDisconnectedCheck( ply )
if ply.cage then
ply.cage.uncage()
end
end
hook.Add( "PlayerDisconnected", "ULXCageDisconnectedCheck", cageDisconnectedCheck )