Jump to content

[Help] setPedLookAt


Ben_Sherman

Recommended Posts

Hello everyone,

I'm trying to sync the setPedLookAt function however I've ran in to some issues since it clearly broadcasts the source and it's coordinates however it's still not change the the look of the other players as it the setPedLookAt function isn't applied to them. But for all of us it works client wise but not the globally. So maybe some one here knows either how to sync it maybe are able to help me out there as this is kinda frustrating.

As I debugged the string in on client side it clearly gives me the players coordinates and including it's name so I know that it's transmitting everything correct. Even as the other players move their head around I can still see the coordinates changing as well.

Client side:

function UpdateFunction() 
    local rotcam = math.rad (360 - getPedCameraRotation (localPlayer)) 
    local xpos,ypos,zpos = getPedBonePosition ( localPlayer, 8 ) 
    local xlook,ylook,zlook = xpos - 300*math.sin(rotcam), ypos + 300*math.cos(rotcam), zpos 
    if xlook and getElementHealth(localPlayer) > 0 then 
        triggerServerEvent("sendRotHead", localPlayer, xlook, ylook, zlook) 
    end 
end 
  
addEventHandler("onClientResourceStart",root, 
function () 
    setTimer(UpdateFunction,1000,0) 
end) 
  
  
addEvent("rotHead", true) 
addEventHandler("rotHead", root, 
function(xlook, ylook, zlook) 
    if isElement(source) then 
        outputDebugString(tostring(getPlayerName(source)).." X: "..xr.." Y: "..yr.." Z: "..zr) 
        setPedLookAt (source, xlook, ylook, zlook, -1) 
    end 
end) 

Server side:

addEvent("sendRotHead",true) 
addEventHandler("sendRotHead",root, 
function (xlook, ylook, zlook) 
    if isElement(source) then 
        triggerClientEvent(root,"rotHead",source, xlook, ylook, zlook) 
    end 
end) 

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...