Skip to content

Commit

Permalink
Merge pull request #959 from esx-framework/dev
Browse files Browse the repository at this point in the history
1.9.4
  • Loading branch information
jbdevic authored Mar 20, 2023
2 parents 4ce57fc + cdbe937 commit 85b3407
Show file tree
Hide file tree
Showing 67 changed files with 3,069 additions and 2,098 deletions.
1 change: 1 addition & 0 deletions [SQL]/legacy.sql
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ CREATE TABLE `users` (
`job` varchar(20) DEFAULT 'unemployed',
`job_grade` int(11) DEFAULT 0,
`loadout` longtext DEFAULT NULL,
`metadata` LONGTEXT NULL DEFAULT NULL,
`position` longtext NULL DEFAULT NULL,
`firstname` varchar(16) DEFAULT NULL,
`lastname` varchar(16) DEFAULT NULL,
Expand Down
2 changes: 1 addition & 1 deletion [core]/cron/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ game 'gta5'
author 'ESX-Framework'
description 'cron'
lua54 'yes'
version '1.9.3'
version '1.9.4'

server_script 'server/main.lua'
4 changes: 2 additions & 2 deletions [core]/cron/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ local Jobs = {}
local LastTime = nil

function RunAt(h, m, cb)
table.insert(Jobs, {
Jobs[#Jobs + 1] = {
h = h,
m = m,
cb = cb
})
}
end

function GetTime()
Expand Down
55 changes: 35 additions & 20 deletions [core]/es_extended/client/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ ESX = {}
Core = {}
ESX.PlayerData = {}
ESX.PlayerLoaded = false
Core.CurrentRequestId = 0
Core.ServerCallbacks = {}
Core.Input = {}
ESX.UI = {}
ESX.UI.Menu = {}
Expand Down Expand Up @@ -187,14 +185,6 @@ ESX.RegisterInput = function(command_name, label, input_group, key, on_press, on
RegisterKeyMapping(on_release ~= nil and "+" .. command_name or command_name, label, input_group, key)
end

function ESX.TriggerServerCallback(name, cb, ...)
local Invoke = GetInvokingResource() or "unknown"
Core.ServerCallbacks[Core.CurrentRequestId] = cb

TriggerServerEvent('esx:triggerServerCallback', name, Core.CurrentRequestId,Invoke, ...)
Core.CurrentRequestId = Core.CurrentRequestId < 65535 and Core.CurrentRequestId + 1 or 0
end

function ESX.UI.Menu.RegisterType(type, open, close)
ESX.UI.Menu.RegisteredTypes[type] = {
open = open,
Expand Down Expand Up @@ -416,6 +406,17 @@ function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
local model = type(vehicle) == 'number' and vehicle or joaat(vehicle)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
networked = networked == nil and true or networked

local playerCoords = GetEntityCoords(ESX.PlayerData.ped)
if not vector or not playerCoords then
return
end
local dist = #(playerCoords - vector)
if dist > 424 then -- Onesync infinity Range (https://docs.fivem.net/docs/scripting-reference/onesync/)
local executingResource = GetInvokingResource() or "Unknown"
return print(("[^1ERROR^7] Resource ^5%s^7 Tried to spawn vehicle on the client but the position is too far away (Out of onesync range)."):format(executing_resource))
end

CreateThread(function()
ESX.Streaming.RequestModel(model)

Expand Down Expand Up @@ -1304,15 +1305,6 @@ function ESX.ShowInventory()
end)
end

RegisterNetEvent('esx:serverCallback', function(requestId,invoker, ...)
if Core.ServerCallbacks[requestId] then
Core.ServerCallbacks[requestId](...)
Core.ServerCallbacks[requestId] = nil
else
print('[^1ERROR^7] Server Callback with requestId ^5'.. requestId ..'^7 Was Called by ^5'.. invoker .. '^7 but does not exist.')
end
end)

RegisterNetEvent('esx:showNotification')
AddEventHandler('esx:showNotification', function(msg, type, length)
ESX.ShowNotification(msg, type, length)
Expand All @@ -1327,4 +1319,27 @@ AddEventHandler('esx:showAdvancedNotification',
RegisterNetEvent('esx:showHelpNotification')
AddEventHandler('esx:showHelpNotification', function(msg, thisFrame, beep, duration)
ESX.ShowHelpNotification(msg, thisFrame, beep, duration)
end)
end)

---@param model number|string
---@return string
function ESX.GetVehicleType(model)
model = type(model) == 'string' and joaat(model) or model

if model == `submersible` or model == `submersible2` then
return 'submarine'
end

local vehicleType = GetVehicleClassFromName(model)
local types = {
[8] = "bike",
[11] = "trailer",
[13] = "bike",
[14] = "boat",
[15] = "heli",
[16] = "plane",
[21] = "train",
}

return types[vehicleType] or "automobile"
end
107 changes: 85 additions & 22 deletions [core]/es_extended/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ local pickups = {}

CreateThread(function()
while not Config.Multichar do
Wait(0)
Wait(100)

if NetworkIsPlayerActive(PlayerId()) then
exports.spawnmanager:setAutoSpawn(false)
DoScreenFadeOut(0)
Expand Down Expand Up @@ -74,6 +75,15 @@ AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
end
end

if Config.DisableVehicleSeatShuff then
AddEventHandler('esx:enteredVehicle', function(vehicle, plate, seat)
if seat == 0 then
SetPedIntoVehicle(ESX.PlayerData.ped, vehicle, 0)
SetPedConfigFlag(ESX.PlayerData.ped, 184, true)
end
end)
end

if Config.DisableHealthRegeneration or Config.DisableWeaponWheel or Config.DisableAimAssist or Config.DisableVehicleRewards then
CreateThread(function()
while true do
Expand Down Expand Up @@ -101,6 +111,74 @@ AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
end)
end

-- Disable Dispatch services
if Config.DisableDispatchServices then
for i = 1, 15 do
EnableDispatchService(i, false)
end
end

-- Disable Scenarios
if Config.DisableScenarios then
local scenarios = {
'WORLD_VEHICLE_ATTRACTOR',
'WORLD_VEHICLE_AMBULANCE',
'WORLD_VEHICLE_BICYCLE_BMX',
'WORLD_VEHICLE_BICYCLE_BMX_BALLAS',
'WORLD_VEHICLE_BICYCLE_BMX_FAMILY',
'WORLD_VEHICLE_BICYCLE_BMX_HARMONY',
'WORLD_VEHICLE_BICYCLE_BMX_VAGOS',
'WORLD_VEHICLE_BICYCLE_MOUNTAIN',
'WORLD_VEHICLE_BICYCLE_ROAD',
'WORLD_VEHICLE_BIKE_OFF_ROAD_RACE',
'WORLD_VEHICLE_BIKER',
'WORLD_VEHICLE_BOAT_IDLE',
'WORLD_VEHICLE_BOAT_IDLE_ALAMO',
'WORLD_VEHICLE_BOAT_IDLE_MARQUIS',
'WORLD_VEHICLE_BOAT_IDLE_MARQUIS',
'WORLD_VEHICLE_BROKEN_DOWN',
'WORLD_VEHICLE_BUSINESSMEN',
'WORLD_VEHICLE_HELI_LIFEGUARD',
'WORLD_VEHICLE_CLUCKIN_BELL_TRAILER',
'WORLD_VEHICLE_CONSTRUCTION_SOLO',
'WORLD_VEHICLE_CONSTRUCTION_PASSENGERS',
'WORLD_VEHICLE_DRIVE_PASSENGERS',
'WORLD_VEHICLE_DRIVE_PASSENGERS_LIMITED',
'WORLD_VEHICLE_DRIVE_SOLO',
'WORLD_VEHICLE_FIRE_TRUCK',
'WORLD_VEHICLE_EMPTY',
'WORLD_VEHICLE_MARIACHI',
'WORLD_VEHICLE_MECHANIC',
'WORLD_VEHICLE_MILITARY_PLANES_BIG',
'WORLD_VEHICLE_MILITARY_PLANES_SMALL',
'WORLD_VEHICLE_PARK_PARALLEL',
'WORLD_VEHICLE_PARK_PERPENDICULAR_NOSE_IN',
'WORLD_VEHICLE_PASSENGER_EXIT',
'WORLD_VEHICLE_POLICE_BIKE',
'WORLD_VEHICLE_POLICE_CAR',
'WORLD_VEHICLE_POLICE',
'WORLD_VEHICLE_POLICE_NEXT_TO_CAR',
'WORLD_VEHICLE_QUARRY',
'WORLD_VEHICLE_SALTON',
'WORLD_VEHICLE_SALTON_DIRT_BIKE',
'WORLD_VEHICLE_SECURITY_CAR',
'WORLD_VEHICLE_STREETRACE',
'WORLD_VEHICLE_TOURBUS',
'WORLD_VEHICLE_TOURIST',
'WORLD_VEHICLE_TANDL',
'WORLD_VEHICLE_TRACTOR',
'WORLD_VEHICLE_TRACTOR_BEACH',
'WORLD_VEHICLE_TRUCK_LOGS',
'WORLD_VEHICLE_TRUCKS_TRAILERS',
'WORLD_VEHICLE_DISTANT_EMPTY_GROUND',
'WORLD_HUMAN_PAPARAZZI'
}

for i, v in pairs(scenarios) do
SetScenarioTypeEnabled(v, false)
end
end

SetDefaultVehicleNumberPlateTextPattern(-1, Config.CustomAIPlates)
StartServerSyncLoops()
end)
Expand Down Expand Up @@ -607,27 +685,8 @@ AddEventHandler("esx:freezePlayer", function(input)
end
end)

RegisterNetEvent("esx:GetVehicleType", function(Model, Request)
if not IsModelInCdimage(Model) then
return TriggerServerEvent("esx:ReturnVehicleType", false, Request)
end

if Model == `submersible` or Model == `submersible2` then
return TriggerServerEvent("esx:ReturnVehicleType", "submarine", Request)
end

local VehicleType = GetVehicleClassFromName(Model)
local types = {
[8] = "bike",
[11] = "trailer",
[13] = "bike",
[14] = "boat",
[15] = "heli",
[16] = "plane",
[21] = "train",
}

TriggerServerEvent("esx:ReturnVehicleType", types[VehicleType] or "automobile", Request)
ESX.RegisterClientCallback("esx:GetVehicleType", function(cb, model)
cb(ESX.GetVehicleType(model))
end)

local DoNotUse = {
Expand All @@ -646,3 +705,7 @@ for i = 1, #DoNotUse do
print("[^1ERROR^7] YOU ARE USING A RESOURCE THAT WILL BREAK ^1ESX^7, PLEASE REMOVE ^5" .. DoNotUse[i] .. "^7")
end
end

RegisterNetEvent('esx:updatePlayerData', function(key, val)
ESX.SetPlayerData(key, val)
end)
2 changes: 1 addition & 1 deletion [core]/es_extended/client/modules/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,4 @@ if Config.EnableDebug then
print('esx:exitedVehicle', 'vehicle', vehicle, 'plate', plate, 'seat', seat, 'displayName', displayName, 'netId', netId)
end)

end
end
40 changes: 40 additions & 0 deletions [core]/es_extended/client/modules/callback.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
local RequestId = 0
local serverRequests = {}

local clientCallbacks = {}

---@param eventName string
---@param callback function
---@param ... any
ESX.TriggerServerCallback = function(eventName, callback, ...)
serverRequests[RequestId] = callback

TriggerServerEvent('esx:triggerServerCallback', eventName, RequestId, GetInvokingResource() or "unknown", ...)

RequestId = RequestId + 1
end

RegisterNetEvent('esx:serverCallback', function(requestId, invoker, ...)
if not serverRequests[requestId] then
return print(('[^1ERROR^7] Server Callback with requestId ^5%s^7 Was Called by ^5%s^7 but does not exist.'):format(requestId, invoker))
end

serverRequests[requestId](...)
serverRequests[requestId] = nil
end)

---@param eventName string
---@param callback function
ESX.RegisterClientCallback = function(eventName, callback)
clientCallbacks[eventName] = callback
end

RegisterNetEvent('esx:triggerClientCallback', function(eventName, requestId, invoker, ...)
if not clientCallbacks[eventName] then
return print(('[^1ERROR^7] Client Callback not registered, name: ^5%s^7, invoker resource: ^5%s^7'):format(eventName, invoker))
end

clientCallbacks[eventName](function(...)
TriggerServerEvent('esx:clientCallback', requestId, invoker, ...)
end, ...)
end)
21 changes: 20 additions & 1 deletion [core]/es_extended/common/modules/table.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ function ESX.Table.Join(t, sep)
return str
end

-- Credits: https://github.com/JonasDev99/qb-garages/blob/b0335d67cb72a6b9ac60f62a87fb3946f5c2f33d/server/main.lua#L5
function ESX.Table.TableContains(tab, val)
if type(val) == "table" then
for _, value in pairs(tab) do
if ESX.Table.TableContains(val, value) then
return true
end
end
return false
else
for _, value in pairs(tab) do
if value == val then
return true
end
end
end
return false
end

-- Credit: https://stackoverflow.com/a/15706820
-- Description: sort function for pairs
function ESX.Table.Sort(t, order)
Expand Down Expand Up @@ -162,4 +181,4 @@ function ESX.Table.Sort(t, order)
return keys[i], t[keys[i]]
end
end
end
end
5 changes: 4 additions & 1 deletion [core]/es_extended/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,18 @@ Config.EnableDefaultInventory = true -- Display the default Inventory ( F2 )
Config.EnableWantedLevel = false -- Use Normal GTA wanted Level?
Config.EnablePVP = true -- Allow Player to player combat

Config.Multichar = true -- Enable support for esx_multicharacter
Config.Multichar = GetResourceState("esx_multicharacter") ~= "missing"
Config.Identity = true -- Select a characters identity data before they have loaded in (this happens by default with multichar)
Config.DistanceGive = 4.0 -- Max distance when giving items, weapons etc.

Config.DisableHealthRegeneration = false -- Player will no longer regenerate health
Config.DisableVehicleRewards = false -- Disables Player Recieving weapons from vehicles
Config.DisableNPCDrops = false -- stops NPCs from dropping weapons on death
Config.DisableDispatchServices = false -- Disable Dispatch services
Config.DisableScenarios = false -- Disable Scenarios
Config.DisableWeaponWheel = false -- Disables default weapon wheel
Config.DisableAimAssist = false -- disables AIM assist (mainly on controllers)
Config.DisableVehicleSeatShuff = false -- Disables vehicle seat shuff
Config.RemoveHudCommonents = {
[1] = false, --WANTED_STARS,
[2] = false, --WEAPON_ICON
Expand Down
1 change: 1 addition & 0 deletions [core]/es_extended/es_extended.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ CREATE TABLE `users` (
`job` VARCHAR(20) NULL DEFAULT 'unemployed',
`job_grade` INT NULL DEFAULT 0,
`loadout` LONGTEXT NULL DEFAULT NULL,
`metadata` LONGTEXT NULL DEFAULT NULL,
`position` longtext NULL DEFAULT NULL,

PRIMARY KEY (`identifier`)
Expand Down
Loading

0 comments on commit 85b3407

Please sign in to comment.