-stolka- Posted April 21, 2014 Share Posted April 21, 2014 these 3 arrays are the cordinates of three hospitals, the fourth value is the distance... how do i make the player spawn ant the nearest one? x,y,z = getElementPosition( source ) local ho = {} ho[0] = { 2036.1735839844, -1413.0563964844, 16.9921875, 0 } -- x, y, z, distance ho[1] = { -2656.12, 631.01, 14.45, 0 } ho[2] = { 1607.07, 1825.3, 10.83, 0 } -- change 0 calculating the distance between the position of the player and the hospital ho[0][3] = getDistanceBetweenPoints3D ( x,y,z,ho[0][0], ho[0][1], ho[0][2] ) ho[1][3] = getDistanceBetweenPoints3D ( x,y,z,ho[1][0], ho[1][1], ho[1][2] ) ho[2][3] = getDistanceBetweenPoints3D ( x,y,z,ho[2][0], ho[2][1], ho[2][2] ) Link to comment
cheez3d Posted April 21, 2014 Share Posted April 21, 2014 There are at least 3 more topics about this. Use the search button. Link to comment
-stolka- Posted April 21, 2014 Author Share Posted April 21, 2014 There are at least 3 more topics about this. Use the search button. well there are no topics that use this system Link to comment
-stolka- Posted April 21, 2014 Author Share Posted April 21, 2014 i cant test it right now... is it correct x,y,z = getElementPosition( source ) local ho = {} ho[0] = { 2036.1735839844, -1413.0563964844, 16.9921875, 0 } ho[1] = { -2656.12, 631.01, 14.45, 0 } ho[2] = { 1607.07, 1825.3, 10.83, 0 } ho[0][3] = getDistanceBetweenPoints3D ( x,y,z,ho[0][0], ho[0][1], ho[0][2] ) ho[1][3] = getDistanceBetweenPoints3D ( x,y,z,ho[1][0], ho[1][1], ho[1][2] ) ho[2][3] = getDistanceBetweenPoints3D ( x,y,z,ho[2][0], ho[2][1], ho[2][2] ) local e=0 local i=0 local xs,ys,zs for e=0,3,1 do if ho[e][3] < ho[e+1][3] then xs = ho[e][0] ys = ho[e][1] zs = ho[e][2] end end setTimer (spawnPlayer, 1000, 1, source, xs,ys,zs, 0, getPedSkin (source), 0, 0, getPlayerTeam(source)) setTimer (setCameraTarget, 1250, 1, source, source) Link to comment
-stolka- Posted April 21, 2014 Author Share Posted April 21, 2014 i tested it.. it doesn't work any help? Link to comment
cheez3d Posted April 21, 2014 Share Posted April 21, 2014 local hospitals = { {2036.1735839844,-1413.0563964844,16.9921875,0}, {-2656.12,631.01,14.45,0}, {1607.07,1825.3,10.83,0} } addEventHandler("onPlayerWasted",root,function() local x,y = getElementPosition(source) local nearest = {} for k,position in ipairs(hospitals) do nearest[k] = {["distance"] = getDistanceBetweenPoints2D(x,y,position[1],position[2]),["position"] = position} end table.sort(nearest,function(a,b) return a["distance"]<b["distance"] end) setTimer(spawnPlayer,1000,1,source,nearest[1]["position"][1],nearest[1]["position"][2],nearest[1]["position"][3],0,getPedSkin(source),nearest[1]["position"][4],0,getPlayerTeam(source)) setTimer (setCameraTarget,1250,1,source,source) end) Not tested. Link to comment
Sasu Posted April 22, 2014 Share Posted April 22, 2014 You can take a look at my old post: viewtopic.php?f=91&t=61094&hilit=+nearest 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