From 7e300e0b319c88c590fe135bd76e611931e489c8 Mon Sep 17 00:00:00 2001 From: Amantu Khan Date: Mon, 1 Aug 2022 13:58:22 +0600 Subject: [PATCH 1/4] spectating fix --- client/events.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/events.lua b/client/events.lua index 21eb6e3..bc3b174 100644 --- a/client/events.lua +++ b/client/events.lua @@ -27,8 +27,10 @@ RegisterNetEvent('qb-admin:client:spectate', function(targetPed) local myPed = PlayerPedId() local targetplayer = GetPlayerFromServerId(targetPed) local target = GetPlayerPed(targetplayer) + local targetcoordsx,targetcoordsy,targetcoordsz = table.unpack(GetEntityCoords(targetPed, false)) if not isSpectating then isSpectating = true + RequestCollisionAtCoord(targetcoordsx,targetcoordsy,targetcoordsz) SetEntityVisible(myPed, false) -- Set invisible SetEntityCollision(myPed, false, false) -- Set collision SetEntityInvincible(myPed, true) -- Set invincible @@ -37,6 +39,7 @@ RegisterNetEvent('qb-admin:client:spectate', function(targetPed) NetworkSetInSpectatorMode(true, target) -- Enter Spectate Mode else isSpectating = false + RequestCollisionAtCoord(lastSpectateCoord.x, lastSpectateCoord.y, lastSpectateCoord.z) NetworkSetInSpectatorMode(false, target) -- Remove From Spectate Mode NetworkSetEntityInvisibleToNetwork(myPed, false) -- Set Visible SetEntityCollision(myPed, true, true) -- Set collision From 9326a6f157889264e75a1cdc4beb0f7375eef82a Mon Sep 17 00:00:00 2001 From: Amantu Khan Date: Sat, 6 May 2023 00:19:50 +0600 Subject: [PATCH 2/4] [NOT TESTED] Few QOL change and fixes Added get ped from server side incase of OneSync Related loading issue where ped don't get where the player is. Added Copy Vector2 Button. --- client/client.lua | 11 +++++++++++ client/events.lua | 24 ++++++++++++++++++++---- locales/en.lua | 3 +++ server/server.lua | 17 +++++++++++++++++ 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/client/client.lua b/client/client.lua index 6c90c3d..98ad381 100644 --- a/client/client.lua +++ b/client/client.lua @@ -283,6 +283,13 @@ local menu5_vehicles_max_upgrades = menu5:AddButton({ }) -- Developer Options Menu Buttons +local menu7_dev_copy_vec2 = menu7:AddButton({ + icon = '📋', + label = Lang:t("menu.copy_vector2"), + value = 'coords', + description = Lang:t("desc.vector2_desc") +}) + local menu7_dev_copy_vec3 = menu7:AddButton({ icon = '📋', label = Lang:t("menu.copy_vector3"), @@ -1141,6 +1148,10 @@ RegisterNetEvent('qb-admin:client:ToggleCoords', function() ToggleShowCoordinates() end) +menu7_dev_copy_vec2:On("select", function() + CopyToClipboard('coords2') +end) + menu7_dev_copy_vec3:On("select", function() CopyToClipboard('coords3') end) diff --git a/client/events.lua b/client/events.lua index b48f135..b37e5c7 100644 --- a/client/events.lua +++ b/client/events.lua @@ -27,17 +27,33 @@ RegisterNetEvent('qb-admin:client:spectate', function(targetPed) local myPed = PlayerPedId() local targetplayer = GetPlayerFromServerId(targetPed) local target = GetPlayerPed(targetplayer) - local targetcoordsx,targetcoordsy,targetcoordsz = table.unpack(GetEntityCoords(targetPed, false)) + local TargetCoords = GetEntityCoords(targetPed, false) + local RoutingBucket = 0 + if not DoesEntityExist(target) then + QBCore.Functions.TriggerCallback('oneSync:get:Spectate', function(ped, coords, routing) + if ped then + target = ped + TargetCoords = coords + RoutingBucket = routing + else + QBCore.Functions.Notify(Lang:t("error.no_player"), 'error') + return + end + end, targetPed) + end + if not isSpectating then + TriggerServerEvent('qb-admin:server:SpectateRouting', RoutingBucket) isSpectating = true - RequestCollisionAtCoord(targetcoordsx,targetcoordsy,targetcoordsz) + RequestCollisionAtCoord(TargetCoords.x,TargetCoords.y,TargetCoords.z) + NetworkSetInSpectatorMode(true, target) -- Enter Spectate Mode + SetEntityInvincible(myPed, true) -- Set invincible SetEntityVisible(myPed, false) -- Set invisible SetEntityCollision(myPed, false, false) -- Set collision - SetEntityInvincible(myPed, true) -- Set invincible NetworkSetEntityInvisibleToNetwork(myPed, true) -- Set invisibility lastSpectateCoord = GetEntityCoords(myPed) -- save my last coords - NetworkSetInSpectatorMode(true, target) -- Enter Spectate Mode else + TriggerServerEvent('qb-admin:server:SpectateRouting', 0) isSpectating = false RequestCollisionAtCoord(lastSpectateCoord.x, lastSpectateCoord.y, lastSpectateCoord.z) NetworkSetInSpectatorMode(false, target) -- Remove From Spectate Mode diff --git a/locales/en.lua b/locales/en.lua index 8b76fa2..23b229a 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -15,6 +15,7 @@ local Translations = { ["failed_set_speed"] = "You did not set a speed.. (`fast` for super-run, `normal` for normal)", ["failed_set_model"] = "You did not set a model..", ["failed_entity_copy"] = "No freeaim entity info to copy to clipboard!", + ["no_player"] = 'Player Doesn\'t exist in server anymore', }, success = { ["blips_activated"] = "Blips activated", @@ -127,6 +128,7 @@ local Translations = { ["weather_options"] = "Weather Options", ["server_time"] = "Server Time", ["time"] = "Time", + ["copy_vector2"] = "Copy vector2", ["copy_vector3"] = "Copy vector3", ["copy_vector4"] = "Copy vector4", ["display_coords"] = "Display Coords", @@ -171,6 +173,7 @@ local Translations = { ["blips_desc"] = "Enable/Disable Blips for players in maps", ["weather_desc"] = "Change The Weather", ["developer_desc"] = "Misc. Dev Options", + ["vector2_desc"] = "Copy vector2 To Clipboard", ["vector3_desc"] = "Copy vector3 To Clipboard", ["vector4_desc"] = "Copy vector4 To Clipboard", ["display_coords_desc"] = "Show Coords On Screen", diff --git a/server/server.lua b/server/server.lua index 7234853..e2ec982 100644 --- a/server/server.lua +++ b/server/server.lua @@ -23,6 +23,18 @@ QBCore.Functions.CreateCallback('test:getdealers', function(_, cb) cb(exports['qb-drugs']:GetDealers()) end) +QBCore.Functions.CreateCallback('oneSync:get:Spectate', function(_, cb, TargetID) + local Target = QBCore.Functions.GetPlayer(TargetID) + local targetRouting = GetPlayerRoutingBucket(TargetID) + if Target then + local TargetPed = GetPlayerPed(Target.PlayerData.source) + local TargetCoords = GetEntityCoords(TargetPed) + cb(TargetPed, TargetCoords, targetRouting) + else + cb(nil) + end +end) + -- Get Players QBCore.Functions.CreateCallback('test:getplayers', function(_, cb) -- WORKS cb(players) @@ -60,6 +72,11 @@ local function BanPlayer(src) end -- Events +RegisterNetEvent('qb-admin:server:SpectateRouting', function(routingBucket) + local src = source + SetPlayerRoutingBucket(src, routingBucket) +end) + RegisterNetEvent('qb-admin:server:GetPlayersForBlips', function() local src = source TriggerClientEvent('qb-admin:client:Show', src, players) From 66506aacdbec65d18e1afdbea5d71ee6ea0d1a71 Mon Sep 17 00:00:00 2001 From: Amantu Khan Date: Sat, 6 May 2023 01:03:54 +0600 Subject: [PATCH 3/4] Update en.lua --- locales/en.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locales/en.lua b/locales/en.lua index 23b229a..73db8fe 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -15,7 +15,7 @@ local Translations = { ["failed_set_speed"] = "You did not set a speed.. (`fast` for super-run, `normal` for normal)", ["failed_set_model"] = "You did not set a model..", ["failed_entity_copy"] = "No freeaim entity info to copy to clipboard!", - ["no_player"] = 'Player Doesn\'t exist in server anymore', + ["no_player"] = 'Player doesn\'t exist in server anymore', }, success = { ["blips_activated"] = "Blips activated", From 6ffeae128fc99cb3a84724a617fe2a14f3538574 Mon Sep 17 00:00:00 2001 From: Amantu Khan Date: Sat, 6 May 2023 01:12:12 +0600 Subject: [PATCH 4/4] Updates --- client/events.lua | 18 +++--------------- server/server.lua | 15 ++------------- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/client/events.lua b/client/events.lua index b37e5c7..ffd05cc 100644 --- a/client/events.lua +++ b/client/events.lua @@ -23,24 +23,12 @@ RegisterNetEvent('qb-admin:client:inventory', function(targetPed) TriggerServerEvent("inventory:server:OpenInventory", "otherplayer", targetPed) end) -RegisterNetEvent('qb-admin:client:spectate', function(targetPed) +RegisterNetEvent('qb-admin:client:spectate', function(targetPed, coords, routingBucket) local myPed = PlayerPedId() local targetplayer = GetPlayerFromServerId(targetPed) local target = GetPlayerPed(targetplayer) - local TargetCoords = GetEntityCoords(targetPed, false) - local RoutingBucket = 0 - if not DoesEntityExist(target) then - QBCore.Functions.TriggerCallback('oneSync:get:Spectate', function(ped, coords, routing) - if ped then - target = ped - TargetCoords = coords - RoutingBucket = routing - else - QBCore.Functions.Notify(Lang:t("error.no_player"), 'error') - return - end - end, targetPed) - end + local TargetCoords = coords + local RoutingBucket = routingBucket if not isSpectating then TriggerServerEvent('qb-admin:server:SpectateRouting', RoutingBucket) diff --git a/server/server.lua b/server/server.lua index e2ec982..e166528 100644 --- a/server/server.lua +++ b/server/server.lua @@ -23,18 +23,6 @@ QBCore.Functions.CreateCallback('test:getdealers', function(_, cb) cb(exports['qb-drugs']:GetDealers()) end) -QBCore.Functions.CreateCallback('oneSync:get:Spectate', function(_, cb, TargetID) - local Target = QBCore.Functions.GetPlayer(TargetID) - local targetRouting = GetPlayerRoutingBucket(TargetID) - if Target then - local TargetPed = GetPlayerPed(Target.PlayerData.source) - local TargetCoords = GetEntityCoords(TargetPed) - cb(TargetPed, TargetCoords, targetRouting) - else - cb(nil) - end -end) - -- Get Players QBCore.Functions.CreateCallback('test:getplayers', function(_, cb) -- WORKS cb(players) @@ -148,7 +136,8 @@ RegisterNetEvent('qb-admin:server:spectate', function(player) if QBCore.Functions.HasPermission(src, permissions['spectate']) or IsPlayerAceAllowed(src, 'command') then local targetped = GetPlayerPed(player.id) local coords = GetEntityCoords(targetped) - TriggerClientEvent('qb-admin:client:spectate', src, player.id, coords) + local routingBucket = GetPlayerRoutingBucket(player.id) + TriggerClientEvent('qb-admin:client:spectate', src, player.id, coords, routingBucket) else BanPlayer(src) end