Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly fix the Onesync Spectate Issue Mentioned in Issue #137 #171

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -1141,6 +1148,10 @@ RegisterNetEvent('qb-admin:client:ToggleCoords', function()
ToggleShowCoordinates()
end)

menu7_dev_copy_vec2:On("select", function()
CopyToClipboard('coords2')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all works fine and looks good to me

end)

menu7_dev_copy_vec3:On("select", function()
CopyToClipboard('coords3')
end)
Expand Down
23 changes: 21 additions & 2 deletions client/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,35 @@ RegisterNetEvent('qb-admin:client:spectate', function(targetPed)
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

if not isSpectating then
TriggerServerEvent('qb-admin:server:SpectateRouting', RoutingBucket)
isSpectating = true
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
NetworkSetEntityInvisibleToNetwork(myPed, false) -- Set Visible
SetEntityCollision(myPed, true, true) -- Set collision
Expand Down
3 changes: 3 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just reviewing and testing in game at the moment, but for the sake of grammar, if you don't make making 'Doesn't' to 'doesn't'

},
success = {
["blips_activated"] = "Blips activated",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 17 additions & 0 deletions server/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down