Author Topic: Making jails in minutes  (Read 5380 times)

0 Members and 1 Guest are viewing this topic.

Offline TwInKiEmAn

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Making jails in minutes
« on: August 20, 2019, 03:49:38 PM »
Hello, so basically I would like to change jail and jailtp times from seconds to minutes
I went and changed everything in here where it said seconds to minutes, would this work or no?
Code: [Select]
local doJail
local jailableArea
function ulx.jail( calling_ply, target_plys, minutes, should_unjail )
local affected_plys = {}
for i=1, #target_plys do
local v = target_plys[ i ]

if not should_unjail then
if ulx.getExclusive( v, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
elseif not jailableArea( v:GetPos() ) then
ULib.tsayError( calling_ply, v:Nick() .. " is not in an area where a jail can be placed!", true )
else
doJail( v, minutes )

table.insert( affected_plys, v )
end
elseif v.jail then
v.jail.unjail()
v.jail = nil
table.insert( affected_plys, v )
end
end

if not should_unjail then
local str = "#A jailed #T"
if minutes > 0 then
str = str .. " for #i minutes"
end
ulx.fancyLogAdmin( calling_ply, str, affected_plys, minutes )
else
ulx.fancyLogAdmin( calling_ply, "#A unjailed #T", affected_plys )
end
end
local jail = ulx.command( CATEGORY_NAME, "ulx jail", ulx.jail, "!jail" )
jail:addParam{ type=ULib.cmds.PlayersArg }
jail:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="minutes, 0 is forever", 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:setOpposite( "ulx unjail", {_, _, _, true}, "!unjail" )

------------------------------ Jail TP ------------------------------
function ulx.jailtp( calling_ply, target_ply, minutes )
local t = {}
t.start = calling_ply:GetPos() + Vector( 0, 0, 32 ) -- Move them up a bit so they can travel across the ground
t.endpos = calling_ply:GetPos() + calling_ply:EyeAngles():Forward() * 16384
t.filter = target_ply
if target_ply ~= calling_ply then
t.filter = { target_ply, calling_ply }
end
local tr = util.TraceEntity( t, target_ply )

local pos = tr.HitPos

if ulx.getExclusive( target_ply, calling_ply ) then
ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
return
elseif not target_ply:Alive() then
ULib.tsayError( calling_ply, target_ply:Nick() .. " is dead!", true )
return
elseif not jailableArea( pos ) then
ULib.tsayError( calling_ply, "That is not an area where a jail can be placed!", true )
return
else
target_ply.ulx_prevpos = target_ply:GetPos()
target_ply.ulx_prevang = target_ply:EyeAngles()

if target_ply:InVehicle() then
target_ply:ExitVehicle()
end

target_ply:SetPos( pos )
target_ply:SetLocalVelocity( Vector( 0, 0, 0 ) ) -- Stop!

doJail( target_ply, minutes )
end

local str = "#A teleported and jailed #T"
if minutes > 0 then
str = str .. " for #i minutes"
end
ulx.fancyLogAdmin( calling_ply, str, target_ply, minutes )
end
local jailtp = ulx.command( CATEGORY_NAME, "ulx jailtp", ulx.jailtp, "!jailtp" )
jailtp:addParam{ type=ULib.cmds.PlayerArg }
jailtp:addParam{ type=ULib.cmds.NumArg, min=0, default=0, hint="minutes, 0 is forever", ULib.cmds.round, ULib.cmds.optional }
jailtp:defaultAccess( ULib.ACCESS_ADMIN )
jailtp:help( "Teleports, then jails target(s)." )

local function jailCheck()
local remove_timer = true
local players = player.GetAll()
for i=1, #players do
local ply = players[ i ]
if ply.jail then
remove_timer = false
end
if ply.jail and (ply.jail.pos-ply:GetPos()):LengthSqr() >= 6500 then
ply:SetPos( ply.jail.pos )
if ply.jail.jail_until then
doJail( ply, ply.jail.jail_until - CurTime() )
else
doJail( ply, 0 )
end
end
end

if remove_timer then
timer.Remove( "ULXJail" )
end
end

jailableArea = function( pos )
entList = ents.FindInBox( pos - Vector( 35, 35, 5 ), pos + Vector( 35, 35, 110 ) )
for i=1, #entList do
if entList[ i ]:GetClass() == "trigger_remove" then
return false
end
end

return true
end

local mdl1 = Model( "models/props_building_details/Storefront_Template001a_Bars.mdl" )
local jail = {
{ pos = Vector( 0, 0, -5 ), ang = Angle( 90, 0, 0 ), mdl=mdl1 },
{ pos = Vector( 0, 0, 97 ), ang = Angle( 90, 0, 0 ), mdl=mdl1 },
{ pos = Vector( 21, 31, 46 ), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( 21, -31, 46 ), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( -21, 31, 46 ), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( -21, -31, 46), ang = Angle( 0, 90, 0 ), mdl=mdl1 },
{ pos = Vector( -52, 0, 46 ), ang = Angle( 0, 0, 0 ), mdl=mdl1 },
{ pos = Vector( 52, 0, 46 ), ang = Angle( 0, 0, 0 ), mdl=mdl1 },
}
doJail = function( v, minutes )
if v.jail then -- They're already jailed
v.jail.unjail()
end

if v:InVehicle() then
local vehicle = v:GetParent()
v:ExitVehicle()
vehicle:Remove()
end

-- Force other players to let go of this player
if v.physgunned_by then
for ply, v in pairs( v.physgunned_by ) do
if ply:IsValid() and ply:GetActiveWeapon():IsValid() and ply:GetActiveWeapon():GetClass() == "weapon_physgun" then
ply:ConCommand( "-attack" )
end
end
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:SetMoveType( MOVETYPE_NONE )
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:DisallowMoving( false )
v:DisallowSpawning( false )
v:DisallowVehicles( false )

ulx.clearExclusive( v )
ulx.setNoDie( v, false )

v.jail = nil
end
if minutes > 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:DisallowMoving( true )
v:DisallowSpawning( true )
v:DisallowVehicles( true )
v.jail = { pos=pos, unjail=unjail, key=key }
if minutes > 0 then
v.jail.jail_until = CurTime() +minutes
end
ulx.setExclusive( v, "in jail" )
ulx.setNoDie( v, true )

timer.Create( "ULXJail", 1, 0, jailCheck )
end

local function jailDisconnectedCheck( ply )
if ply.jail then
ply.jail.unjail()
end
end

Offline mark272

  • Newbie
  • *
  • Posts: 16
  • Karma: 5
Re: Making jails in minutes
« Reply #1 on: August 20, 2019, 04:04:43 PM »
You only changed a Variable name and some words in strings? No this way it wouldn’t work.
Just add a simple calculation. seconds multiplied by 60

Offline TwInKiEmAn

  • Newbie
  • *
  • Posts: 6
  • Karma: 0
Re: Making jails in minutes
« Reply #2 on: August 20, 2019, 04:11:17 PM »
lol im stupid. where would I insert that calculation?

Offline mark272

  • Newbie
  • *
  • Posts: 16
  • Karma: 5
Re: Making jails in minutes
« Reply #3 on: August 20, 2019, 04:33:09 PM »
doJail( v, minutes*60 )
Should work. I did it on my iPad so yeah it may not work.
Basically you just need to add the *60
« Last Edit: August 20, 2019, 04:36:19 PM by mark272 »