Jump to content

[HELP] Moving head with mouse


hrtht

Recommended Posts

3 hours ago, MrTasty said:

Share the code that you need help with, or at least tell us which script it is if it's from MTASA community resources website.

addEventHandler("onClientRender", getRootElement(), function()

for k,player in ipairs(getElementsByType("player")) do
if getElementHealth(player) >= 1 then
local width, height = guiGetScreenSize ()
local lx, ly, lz = getWorldFromScreenPosition ( width/2, height/2, 10 )
setPedLookAt(player, lx, ly, lz)
end 
end
   
end)

Link to comment

You're setting everyone's look-at coordinates to the centre of the localPlayer's screen, not the respective player's screen. Also, last time I used setPedLookAt, it didn't work for remote players correctly. Also, read the Wiki notices (specifically the first one - don't run this on onClientRender):

Note: Avoid calling setPedLookAt every frame as this can cause bugs like being invincible to burning.
Note: For remote players, you have to use setPedAimTarget before setPedLookAt.
Link to comment
3 hours ago, MrTasty said:

You're setting everyone's look-at coordinates to the centre of the localPlayer's screen, not the respective player's screen. Also, last time I used setPedLookAt, it didn't work for remote players correctly. Also, read the Wiki notices (specifically the first one - don't run this on onClientRender):

Note: Avoid calling setPedLookAt every frame as this can cause bugs like being invincible to burning.
Note: For remote players, you have to use setPedAimTarget before setPedLookAt.

I started days ago on this.. if you can send me the code it would be great man

Link to comment

All you should do is get new look at coordinates -> send to server -> sync to others clients
but remember; dont try to destroy your server's network :D
 

--serverside
addEvent('syncLookAt', true)
addEventHandler('syncLookAt', root, function(x,y,z)
	triggerLatentClientEvent("setLookAt", 30000, false, client, x,y,z)
	-- triggerClientEvent("setLookAt", client, x,y,z)
end)

--clientside
local screenW, screenH = guiGetScreenSize()

setTimer(function()
    local x,y,z = getWorldFromScreenPosition(screenW*0.5, screenH*0.5, 10)
    triggerLatentServerEvent("syncLookAt", 30000, false, localPlayer, x,y,z)
--    triggerServerEvent("syncLookAt", localPlayer, x,y,z)
end, 200, 0)

addEvent('setLookAt', true)
addEventHandler('setLookAt', root, function(x,y,z)
    setPedLookAt(source, x,y,z)
end)

 

Edited by iDannz [Breno]
  • Like 1
Link to comment
3 hours ago, iDannz [Breno] said:

All you should do is get new look at coordinates -> send to server -> sync to others clients
but remember; dont try to destroy your server's network :D
 


--serverside
addEvent('syncLookAt', true)
addEventHandler('syncLookAt', root, function(x,y,z)
	triggerLatentClientEvent("setLookAt", 30000, false, client, x,y,z)
	-- triggerClientEvent("setLookAt", client, x,y,z)
end)

--clientside
local screenW, screenH = guiGetScreenSize()

setTimer(function()
    local x,y,z = getWorldFromScreenPosition(screenW*0.5, screenH*0.5, 10)
    triggerLatentServerEvent("syncLookAt", 30000, false, localPlayer, x,y,z)
--    triggerServerEvent("syncLookAt", localPlayer, x,y,z)
end, 200, 0)

addEvent('setLookAt', true)
addEventHandler('setLookAt', root, function(x,y,z)
    setPedLookAt(source, x,y,z)
end)

 

Still doesn't work, the head is stuck to the right, I want it for all not just local player man

Link to comment
On 17/03/2020 at 00:49, iDannz [Breno] said:

its working fine here, just tested it now.

I would also like to know the answer to this question. This only works for the local client. that is, you see where the head is turning, and for the other player you have your head "turned in one direction and froze" although you turn your head. On the local side, everything is fine, but how to implement this correctly for other players?

Link to comment
  • 3 weeks later...

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