2026-04-14 17:41:39 +02:00

85 lines
2.7 KiB
Lua

local JailData = nil
-- Functions
function UnJailPlayer()
TriggerServerEvent("mAdmin:server:DeleteData", JailData, "Delete")
JailData = nil
local JailExitCoords = Config.Jail.JailExitCoords
SetEntityCoords(GetPlayerPed(PlayerId()), JailExitCoords.x, JailExitCoords.y, JailExitCoords.z)
end
function AddTime()
JailData.currentTime = JailData.currentTime + 1
if JailData.currentTime >= JailData.jailTime then
UnJailPlayer()
end
end
function CheckCoords()
local PlayerPed = GetPlayerPed(PlayerId())
local CurrentCoords = GetEntityCoords(PlayerPed)
local JailCoords = Config.Jail.JailCoords
if #(JailCoords.xy - CurrentCoords.xy) >= Config.Jail.ControlDistance then
SetEntityCoords(PlayerPed, JailCoords.x, JailCoords.y, JailCoords.z)
Config.Functions.SendNotify("You tried to escape from prison!", true, "client")
end
end
function StartTimer()
Citizen.CreateThread(function()
while JailData do
Wait(1000)
if JailData ~= nil then
AddTime()
CheckCoords()
end
end
end)
end
-- Events
RegisterNetEvent("mAdmin:client:JailPlayerOnJoin", function(data)
Config.Functions.SendNotify("You've been jailed again because of quitting game.", true, "client")
JailData = data
local JailCoords = Config.Jail.JailCoords
SetEntityCoords(GetPlayerPed(PlayerId()), JailCoords.x, JailCoords.y, JailCoords.z)
StartTimer()
end)
RegisterNetEvent("mAdmin:client:jailPlayer", function(time, reason, key)
local PermissionCheck = LV.CheckPermission(key, "Players", 7)
if PermissionCheck == false then return end
JailData = {
jailTime = tonumber(time) * 60,
currentTime = 0,
identifier = LV.GetIdentifier(),
source = GetPlayerServerId(PlayerId()),
reason = reason
}
local JailCoords = Config.Jail.JailCoords
SetEntityCoords(GetPlayerPed(PlayerId()), JailCoords.x, JailCoords.y, JailCoords.z)
TriggerServerEvent("mAdmin:server:PushJailData", JailData, key)
StartTimer()
end)
RegisterNetEvent("mAdmin:client:unjailPlayer", function(key)
local PermissionCheck = LV.CheckPermission(key, "Players", 7)
if PermissionCheck == false then return end
UnJailPlayer()
end)
-- Commands
RegisterCommand(Config.Jail.JailCheckCommand, function()
if JailData then
local remaining = string.format("%.1f", (JailData.jailTime - JailData.currentTime) / 60)
Config.Functions.SendNotify("You have "..remaining.." months.\nReason: "..JailData.reason, false, "client")
else
Config.Functions.SendNotify("You're not in jail.", true, "client")
end
end, false)