Sasu Posted November 11, 2013 Share Posted November 11, 2013 I have this script: function onClientLookAtRender() for i,v in ipairs(getElementsByType("player")) do local rotcam = math.rad (360 - getPedCameraRotation (v)) local xpos,ypos,zpos = getPedBonePosition (v, 8 ) local xlook,ylook,zlook = xpos - 300*math.sin(rotcam), ypos + 300*math.cos(rotcam), zpos setPedLookAt (v, xlook, ylook, zlook, -1) end end addEventHandler ("onClientRender", root, onClientLookAtRender) But I saw that it does not work. The localPlayer works correctly but the other players only see to north, I think. Can you help me? Link to comment
myonlake Posted November 12, 2013 Share Posted November 12, 2013 Because client-side functions are only triggered to the remote client. You need to make it synchronize it with all players by hooking client- and server-side with a timer. Or you could also set element data on each player with the head rotation and in the render function you fetch all streamed in and on screen players and their head rotation and then set it. Link to comment
Sasu Posted November 12, 2013 Author Share Posted November 12, 2013 You mean to do a loop of all player and then use triggerClientEvent for each player? Link to comment
Moderators IIYAMA Posted November 12, 2013 Moderators Share Posted November 12, 2013 Well triggerClientEvent or elementdata. - TriggerClientEvent uses 3+ times more data but you can choose what player receives the data. (the closes players) - ElementData uses less data but it will send to all players directly. It depends on this: - 30+ players and for big maps (or full gta san) use triggerClientEvent. - Less players and players are all in the same part of the world, use elementdata. Use the command: /shownetstat to choose between those ways of data transfer. Link to comment
Sasu Posted November 12, 2013 Author Share Posted November 12, 2013 I tried with this but it doesnt work: function onClientLookAtRender() setElementData(localPlayer, "CRotation", getPedCameraRotation(localPlayer)) local cx,cy,cz = getPedBonePosition (localPlayer, -- s8) --> setElementData(localPlayer, "CRotationX", cx) setElementData(localPlayer, "CRotationY", cy) setElementData(localPlayer, "CRotationZ", cz) for i,v in ipairs(getElementsByType("player")) do local CCam = tonumber(getElementData(v, "CRotation")) or 0 local rotcam = math.rad (360 - CCam) local xpos,ypos,zpos = tonumber(getElementData(v, "CRotationX")), tonumber(getElementData(v, "CRotationY")), tonumber(getElementData(v, "CRotationZ")) local xlook,ylook,zlook = xpos - 300*math.sin(rotcam), ypos + 300*math.cos(rotcam), zpos setPedLookAt (v, xlook, ylook, zlook, -1) end end addEventHandler ("onClientRender", root, onClientLookAtRender) Then I tried with this other one but it doesnt work too: Server: function rotateHead() for i,v in ipairs(getElementsByType("player")) do triggerClientEvent("rotateHead", v) end end setTimer(rotateHead, 3000, 0) Client: addEvent("rotateHead", true) addEventHandler("rotateHead", root, function() local rotcam = math.rad (360 - getPedCameraRotation (source)) local xpos,ypos,zpos = getPedBonePosition (source, 8 ) local xlook,ylook,zlook = xpos - 300*math.sin(rotcam), ypos + 300*math.cos(rotcam), zpos setPedLookAt (source, xlook, ylook, zlook, -1) end) Link to comment
Moderators IIYAMA Posted November 12, 2013 Moderators Share Posted November 12, 2013 send this information over from server to client: https://wiki.multitheftauto.com/wiki/GetCameraMatrix float targetX, float targetY, float targetZ Link to comment
Sasu Posted November 12, 2013 Author Share Posted November 12, 2013 Something like this?: Server: function rotateHead() for i,v in ipairs(getElementsByType("player")) do local _,_,_, x,y,z = getCameraMatrix(v) triggerClientEvent("rotateHead", v, x, y, z) end end setTimer(rotateHead, 3000, 0) Client: addEvent("rotateHead", true) addEventHandler("rotateHead", root, function(rx, ry, rz) setPedLookAt (source, rx, ry, rz, -1) end) It says in debugscript 3: Bad Argument @ 'setPedLookAt' Link to comment
pa3ck Posted November 12, 2013 Share Posted November 12, 2013 You defined x, y, z not rx, ry, rz. You gotta correct that on the client side. Link to comment
Sasu Posted November 13, 2013 Author Share Posted November 13, 2013 It will not change anything because you can put everything you want as variable. Link to comment
xXMADEXx Posted November 13, 2013 Share Posted November 13, 2013 You need to trigger the client event for all of the players. Link to comment
WASSIm. Posted November 13, 2013 Share Posted November 13, 2013 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
OGF Posted November 13, 2013 Share Posted November 13, 2013 Something like this?:Server: function rotateHead() for i,v in ipairs(getElementsByType("player")) do local _,_,_, x,y,z = getCameraMatrix(v) triggerClientEvent("rotateHead", v, x, y, z) end end setTimer(rotateHead, 3000, 0) Client: addEvent("rotateHead", true) addEventHandler("rotateHead", root, function(rx, ry, rz) setPedLookAt (source, rx, ry, rz, -1) end) It says in debugscript 3: Bad Argument @ 'setPedLookAt' a Timer? are you crazy? Link to comment
pa3ck Posted November 13, 2013 Share Posted November 13, 2013 Something like this?:Server: function rotateHead() for i,v in ipairs(getElementsByType("player")) do local _,_,_, x,y,z = getCameraMatrix(v) triggerClientEvent("rotateHead", v, x, y, z) end end setTimer(rotateHead, 3000, 0) Client: addEvent("rotateHead", true) addEventHandler("rotateHead", root, function(rx, ry, rz) setPedLookAt (source, rx, ry, rz, -1) end) It says in debugscript 3: Bad Argument @ 'setPedLookAt' What I mean is that you triggered ('rotateHead', v, x, y, z) then you wanted to set the ped looking at rx, ry, rz, which is not defined. Link to comment
Moderators IIYAMA Posted November 13, 2013 Moderators Share Posted November 13, 2013 ignore pa3ck his post, it seems he doesn't know what the source is.... Btw try this: (not tested) It will give you better information about the head rotation, the default update of the camera matrix is 4 secs. addEvent("sendRotateHead",true) addEventHandler("sendRotateHead",root, function (xr,yr,zr) if isElement(source) then -- make sure he is still in game triggerClientEvent(root,"rotateHead",source,xr,yr,zr) end end) local headUpdateFunction = function () local x,y,z,xr,yr,zr = getCameraMatrix(localPlayer) if xr and getElementHealth(localPlayer) > 0 then triggerServerEvent("sendRotateHead", localPlayer, xr,yr,zr) end end addEventHandler("onClientResourceStart",root, function () setTimer(headUpdateFunction,1000,0) end) addEvent("rotateHead", true) addEventHandler("rotateHead", root, function(xr,yr,zr) if isElement(source then -- make sure he is still in game setPedLookAt (source, xr,yr,zr, 100) end end) Updated. Link to comment
Desaster Posted November 13, 2013 Share Posted November 13, 2013 idk if I am late try this function movePlayerHead() for k, players in ipairs(getElementsByType("player")) do if (getElementHealth(players) > 1) then local w, h = guiGetScreenSize() local lookatX, lookatY, lookatZ = getWorldFromScreenPosition(w/2, h/2, 10) setPedLookAt(players, lookatX, lookatY, lookatZ) end end end lol after reading this topic I saw that I use the same as wasim's one Link to comment
Sasu Posted November 13, 2013 Author Share Posted November 13, 2013 ignore pa3ck his post, it seems he doesn't know what the source is....Btw try this: (not tested) It will give you better information about the head rotation, the default update of the camera matrix is 4 secs. addEvent("sendRotateHead",true) addEventHandler("sendRotateHead",root, function (xr,yr,zr) if isElement(source) then -- make sure he is still in game triggerClientEvent(root,"rotateHead",source,xr,yr,zr) end end) local headUpdateFunction = function () local x,y,z,xr,yr,zr = getCameraMatrix(localPlayer) if xr and getElementHealth(localPlayer) > 0 then triggerServerEvent("sendRotateHead", localPlayer, xr,yr,zr) end end addEventHandler("onClientResourceStart",root, function () setTimer(headUpdateFunction,1000,0) end) addEvent("rotateHead", true) addEventHandler("rotateHead", root, function(xr,yr,zr) if isElement(source then -- make sure he is still in game setPedLookAt (source, xr,yr,zr, 100) end end) Updated. Now, the character is looking at me(camera). Something like this?:Server: function rotateHead() for i,v in ipairs(getElementsByType("player")) do local _,_,_, x,y,z = getCameraMatrix(v) triggerClientEvent("rotateHead", v, x, y, z) end end setTimer(rotateHead, 3000, 0) Client: addEvent("rotateHead", true) addEventHandler("rotateHead", root, function(rx, ry, rz) setPedLookAt (source, rx, ry, rz, -1) end) It says in debugscript 3: Bad Argument @ 'setPedLookAt' a Timer? are you crazy? Have you got any good idea? Link to comment
Moderators IIYAMA Posted November 13, 2013 Moderators Share Posted November 13, 2013 I will look at it tomorrow, probably because the camera end stops at the player. It should be extended. Link to comment
Moderators Vinyard Posted December 27, 2013 Moderators Share Posted December 27, 2013 Any ideas? It's a bit late to ask, but who knows.. Link to comment
Moderators IIYAMA Posted December 27, 2013 Moderators Share Posted December 27, 2013 Any ideas? It's a bit late to ask, but who knows.. Ah, you are hunting for free scripts... I know because I already fixed it and shared it with the poster. So yes a bit late, Link to comment
pa3ck Posted December 27, 2013 Share Posted December 27, 2013 Any ideas? It's a bit late to ask, but who knows.. Ah, you are hunting for free scripts... I know because I already fixed it and shared it with the poster. So yes a bit late, Could you give us some instructions on which functions are needed? Link to comment
Moderators IIYAMA Posted December 27, 2013 Moderators Share Posted December 27, 2013 For what I created: "onClientResourceStart" "onClientRender" "onPlayerSpawn" triggerClientEvent table = {} getNetworkStats getDistanceBetweenPoints3D getTickCount and much more... for a working a script, that's keeping up the performance of your internet speed. At the moment I am busy with something similar to combination of slothbot and dayZ, I don't have time to guide you, sorry. Link to comment
pa3ck Posted December 27, 2013 Share Posted December 27, 2013 Mkaay, so it's not an easy thing, is it? Thanks anyways. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now