'LinKin Posted January 1, 2014 Share Posted January 1, 2014 (edited) Hello, When I create an arrow and attach it to a player, I want it to be visible only for the player that it's attached to.. How can I do that via serverside? setElementVisibleTo ( theArrow, getRootElement(), false ) did not work.. Everyone can see the arrow Edited January 1, 2014 by Guest Link to comment
xXMADEXx Posted January 1, 2014 Share Posted January 1, 2014 create the arrow on the client side, and use this function in onClientPreRender https://wiki.multitheftauto.com/wiki/FindRotation Link to comment
'LinKin Posted January 2, 2014 Author Share Posted January 2, 2014 Hm Does someone know how can I rotate the arrow so that it points to a moving vehicle everytime? It's kinda hard because the vehicle is on movement... Link to comment
xXMADEXx Posted January 2, 2014 Share Posted January 2, 2014 (Not Tested) local car = createVehicle ( 0, 0, 0 ) local arrow = createObject ( the_arrow_id, 0, 0, 0 ) addEventHandler ( "onClientPreRender", root, function ( ) local cx, cy, cz = getElementPosition ( car ) local x, y, z = getElementPosition ( localPlayer ) local rot = findRotation ( cx, cy, x, y ) setElementPosition ( arrow, x, y, z + 1 ) setElementRotation ( arrow, 0, 0, rot ) end ) function findRotation(x1,y1,x2,y2) local t = -math.deg(math.atan2(x2-x1,y2-y1)) if t < 0 then t = t + 360 end; return t; end Link to comment
'LinKin Posted January 2, 2014 Author Share Posted January 2, 2014 Thanks. Btw, why onClientPreRender and not onClientRender? Link to comment
xXMADEXx Posted January 2, 2014 Share Posted January 2, 2014 Thanks.Btw, why onClientPreRender and not onClientRender? If you use onClientRender, the arrow is very laggy. onClientPreRender smooths it out. Link to comment
'LinKin Posted January 2, 2014 Author Share Posted January 2, 2014 Also. Is it possible that the arrow points to a target in 3D? I mean, I see most of GPS systems just turn the arrow horizontally. Is it possible to make an arrow point to the target vertically too? For example; If the target is under you, it points down. If target's over you, it points up. If target's diagonally, it points diagonally (vertical & horizontal rotation) Link to comment
xXMADEXx Posted January 2, 2014 Share Posted January 2, 2014 Also.Is it possible that the arrow points to a target in 3D? I mean, I see most of GPS systems just turn the arrow horizontally. Is it possible to make an arrow point to the target vertically too? For example; If the target is under you, it points down. If target's over you, it points up. If target's diagonally, it points diagonally (vertical & horizontal rotation) It is, but you'd need to make your own "findRotation" function for that. Link to comment
Jusonex Posted January 2, 2014 Share Posted January 2, 2014 function GPS:update() local vehicle = getPedOccupiedVehicle(localPlayer) if not vehicle then self:stopNavigation() return end local x, y, z = getElementPosition(vehicle) local horizontalRotation = findRotation(x, y, self.m_Destination.X, self.m_Destination.Y) - 90 local verticalRotation = math.deg(math.asin((self.m_Destination.Z - z) / getDistanceBetweenPoints3D(self.m_Destination.X, self.m_Destination.Y, self.m_Destination.Z, x, y, z))) setElementPosition(self.m_Arrow, x, y, z + 1) setElementRotation(self.m_Arrow, 0, 90 + verticalRotation, horizontalRotation) end Link to comment
'LinKin Posted January 2, 2014 Author Share Posted January 2, 2014 What is that, Jusonex?.. I see it's like a part of a script. Link to comment
Jusonex Posted January 2, 2014 Share Posted January 2, 2014 It's a function that calculates the rotation you need to point to a specified position. Transferred to your code: local car = createVehicle ( 0, 0, 0 ) local arrow = createObject ( the_arrow_id, 0, 0, 0 ) addEventHandler ( "onClientPreRender", root, function ( ) local cx, cy, cz = getElementPosition ( car ) local x, y, z = getElementPosition ( localPlayer ) local rotH = findRotation ( cx, cy, x, y ) - 90 local rotV = math.deg(math.asin((cz - z) / getDistanceBetweenPoints3D(cx, cy, cz, x, y, z))) setElementPosition ( arrow, x, y, z + 1 ) setElementRotation ( arrow, 0, 90 + rotV, rotH ) end ) Link to comment
'LinKin Posted January 3, 2014 Author Share Posted January 3, 2014 Thanks. Now I'm looking at Jusonex's script and I see that the arrow that he creates is different from the one I create.. I'm currently using this arrow_id = 1318 Jusonex, can you tell me which arrow_id you're using? Because yours is way better than mine. (More visible, understable) This is what my arrow looks like: http://i.imgur.com/Owe1rs0.png http://i.imgur.com/tCcJsCn.png Link to comment
Jusonex Posted January 4, 2014 Share Posted January 4, 2014 That's a very old script (and if I remember correctly it's compiled). I'm currently using this arrow_id = 1318 I'm using the same object. I uploaded my current object-oriented version here: http://www.jusonex.net/public/mta/navi.zip Link to comment
denny199 Posted January 4, 2014 Share Posted January 4, 2014 I posted this some days ago: function findPitch(camerax,cameray,cameraz,pointx,pointy,pointz) local dX=camerax-pointx local dY=cameraz-pointz local dZ=cameray-pointy local pitch=math.atan2(dY,math.sqrt(math.pow(dZ,2) + math.pow(dX,2))); return pitch end It's returning in radians, so you need to convert it to degrees: local degree = pitchReturn*(180/math.pi) pitchReturn = The "findPitch" function. It's the same as findRotation but then for the X rotation (up and down) so if someone is underneath you it will calculate the position under you. Here's a little example with a plane: function findYaw(x1,y1,x2,y2) local zRot = -math.deg(math.atan2(x2-x1,y2-y1)) if zRot < 0 then zRot = zRot + 360 end; return zRot; end function findPitch(camerax,cameray,cameraz,pointx,pointy,pointz) local dX=camerax-pointx local dY=cameraz-pointz local dZ=cameray-pointy local pitch=math.atan2(dY,math.sqrt(math.pow(dZ,2) + math.pow(dX,2))); return pitch end car = createVehicle ( 513, 0,0, 10 ) addEventHandler ( "onClientPreRender", root, function () local x,y,z = getElementPosition (localPlayer) local pointX, pointY, pointZ = getElementPosition ( car ) local rotZ = findYaw(pointX, pointY,x,y) local rotX = findPitch(pointX,pointY,pointZ, x,y,z) local degreePitch = rotX*(180/math.pi) setElementPosition ( car, 0,0, 10 ) setElementRotation ( car,-degreePitch,0,rotZ) end) findYaw is the same function as "findRotation". Edit: Put the degree return always in the "-", or else it will point the other way Regards, Danny Link to comment
arezu Posted January 5, 2014 Share Posted January 5, 2014 Why not just create arrow and attach it to the player? like editor does. Link to comment
'LinKin Posted January 5, 2014 Author Share Posted January 5, 2014 Thanks Danny, arezu, Justonex. As I said, it's working fine, the horizontal and vertical rotation is perfect. I was just asking for the model of the arrow, because my arrow is different from others.. I don't know why. Im using the same model as others. Maybe it is something else that changes its aspect? Link to comment
Saml1er Posted January 5, 2014 Share Posted January 5, 2014 I'm not a pro at math but the solution is quite simple as I see. In shooter maps we always shoot rockets in straight direction, so you want that arrow to be in straight direction, right? So download an shooter map and there should be 4 lines where math.cos is used, just use thèse four lines to get the position and to to keep the arrow in straight direction and add onClientRender to get the rotation. Right now I'm away from home, once I'm back. I'll help you then. Link to comment
'LinKin Posted January 5, 2014 Author Share Posted January 5, 2014 Gosh. Arrow is pointing ok! I'm asking about the model of the arrow. Visual aspect Link to comment
.:HyPeX:. Posted January 6, 2014 Share Posted January 6, 2014 If you use onClientRender, the arrow is very laggy. onClientPreRender smooths it out. this is based on what??.. Link to comment
denny199 Posted January 6, 2014 Share Posted January 6, 2014 Gosh.Arrow is pointing ok! I'm asking about the model of the arrow. Visual aspect Whats wrong with the model, is it to small, or to big?? Link to comment
'LinKin Posted January 6, 2014 Author Share Posted January 6, 2014 It's not a big problem, just wondering why that happen Thanks.This is what my arrow looks like: http://i.imgur.com/Owe1rs0.png http://i.imgur.com/tCcJsCn.png This is what other arrows look like (from Justonex's script and some other server) https://community.multitheftauto.com/im ... s/3811.png http://img837.imageshack.us/img837/1378/443s.png http://img855.imageshack.us/img855/1285/2q7c.png http://img59.imageshack.us/img59/5126/du7y.png http://img31.imageshack.us/img31/2687/4bad.png Link to comment
denny199 Posted January 6, 2014 Share Posted January 6, 2014 Hmm, do you have any shaders on the server? Also try to disable all the textures on the server, and also to set the time to 12:00 to see any difference.. 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