Sign in to follow this  
slapz0r

Head script

Recommended Posts

Posted (edited)

I have script for head (head rotation by mouse). but it's cliend side and only 1 player sees this. I mean only 1 player can see this actions(Example You can see only your head rotation but not other players) How to make it translate to the server so that all players see the head rotation? 

Quote

 

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)

 

 

Edited by slapz0r

Share this post


Link to post
-- remove setPedLookAt function and replace it to :
triggerServerEvent("onMyEvent",localPlayer,player,lx,ly,lz)

then from server to client :

addEvent("onMyEvent",true)
addEventHandler("onMyEvent",root,
  function(ped,lx,ly,lz)
    for k, v in ipairs (getElementsByType("player")) do
 		 triggerClientEvent(v,"onClientMyEvent",v,ped,lx,ly,lz);
    end
 end
)

then you'll receive this event in the client side onClientMyEvent

and put the (SetPedLookAt) function inside the event function ..

addEvent("onClientMyEvent",true);
function eventFunc(ped,lx,ly,lz)
  setPedLookAt(ped,lx,ly,lz);
end
addEventHandler("onClientMyEvent",root,eventFunc)

 

Share this post


Link to post

For performance reason I don't advise you to do that on a server with a lot of people connected

Share this post


Link to post
14 hours ago, NX_CI said:

-- remove setPedLookAt function and replace it to :
triggerServerEvent("onMyEvent",localPlayer,player,lx,ly,lz)

then from server to client :


addEvent("onMyEvent",true)
addEventHandler("onMyEvent",root,
  function(ped,lx,ly,lz)
    for k, v in ipairs (getElementsByType("player")) do
 		 triggerClientEvent(v,"onClientMyEvent",v,ped,lx,ly,lz);
    end
 end
)

then you'll receive this event in the client side onClientMyEvent

and put the (SetPedLookAt) function inside the event function ..


addEvent("onClientMyEvent",true);
function eventFunc(ped,lx,ly,lz)
  setPedLookAt(ped,lx,ly,lz);
end
addEventHandler("onClientMyEvent",root,eventFunc)

 

Rotation the heads of other players is still not visible. and I had problems with a local player. The head began to vibrate hard

Share this post


Link to post
4 hours ago, slapz0r said:

Rotation the heads of other players is still not visible. and I had problems with a local player. The head began to vibrate hard

Remove my edits and restore your code

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.