From 96f91bdeebdab22b462233a982b3cdf972b1479b Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:27:38 -0400 Subject: [PATCH 1/9] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index bdde073..d972322 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,9 @@ Let cops jail people! 4. Select language in `config.lua` 5. (Optional) See below on how to jail via `esx_policejob` +# Dependencies +oxmysql (I removed async since it was crap) + # How to jail - Use the `esx_jail:sendToJail(source, jailTime)` server side trigger From f57023ffebab327f16dd4556d93d90923064e15c Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:28:48 -0400 Subject: [PATCH 2/9] Update main.lua Updated for oxmysql --- server/main.lua | 50 ++++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/server/main.lua b/server/main.lua index 499f6ec..3bceed1 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,12 +1,7 @@ -ESX = nil local playersInJail = {} -TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - AddEventHandler('esx:playerLoaded', function(playerId, xPlayer) - MySQL.Async.fetchAll('SELECT jail_time FROM users WHERE identifier = @identifier', { - ['@identifier'] = xPlayer.identifier - }, function(result) + exports.oxmysql:execute('SELECT jail_time FROM users WHERE identifier = ?', { xPlayer.identifier }, function(result) if result[1] and result[1].jail_time > 0 then TriggerEvent('esx_jail:sendToJail', xPlayer.source, result[1].jail_time, true) end @@ -17,7 +12,8 @@ AddEventHandler('esx:playerDropped', function(playerId, reason) playersInJail[playerId] = nil end) -MySQL.ready(function() +-- Use 'AddEventHandler' to listen for the 'oxmysql:ready' event +AddEventHandler('oxmysql:ready', function() Citizen.Wait(2000) local xPlayers = ESX.GetPlayers() @@ -25,9 +21,7 @@ MySQL.ready(function() Citizen.Wait(100) local xPlayer = ESX.GetPlayerFromId(xPlayers[i]) - MySQL.Async.fetchAll('SELECT jail_time FROM users WHERE identifier = @identifier', { - ['@identifier'] = xPlayer.identifier - }, function(result) + exports.oxmysql:execute('SELECT jail_time FROM users WHERE identifier = ?', { xPlayer.identifier }, function(result) if result[1] and result[1].jail_time > 0 then TriggerEvent('esx_jail:sendToJail', xPlayer.source, result[1].jail_time, true) end @@ -54,19 +48,15 @@ AddEventHandler('esx_jail:sendToJail', function(playerId, jailTime, quiet) if xPlayer then if not playersInJail[playerId] then - MySQL.Async.execute('UPDATE users SET jail_time = @jail_time WHERE identifier = @identifier', { - ['@identifier'] = xPlayer.identifier, - ['@jail_time'] = jailTime - }, function(rowsChanged) + exports.oxmysql:execute('UPDATE users SET jail_time = ? WHERE identifier = ?', { jailTime, xPlayer.identifier }, function(rowsChanged) xPlayer.triggerEvent('esx_policejob:unrestrain') xPlayer.triggerEvent('esx_jail:jailPlayer', jailTime) playersInJail[playerId] = {timeRemaining = jailTime, identifier = xPlayer.getIdentifier()} if not quiet then - TriggerClientEvent('chat:addMessage', -1, {args = {_U('judge'), _U('jailed_msg', xPlayer.getName(), ESX.Math.Round(jailTime / 60))}, color = {147, 196, 109}}) + TriggerClientEvent('chat:addMessage', -1, {args = {'Judge', ('%s has been jailed for %s minutes.'):format(xPlayer.getName(), ESX.Math.Round(jailTime / 60))}, color = {147, 196, 109}}) end end) - end end end) @@ -76,10 +66,8 @@ function unjailPlayer(playerId) if xPlayer then if playersInJail[playerId] then - MySQL.Async.execute('UPDATE users SET jail_time = 0 WHERE identifier = @identifier', { - ['@identifier'] = xPlayer.identifier - }, function(rowsChanged) - TriggerClientEvent('chat:addMessage', -1, {args = {_U('judge'), _U('unjailed', xPlayer.getName())}, color = {147, 196, 109}}) + exports.oxmysql:execute('UPDATE users SET jail_time = 0 WHERE identifier = ?', { xPlayer.identifier }, function(rowsChanged) + TriggerClientEvent('chat:addMessage', -1, {args = {'Judge', ('%s has been released from jail.'):format(xPlayer.getName())}, color = {147, 196, 109}}) playersInJail[playerId] = nil xPlayer.triggerEvent('esx_jail:unjailPlayer') end) @@ -91,34 +79,24 @@ Citizen.CreateThread(function() while true do Citizen.Wait(1000) - for playerId,data in pairs(playersInJail) do + for playerId, data in pairs(playersInJail) do playersInJail[playerId].timeRemaining = data.timeRemaining - 1 if data.timeRemaining < 1 then - unjailPlayer(playerId, false) + unjailPlayer(playerId) end end end end) +-- Updated thread without 'Async.parallelLimit' Citizen.CreateThread(function() while true do Citizen.Wait(Config.JailTimeSyncInterval) - local tasks = {} - - for playerId,data in pairs(playersInJail) do - local task = function(cb) - MySQL.Async.execute('UPDATE users SET jail_time = @time_remaining WHERE identifier = @identifier', { - ['@identifier'] = data.identifier, - ['@time_remaining'] = data.timeRemaining - }, function(rowsChanged) - cb(rowsChanged) - end) - end - table.insert(tasks, task) + for playerId, data in pairs(playersInJail) do + -- Update jail time for each player + exports.oxmysql:execute('UPDATE users SET jail_time = ? WHERE identifier = ?', { data.timeRemaining, data.identifier }) end - - Async.parallelLimit(tasks, 4, function(results) end) end end) From aa2564e46ff8189077677480092080b11d81f886 Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:29:31 -0400 Subject: [PATCH 3/9] Update fxmanifest.lua Updated for oxmysql --- fxmanifest.lua | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fxmanifest.lua b/fxmanifest.lua index 90e1bf0..82b6d97 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -1,4 +1,4 @@ -fx_version 'adamant' +fx_version 'cerulean' game 'gta5' @@ -6,9 +6,10 @@ description 'ESX Jail' version '1.1.0' +shared_script '@es_extended/imports.lua' + server_scripts { - '@async/async.lua', - '@mysql-async/lib/MySQL.lua', + '@oxmysql/lib/MySQL.lua', '@es_extended/locale.lua', 'locales/en.lua', 'locales/br.lua', @@ -30,5 +31,5 @@ client_scripts { dependencies { 'es_extended', - 'async' + 'oxmysql' } From 70f9643aeeff4463e01225f0f9be01c4d56d1dff Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:35:15 -0400 Subject: [PATCH 4/9] Update README.md Updated docs to match new updates for oxmysql --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d972322..8e69917 100644 --- a/README.md +++ b/README.md @@ -68,3 +68,9 @@ function JailPlayer(player) end) end ``` + +This is for English local only for esx_policejob. Add this line below to (esx_policejob/locales/en.lua) this is needed so that it says in the interact menu (Jail). This is the same concept for all other locales BUT make sure you edit the line ({label = _U('blah blah'), value = 'blah blah'}) so that it matches your lang. So whatever word you put in Jail you need to match this in locales (['blah blah'] = 'blah blah',) +``` +['jail'] = 'jail', +``` + From d59041c109cfc30101fcd53c232d7084749b4ddf Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:38:27 -0400 Subject: [PATCH 5/9] Update main.lua Updated for oxmysql. I will also clean up this code later. --- client/main.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/main.lua b/client/main.lua index 5719c5e..8aaa0ed 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,13 +1,11 @@ local isInJail, unjail = false, false local jailTime, fastTimer = 0, 0 -ESX = nil -Citizen.CreateThread(function() while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Citizen.Wait(0) end -end) +--end) RegisterNetEvent('esx_jail:jailPlayer') AddEventHandler('esx_jail:jailPlayer', function(_jailTime) @@ -104,4 +102,4 @@ function draw2dText(text, x, y) BeginTextCommandDisplayText('STRING') AddTextComponentSubstringPlayerName(text) EndTextCommandDisplayText(x, y) -end \ No newline at end of file +end From b63550b9e3513130197a9cff2c535cb05fcd67b1 Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:40:08 -0400 Subject: [PATCH 6/9] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e69917..987a247 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Let cops jail people! 5. (Optional) See below on how to jail via `esx_policejob` # Dependencies -oxmysql (I removed async since it was crap) +oxmysql (I removed async since it was crap) - [oxmysql](https://github.com/overextended/oxmysql) # How to jail @@ -36,6 +36,7 @@ oxmysql (I removed async since it was crap) # Based off - [Original script](https://forum.fivem.net/t/release-fx-jailer-1-1-0-0/41963) - [dbjailer](https://github.com/SSPU1W/dbjailer) +- [oxmysql](https://github.com/overextended/oxmysql) # Add to menu From 453408a8a3408f7ae217f959b0af3c9153288b5d Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:42:17 -0400 Subject: [PATCH 7/9] Update README.md --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 987a247..2baa612 100644 --- a/README.md +++ b/README.md @@ -43,12 +43,16 @@ oxmysql (I removed async since it was crap) - [oxmysql](https://github.com/overe Example in `esx_policejob: client/main.lua`: ```lua - {label = _U('fine'), value = 'fine'}, - {label = _U('jail'), value = 'jail'} + {icon = "fas fa-idkyet", title = TranslateCap('fine'), value = 'fine'}, + {icon = "fas fa-idkyet", title = TranslateCap('jail'), value = 'jail'}, + {icon = "fas fa-idkyet", title = TranslateCap('unpaid_bills'), value = 'unpaid_bills'} - if data2.current.value == 'jail' then - JailPlayer(GetPlayerServerId(closestPlayer)) + elseif action == 'license' then + ShowPlayerLicense(closestPlayer) + elseif action == 'jail' then + JailPlayer(GetPlayerServerId(closestPlayer)) + elseif action == 'unpaid_bills' then end --- From ecff7ce0b381f09ba6f204be482982588147560a Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Tue, 15 Oct 2024 18:43:08 -0400 Subject: [PATCH 8/9] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2baa612..01ad70b 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ oxmysql (I removed async since it was crap) - [oxmysql](https://github.com/overe Example in `esx_policejob: client/main.lua`: ```lua - {icon = "fas fa-idkyet", title = TranslateCap('fine'), value = 'fine'}, - {icon = "fas fa-idkyet", title = TranslateCap('jail'), value = 'jail'}, - {icon = "fas fa-idkyet", title = TranslateCap('unpaid_bills'), value = 'unpaid_bills'} + {icon = "fas fa-idkyet", title = TranslateCap('fine'), value = 'fine'}, + {icon = "fas fa-idkyet", title = TranslateCap('jail'), value = 'jail'}, + {icon = "fas fa-idkyet", title = TranslateCap('unpaid_bills'), value = 'unpaid_bills'} elseif action == 'license' then From 7787ac2f3fa9dde786a5761e19fab2344d788e5a Mon Sep 17 00:00:00 2001 From: apeoplerson <126418234+apeoplerson@users.noreply.github.com> Date: Wed, 16 Oct 2024 12:13:10 -0400 Subject: [PATCH 9/9] Update main.lua fixed and cleaned up code. --- client/main.lua | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/client/main.lua b/client/main.lua index 8aaa0ed..e937c73 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,18 +1,17 @@ local isInJail, unjail = false, false local jailTime, fastTimer = 0, 0 - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - Citizen.Wait(0) - end ---end) +-- Initialize ESX +ESX = exports["es_extended"]:getSharedObject() RegisterNetEvent('esx_jail:jailPlayer') AddEventHandler('esx_jail:jailPlayer', function(_jailTime) jailTime = _jailTime + fastTimer = jailTime local playerPed = PlayerPedId() + -- Apply prison uniform TriggerEvent('skinchanger:getSkin', function(skin) if skin.sex == 0 then TriggerEvent('skinchanger:loadClothes', skin, Config.Uniforms.prison_wear.male) @@ -25,6 +24,7 @@ AddEventHandler('esx_jail:jailPlayer', function(_jailTime) ESX.Game.Teleport(playerPed, Config.JailLocation) isInJail, unjail = true, false + -- Main jail loop while not unjail do playerPed = PlayerPedId() @@ -33,36 +33,40 @@ AddEventHandler('esx_jail:jailPlayer', function(_jailTime) ClearPedTasksImmediately(playerPed) end - Citizen.Wait(20000) + Citizen.Wait(20000) -- Wait 20 seconds before checking escape attempt -- Is the player trying to escape? - if #(GetEntityCoords(playerPed) - Config.JailLocation) > 10 then + local distance = #(GetEntityCoords(playerPed) - vector3(Config.JailLocation.x, Config.JailLocation.y, Config.JailLocation.z)) + if distance > 10.0 then ESX.Game.Teleport(playerPed, Config.JailLocation) TriggerEvent('chat:addMessage', {args = {_U('judge'), _U('escape_attempt')}, color = {147, 196, 109}}) end end + -- Release player from jail ESX.Game.Teleport(playerPed, Config.JailBlip) isInJail = false + -- Restore player skin ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin) TriggerEvent('skinchanger:loadSkin', skin) end) end) +-- Jail timer thread Citizen.CreateThread(function() while true do - Citizen.Wait(0) - if jailTime > 0 and isInJail then - if fastTimer < 0 then - fastTimer = jailTime - end + Citizen.Wait(1000) -- Update every second - draw2dText(_U('remaining_msg', ESX.Math.Round(fastTimer)), 0.175, 0.955) - fastTimer = fastTimer - 0.01 + fastTimer = fastTimer - 1 + draw2dText(_U('remaining_msg', fastTimer), 0.175, 0.955) + + if fastTimer <= 0 then + TriggerEvent('esx_jail:unjailPlayer') + end else - Citizen.Wait(500) + Citizen.Wait(5000) -- No need to run the loop frequently if not in jail end end end) @@ -78,11 +82,12 @@ AddEventHandler('playerSpawned', function(spawn) end end) +-- Create jail blip on the map Citizen.CreateThread(function() local blip = AddBlipForCoord(Config.JailBlip) SetBlipSprite(blip, 188) - SetBlipScale (blip, 1.9) + SetBlipScale(blip, 1.9) SetBlipColour(blip, 6) SetBlipAsShortRange(blip, true) @@ -91,6 +96,7 @@ Citizen.CreateThread(function() EndTextCommandSetBlipName(blip) end) +-- Function to draw 2D text on screen function draw2dText(text, x, y) SetTextFont(4) SetTextScale(0.45, 0.45)