Jump to content

track player


Wisin

Recommended Posts

Posted

hi, i made a track script that allows the player to track another player and a label will appear at screen with the meters he is from you, all working fine but i want to make like "Robot is approximately 50 north from you" my question is, how i make that "north" or "south"?

thanks in advance.

Posted

you need all directions (W E N S) or just N S ? if Y of "robot" > Y of player - north, else - south.

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

i asked you if you need only N/S or all directions?... you didnt answer

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

you need to get distance 2d between player and robot, "virtually create" point C placed your distance length to north ( so X of player, Y + distance),

count the angle PLAYER, C, ROBOT (trigonometry, search wikipedia), now if robot X < player X - add 180 to result.

you will get direction (azimuth). now if its:

0-45 or 315-360 == north

45-135 == east

135-225 = south

225 - 315 = west

edit: function to count angle between 3 points:

  
function getAngleBetweenPoints2D(ax,ay,bx,by,cx,cy) 
    local AB = { ax-bx, ay-by } 
    local BC = { cx-bx, cy-by } 
    local AB_ = getDistanceBetweenPoints2D(ax,ay,bx,by) 
    local BC_ = getDistanceBetweenPoints2D(bx,by,cx,cy) 
    local iloczynSkalarny = AB[1]*BC[1] + AB[2]*BC[2] 
    local tmp = iloczynSkalarny/(AB_*BC_) 
    local kat = math.acos(tmp) 
    local degrees = kat*180/(22/7) 
    --outputChatBox("deg "..degrees) 
    return degrees 
end 
-- note: in my script there was angle invertion on return (180-degrees) - not sure if you should use it or not, as i dont remember it exactly 
  

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

i made this but keeps returning "north" and "east"

x, y, z = getElementPosition ( ped ) 
x2, y2, z2 = getElementPosition ( player ) 
distance = getDistanceBetweenPoints2D ( x, y, x2, y2 ) 
local newvalue = math.floor ( distance ) 
local loc = getAngleBetweenPoints2D(x,y,x2,y2,x,y2) 
if loc < 45 then 
loca = "north" 
elseif loc < 135 then 
loca = "east" 
elseif loc < 225 then 
loca = "south" 
elseif loc < 315 then 
loca = "west" 

Posted

you didnt read carefully..

try this one, should work, but im not a math god, also this was written in browser..

  
local px,py,pz = getElementPosition(player) 
local rx, ry, rz = getElementPosition(bot) 
local distanceBetweenPlayerAndBot = getDistanceBetweenElements2D(px,py,rx,ry) 
local cx = px 
local cy = py+distanceBetweenPlayerAndBot 
local angle = getAngleBetweenPoints2D(px,py,cx,cy,rx,ry) 
if rxif (angle >= 0 and angle < 45) or (angle > 315 and angle <= 360) then 
  direction = "north" 
elseif (angle>45 and angle <= 135) then 
  direction = "east" 
elseif (angle>135 and angle <= 225) then 
  direction = "south" 
elseif (angle>225 and angle <= 315) then 
  direction = "west" 
end 
  

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

dosn't works makes this error: attempt to call global 'getDistanceBetweenElements2D' (a nil value), at line: local distanceBetweenPlayerAndBot = getDistanceBetweenElements2D(px,py,rx,ry)

Posted

maybe try doing something by yourself?

i told you it was written in browser - the only thing you had to do is open wiki and see my mistake.

it's: getDistanceBetweenPoints2D

...

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

are directions ok? or just script is not broking? im wondering if i did everything right as i suck at maths

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

are the directions correct? not inverted or just random?

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

lol, just go to the north from the bot and check if it is saying "south"? :P same for other directions..

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

Posted

your welcome, im happy that math thing done by me actually worked :D

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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