Jump to content

[HELP] Taking camera position of other players


Serius

Recommended Posts

  • Discord Moderators

You need to sync the camera matrix between the player and the other players manually

triggerServerEvent -- Send the camera matrix from the player to the server
triggerClientEvent -- Send the camera matrix to the other players from the server

 

Edited by Zango
Link to comment

Did you know that getCameraMatrix is shared? So you could do it on the server side...

 

function getPlayerFromID(id)
    v = false
    for i, player in ipairs (getElementsByType("player")) do
        if getElementData(player, "ID") == id then
            v = player
            break
        end
    end
    return v
end

addCommandHandler("getcam", 
    function(player, _, id)
            if (tonumber(id)) then
            local playerID = getPlayerFromID(id)
            if (playerID) then
                local cameraMatrix = {getCameraMatrix(playerID)}
                outputChatBox("The player's camera matrix is: [1] x = "..(cameraMatrix[1])..", y = "..(cameraMatrix[2])..", z = "..(cameraMatrix[3]).." [2] x = "..(cameraMatrix[4])..", y = "..(cameraMatrix[5])..", z = "..(cameraMatrix[6]).." [3] x = "..(cameraMatrix[7])..", y = "..(cameraMatrix[8]), player)
            else
                outputChatBox("The player is not online", player)
            end
        else
            outputChatBox("You did not enter the id", player)
        end
    end
)

I think it's something like this! I hope this helps.

Link to comment
  • Discord Moderators
19 hours ago, RomanDev said:

Did you know that getCameraMatrix is shared? So you could do it on the server side...

getCameraMatrix only works serverside if the camera is fixed with setCameraMatrix, it doesn't return GTA camera values.

Instead of element data, I recommend using triggerServerEvent to send the values to server, and triggerClientEvent to send to relevant (nearby) players.

  • Thanks 1
Link to comment
34 minutes ago, Zango said:

getCameraMatrix só funciona no lado do servidor se a câmera for fixada com setCameraMatrix, não retorna os valores da câmera GTA.

Em vez de dados de elemento, eu recomendo usar triggerServerEvent para enviar os valores para o servidor e triggerClientEvent para enviar para jogadores relevantes (próximos).

Okay, sorry! New code:
 

-- Server-Side

addEvent("dataClient:CameraMatrix", true)
addEventHandler("dataClient:CameraMatrix", root,
    function(data)
        outputChatBox("The player camera matrix is: [1] x = "..(data[1])..", y = "..(data[2])..", z = "..(data[3]).." [2] x = "..(data[4])..", y = "..(data[5])..", z = "..(data[6]).." [3] x = "..(data[7])..", y = "..(data[8]), source)
    end
)

-- Client-Side

function getPlayerFromID(id)
    v = false
    for i, player in ipairs (getElementsByType("player")) do
        if getElementData(player, "ID") == id then
            v = player
            break
        end
    end
    return v
end

addCommandHandler("getcam", 
    function(_, id)
            if (tonumber(id)) then
            local playerID = getPlayerFromID(id)
            if (playerID) then
                local cameraMatrix = {getCameraMatrix(playerID)}
                triggerServerEvent("dataClient:CameraMatrix", localPlayer, cameraMatrix)
            else
                outputChatBox("The player is not online", localPlayer)
            end
        else
            outputChatBox("You did not enter the id", localPlayer)
        end
    end
)

 

Edited by RomanDev
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...