Is it really that difficult?
Just save the player's location and time, assuming the map doesn't change, and just put him back there and run the jail function.
That's not how ulx jail works. It uses curtime to determine it. Think of it this way.
Lets say I jail PLAYER1 for 60 seconds. He leaves at 30 seconds, so there is 30 seconds remaining, the way ULX jail is, there is just the number of how many seconds he was jailed for, then a curtime t determine when we'll get out.
So we need to determine how much time is left using CurTime, which is not hard and is completed, my issue is to set time back to zero if player left and rejoined, then when time was still counting, there seems to be a glitch with it, causing my reset to reset at the start, and I do not know why, because according to ULX, it should only be ran once.. but it is not.
Though at the same time, ulx enjoys being complicated when it comes down to it.
If you want to see my code, here, I give up:
Jail Code:------------------------------ Jail ------------------------------
local doJail
local jailableArea
function ulx.jail( calling_ply, target_plys, seconds, 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, seconds )
v:SetPData("UlxDBJail",seconds)
v:SetPData("UlxDBJailCurTime",math.Round(CurTime()))
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 seconds > 0 then
str = str .. " for #i seconds"
end
ulx.fancyLogAdmin( calling_ply, str, affected_plys, seconds )
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="seconds, 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" )
Other Codes (The initial spawn was created, the disconnected one was already there, so make sure to replace it and not make another disconnect or errors will occur)
local function jailDisconnectedCheck( ply )
local OldCurentTime = tonumber(ply:GetPData("UlxDBJailCurTime"))
local TotoalJailTime = tonumber(ply:GetPData("UlxDBJail"))
--if OldCurentTime == nil || TotoalJailTime == nil then return end
local RemaingTime = (math.Round(CurTime()) - OldCurentTime)
if TotoalJailTime > RemaingTime then
local NewJailTime = (TotoalJailTime - RemaingTime)
ply:SetPData("UlxDBJail",tonumber(NewJailTime))
ply:SetPData("UlxDBJailCurTime",math.Round(CurTime()))
MsgN(NewJailTime)
end
if ply.jail then
ply.jail.unjail()
end
end
hook.Add( "PlayerDisconnected", "ULXJailDisconnectedCheck", jailDisconnectedCheck )
function CheckULXJailAgain(ply)
timer.Simple(3,function()
local WhatTheTime = tonumber(ply:GetPData("UlxDBJail"))
if WhatTheTime == nil then return end
MsgN(WhatTheTime)
if WhatTheTime == 0 then
return
elseif WhatTheTime > 0 then
doJail(ply, WhatTheTime)
end
end)
end
hook.Add( "PlayerInitialSpawn", "CheckULXJailAgain", CheckULXJailAgain )