Spice Posted July 3, 2015 Share Posted July 3, 2015 Hello guys, i want to make the player get spawned to the nearest spawn point (the spawn points in the table) so how can i do that ? locations = { {x = 2030.73840, y = -1404.19531, z = 17.26210} {x = 1178.60681 -1324.14050 14.12840} } function loc () spawnPlayer (source, locations[1]["x"], locations[1]["y"], locations[1]["z"]) end addEventHandler ( "onPlayerWasted", getRootElement(), loc ) Link to comment
xXMADEXx Posted July 3, 2015 Share Posted July 3, 2015 You just have to loop the table and compare all the distances with getDistanceBetweenPoints3D locations = { {x = 2030.73840, y = -1404.19531, z = 17.26210} {x = 1178.60681, y= -1324.14050, z= 14.12840} } function loc () local index = 1 local x, y, z = getElementPosition ( source ); for i, v in pairs ( locations ) do if ( getDistanceBetweenPoints3D ( v.x, v.y, v.z, x, y, z ) < getDistanceBetweenPoints3D ( locations[index].x, locations[index].y, locations[index].z, x, y, z ) ) then index = i end end spawnPlayer ( source, locations[index].x, locations[index].y, locations[index].z ); end addEventHandler ( "onPlayerWasted", getRootElement(), loc ) 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