From c80bd0331b8c94559859d7629519c006b3a79743 Mon Sep 17 00:00:00 2001 From: LoveFistRP Date: Fri, 23 Apr 2021 15:08:50 -0700 Subject: [PATCH] Infinity Compatible TP --- client/events.lua | 11 +++-------- server/commands.lua | 16 +++++++++------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/client/events.lua b/client/events.lua index de3b9de..2175d75 100644 --- a/client/events.lua +++ b/client/events.lua @@ -1,13 +1,8 @@ -- QBCore Command Events RegisterNetEvent('QBCore:Command:TeleportToPlayer') -AddEventHandler('QBCore:Command:TeleportToPlayer', function(othersource) - local coords = QBCore.Functions.GetCoords(GetPlayerPed(GetPlayerFromServerId(othersource))) - local entity = PlayerPedId() - if IsPedInAnyVehicle(entity, false) then - entity = GetVehiclePedIsUsing(entity) - end - SetEntityCoords(entity, coords.x, coords.y, coords.z) - SetEntityHeading(entity, coords.a) +AddEventHandler('QBCore:Command:TeleportToPlayer', function(coords) + local ped = PlayerPedId() + SetPedCoordsKeepVehicle(ped, coords.x, coords.y, coords.z) end) RegisterNetEvent('QBCore:Command:TeleportToCoords') diff --git a/server/commands.lua b/server/commands.lua index ca038f9..753d225 100644 --- a/server/commands.lua +++ b/server/commands.lua @@ -25,15 +25,17 @@ end QBCore.Commands.Add("tp", "TP To Player or Coords (Admin Only)", {{name="id/x", help="ID of player or X position"}, {name="y", help="Y position"}, {name="z", help="Z position"}}, false, function(source, args) if (args[1] ~= nil and (args[2] == nil and args[3] == nil)) then - -- tp to player - local Player = QBCore.Functions.GetPlayer(tonumber(args[1])) - if Player ~= nil then - TriggerClientEvent('QBCore:Command:TeleportToPlayer', source, Player.PlayerData.source) - else - TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error") + for k,v in ipairs(GetPlayers()) do + local id = args[1] + if v == id then + local target = GetPlayerPed(v) + local coords = GetEntityCoords(target) + TriggerClientEvent('QBCore:Command:TeleportToPlayer', source, coords) + else + TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error") + end end else - -- tp to location if args[1] ~= nil and args[2] ~= nil and args[3] ~= nil then local x = tonumber(args[1]) local y = tonumber(args[2])