Jump to content

How to turn a distance between two points into a percentage?


drk

Recommended Posts

Posted

I want to turn this distance between two points:

function drawDistance ( ) 
    local x, y, sx, sy 
    loadHunterPosition ( ) 
    local playerX, playerY, playerZ = getElementPosition ( getLocalPlayer( ) ) -- Get player position 
    local distFromVehicleToHunter = getDistanceBetweenPoints3D ( playerX, playerY, playerZ, hunterX, hunterY, hunterZ ) -- Calculate distance 
    x, y = AbsoluteToRelativ(1920-721, 1080-55) 
    sx, sy = AbsoluteToRelativ( 1920-515,1080-36 ) 
    dxDrawText ("   Distance:",x, y, sx, sy,tocolor(192,255,62,255),0.6,"bankgothic","left","top",false,false,false) -- Create DX Text 
    x, y = AbsoluteToRelativ(1920-699, 1080-31) 
    sx, sy = AbsoluteToRelativ( 265, 30 ) 
    dxDrawImage( x, y, sx, sy,"images/DistToHunter-Logo.png",0.0,0.0,0.0,tocolor(255,255,255,255),false) 
    x, y = AbsoluteToRelativ(1920-494, 1080-54) 
    sx, sy = AbsoluteToRelativ( 1920-366,800-10 ) 
    dxDrawText( string.format("%.0f",distFromVehicleToHunter).."m",x, y, sx, sy,tocolor(255,255,255,255),0.6,"bankgothic","left","top",false,false,false) 
end 

into a percentage. It can be done? If it can be done anyone can help me how to do :S

Posted

\õ/ I want to made a script that appear on the local player screen with percentage of distance missing to reach hunter. Understand?

Posted
I know it can be done, but it's gonna take some math logic and some more scripting, srry i'm not good with percentage or math

Im not good with percentage or math too :S

Posted
distance=pos2-pos1 --use getDistanceBetweenPoints if 2/3D needed 
currentDistance=pos2-yourPos --use getDistanceBetweenPoints if 2/3D needed 
precents=math.min(math.max(math.abs(currentDistance/distance*100),0),100) 

seriously, you should figure this easy thing on yourself

  • 3 months later...
Posted

the easiest way is to just:

local hunterDistance = currentDistanceToHunter/maxDistanceToHunter

where currentDistanceToHunter is current distance between player and hunter pickup, and

maxDistanceToHunter is distance between player spawn position and hunter pickup.

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