mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-09-04 17:23:31 +00:00
Merge pull request #548 from Mycroft-Studios/main
Feat(events): Better TPM Event
This commit is contained in:
+79
-9
@@ -30,19 +30,89 @@ RegisterNetEvent('QBCore:Command:TeleportToCoords', function(x, y, z)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
RegisterNetEvent('QBCore:Command:GoToMarker', function()
|
RegisterNetEvent('QBCore:Command:GoToMarker', function()
|
||||||
local ped = PlayerPedId()
|
local PlayerPedId = PlayerPedId
|
||||||
local blip = GetFirstBlipInfoId(8)
|
local GetEntityCoords = GetEntityCoords
|
||||||
if not DoesBlipExist(blip) then return end
|
local GetGroundZFor_3dCoord = GetGroundZFor_3dCoord
|
||||||
local blipCoords = GetBlipCoords(blip)
|
|
||||||
for height = 1, 1000 do
|
local blipMarker <const> = GetFirstBlipInfoId(8)
|
||||||
SetPedCoordsKeepVehicle(ped, blipCoords.x, blipCoords.y, height + 0.0)
|
if not DoesBlipExist(blipMarker) then
|
||||||
local foundGround, zPos = GetGroundZFor_3dCoord(blipCoords.x, blipCoords.y, height + 0.0)
|
QBCore.Functions.Notify('No Waypoint Set.', "error",5000)
|
||||||
if foundGround then
|
return 'marker'
|
||||||
SetPedCoordsKeepVehicle(ped, blipCoords.x, blipCoords.y, height + 0.0)
|
end
|
||||||
|
|
||||||
|
-- Fade screen to hide how clients get teleported.
|
||||||
|
DoScreenFadeOut(650)
|
||||||
|
while not IsScreenFadedOut() do
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
local ped, coords <const> = PlayerPedId(), GetBlipInfoIdCoord(blipMarker)
|
||||||
|
local vehicle = GetVehiclePedIsIn(ped, false)
|
||||||
|
local oldCoords <const> = GetEntityCoords(ped)
|
||||||
|
|
||||||
|
-- Unpack coords instead of having to unpack them while iterating.
|
||||||
|
-- 825.0 seems to be the max a player can reach while 0.0 being the lowest.
|
||||||
|
local x, y, groundZ, Z_START = coords['x'], coords['y'], 850.0, 950.0
|
||||||
|
local found = false
|
||||||
|
if vehicle > 0 then
|
||||||
|
FreezeEntityPosition(vehicle, true)
|
||||||
|
else
|
||||||
|
FreezeEntityPosition(ped, true)
|
||||||
|
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
|
||||||
|
end
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
NewLoadSceneStop()
|
||||||
|
SetPedCoordsKeepVehicle(ped, x, y, z)
|
||||||
|
|
||||||
|
while not HasCollisionLoadedAroundEntity(ped) do
|
||||||
|
RequestCollisionAtCoord(x, y, z)
|
||||||
|
if GetGameTimer() - curTime > 1000 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
Wait(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Get ground coord. As mentioned in the natives, this only works if the client is in render distance.
|
||||||
|
found, groundZ = GetGroundZFor_3dCoord(x, y, z, false);
|
||||||
|
if found then
|
||||||
|
Wait(0)
|
||||||
|
SetPedCoordsKeepVehicle(ped, x, y, groundZ)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
Wait(0)
|
Wait(0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Remove black screen once the loop has ended.
|
||||||
|
DoScreenFadeIn(650)
|
||||||
|
if vehicle > 0 then
|
||||||
|
FreezeEntityPosition(vehicle, false)
|
||||||
|
else
|
||||||
|
FreezeEntityPosition(ped, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not found then
|
||||||
|
-- If we can't find the coords, set the coords to the old ones.
|
||||||
|
-- We don't unpack them before since they aren't in a loop and only called once.
|
||||||
|
SetPedCoordsKeepVehicle(ped, oldCoords['x'], oldCoords['y'], oldCoords['z'] - 1.0)
|
||||||
|
QBCore.Functions.Notify('Error While Teleporting.', "error",5000)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- If Z coord was found, set coords in found coords.
|
||||||
|
SetPedCoordsKeepVehicle(ped, x, y, groundZ)
|
||||||
|
QBCore.Functions.Notify('Teleported To Waypoint.', "success",5000)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- Vehicle Commands
|
-- Vehicle Commands
|
||||||
|
|||||||
Reference in New Issue
Block a user