Skip to content

Commit

Permalink
revert await callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Thekuca committed Feb 2, 2024
1 parent 2e5d111 commit c46aa10
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 76 deletions.
122 changes: 63 additions & 59 deletions [core]/es_extended/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -508,71 +508,73 @@ RegisterNetEvent("esx:tpm", function()
local GetBlipInfoIdCoord = GetBlipInfoIdCoord
local GetVehiclePedIsIn = GetVehiclePedIsIn

if not ESX.TriggerServerCallback.Await('esx:isUserAdmin') then return end
ESX.TriggerServerCallback('esx:isUserAdmin', function(isAdmin)
if not isAdmin then return end

local blipMarker = GetFirstBlipInfoId(8)
if not DoesBlipExist(blipMarker) then
ESX.ShowNotification(TranslateCap("tpm_nowaypoint"), true, false, 140)
return "marker"
end
local blipMarker = GetFirstBlipInfoId(8)
if not DoesBlipExist(blipMarker) then
ESX.ShowNotification(TranslateCap("tpm_nowaypoint"), true, false, 140)
return "marker"
end

DoScreenFadeOut(650)
while not IsScreenFadedOut() do
Wait(0)
end
DoScreenFadeOut(650)
while not IsScreenFadedOut() do
Wait(0)
end

local ped, coords = ESX.PlayerData.ped, GetBlipInfoIdCoord(blipMarker)
local vehicle = GetVehiclePedIsIn(ped, false)
local oldCoords = GetEntityCoords(ped)
local ped, coords = ESX.PlayerData.ped, GetBlipInfoIdCoord(blipMarker)
local vehicle = GetVehiclePedIsIn(ped, false)
local oldCoords = GetEntityCoords(ped)

local x, y, groundZ, Z_START = coords["x"], coords["y"], 850.0, 950.0
local found = false
FreezeEntityPosition(vehicle > 0 and vehicle or ped, true)
local x, y, groundZ, Z_START = coords["x"], coords["y"], 850.0, 950.0
local found = false
FreezeEntityPosition(vehicle > 0 and vehicle or ped, true)

for i = Z_START, 0, -25.0 do
local z = i
if (i % 2) ~= 0 then
z = Z_START - i
end
for i = Z_START, 0, -25.0 do
local z = i
if (i % 2) ~= 0 then
z = Z_START - i
end

NewLoadSceneStart(x, y, z, x, y, z, 50.0, 0)
local curTime = GetGameTimer()
while IsNetworkLoadingScene() do
if GetGameTimer() - curTime > 1000 then
break
NewLoadSceneStart(x, y, z, x, y, z, 50.0, 0)
local curTime = GetGameTimer()
while IsNetworkLoadingScene() do
if GetGameTimer() - curTime > 1000 then
break
end
Wait(0)
end
Wait(0)
end
NewLoadSceneStop()
SetPedCoordsKeepVehicle(ped, x, y, z)
NewLoadSceneStop()
SetPedCoordsKeepVehicle(ped, x, y, z)

while not HasCollisionLoadedAroundEntity(ped) do
RequestCollisionAtCoord(x, y, z)
if GetGameTimer() - curTime > 1000 then
while not HasCollisionLoadedAroundEntity(ped) do
RequestCollisionAtCoord(x, y, z)
if GetGameTimer() - curTime > 1000 then
break
end
Wait(0)
end

found, groundZ = GetGroundZFor_3dCoord(x, y, z, false)
if found then
Wait(0)
SetPedCoordsKeepVehicle(ped, x, y, groundZ)
break
end
Wait(0)
end

found, groundZ = GetGroundZFor_3dCoord(x, y, z, false)
if found then
Wait(0)
SetPedCoordsKeepVehicle(ped, x, y, groundZ)
break
end
Wait(0)
end
DoScreenFadeIn(650)
FreezeEntityPosition(vehicle > 0 and vehicle or ped, false)

DoScreenFadeIn(650)
FreezeEntityPosition(vehicle > 0 and vehicle or ped, false)
if not found then
SetPedCoordsKeepVehicle(ped, oldCoords["x"], oldCoords["y"], oldCoords["z"] - 1.0)
ESX.ShowNotification(TranslateCap("tpm_success"), true, false, 140)
end

if not found then
SetPedCoordsKeepVehicle(ped, oldCoords["x"], oldCoords["y"], oldCoords["z"] - 1.0)
SetPedCoordsKeepVehicle(ped, x, y, groundZ)
ESX.ShowNotification(TranslateCap("tpm_success"), true, false, 140)
end

SetPedCoordsKeepVehicle(ped, x, y, groundZ)
ESX.ShowNotification(TranslateCap("tpm_success"), true, false, 140)
end)
end)

local noclip = false
Expand Down Expand Up @@ -621,19 +623,21 @@ local function noclipThread()
end

RegisterNetEvent("esx:noclip", function()
if not ESX.TriggerServerCallback.Await('esx:isUserAdmin') then return end
ESX.TriggerServerCallback('esx:isUserAdmin', function(isAdmin)
if not isAdmin then return end

if not noclip then
noclip_pos = GetEntityCoords(ESX.PlayerData.ped, false)
heading = GetEntityHeading(ESX.PlayerData.ped)
end
if not noclip then
noclip_pos = GetEntityCoords(ESX.PlayerData.ped, false)
heading = GetEntityHeading(ESX.PlayerData.ped)
end

noclip = not noclip
if noclip then
CreateThread(noclipThread)
end
noclip = not noclip
if noclip then
CreateThread(noclipThread)
end

ESX.ShowNotification(TranslateCap("noclip_message", noclip and Translate("enabled") or Translate("disabled")), true, false, 140)
ESX.ShowNotification(TranslateCap("noclip_message", noclip and Translate("enabled") or Translate("disabled")), true, false, 140)
end)
end)

RegisterNetEvent("esx:killPlayer", function()
Expand Down
22 changes: 5 additions & 17 deletions [core]/es_extended/client/modules/callback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,13 @@ local clientCallbacks = {}
---@param eventName string
---@param callback function
---@param ... any
ESX.TriggerServerCallback = setmetatable({
Await = function(eventName, ...)
local p = promise.new()
ESX.TriggerServerCallback = function(eventName, callback, ...)
serverRequests[RequestId] = callback

ESX.TriggerServerCallback(eventName, function(...)
p:resolve(...)
end, ...)
TriggerServerEvent('esx:triggerServerCallback', eventName, RequestId, GetInvokingResource() or 'unknown', ...)

return Citizen.Await(p)
end
}, {
__call = function(eventName, callback, ...)
serverRequests[RequestId] = callback

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

RequestId = RequestId + 1
end
})
RequestId = RequestId + 1
end

RegisterNetEvent("esx:serverCallback", function(requestId, invoker, ...)
if not serverRequests[requestId] then
Expand Down

0 comments on commit c46aa10

Please sign in to comment.