Jump to content

problem[Table]


Recommended Posts

local v={
{1108.4, -1720.36, 13.55-1},
{1146.03, -1749.56, 13.57-1},
{1150.04, -1732.18, 13.77-1},
{1134.05, -1724.94, 13.9-1}
}
value1=false
value2=false
value3=false

mymarker={}
function getnerpos()

local aTable={}
local x,y,z=getElementPosition(localPlayer)
for k,m in ipairs(v)do
local newmin=getDistanceBetweenPoints3D (x,y,z,m[1],m[2],m[3])
if value1~=m[1] and value2~=m[2] and value3~=m[3] then
table.insert(aTable,{newmin,m[1],m[2],m[3]})
table [ 'sort' ] ( aTable , function ( aVar1 , aVar2 ) return ( aVar1 [ 1 ] < aVar2[1] ) end )
end
end
for g,k in ipairs(v)do
if aTable[1][2]==k[1] and aTable[1][3]==k[2] and aTable[1][4]==k[3] then
 mymarker[localPlayer]= createMarker ( k[1], k[2], k[3], "cylinder", 5, 255, 255, 0, 170 )
value1=k[1]
value2=k[2]
value3=k[3]
 blip=createBlipAttachedTo(mymarker[localPlayer],0)
 table.remove(v,k[1],k[2],k[3])

 end
end
end

it's create a marker but it doesn't remove position from table 

and create the same marker with the same position 

Link to comment
45 minutes ago, Tails said:

Tell us exactly what you're trying to do. We need more information.

It looks like you're trying to place a marker at the nearest position to the player?

I can write you an example but it might not be what you want.

 

yes i want place a marker at nearest position to player from the table and when he hit the marker the marker position  remove  from table

and create another marker

 

Edited by Master_MTA
Link to comment

Try this (untested)

function getPosNearPlr(plr)
	local sorted = {}
	local x, y, z = getElementPosition(plr)
	for i, v in ipairs(positions) do
		local d = getDistanceBetweenPoints3D(x, y, z, v[1], v[2], v[3])
		sorted[i] = {pos = v, dist = d}
	end
	table.sort(sorted, function(a, b) return a.dist < b.dist end)
	
	for i=1, #sorted do
		positions[i] = v.pos
	end
	
	table.remove(positions, 1)
	
	return sorted[1].pos
end

local pos = getPosNearPlr(localPlayer)

 

Edited by Tails
  • Like 1
Link to comment
40 minutes ago, Tails said:

Oops an error. It was too late to edit it.


for i=1, #sorted do
  positions[i] = v.pos
end

-- should be

for i=1, #sorted do
  positions[i] = sorted[i].pos
end

 

it's work great thx alot

can you enplane to me  what does you did?

i didn't understood 

45 minutes ago, Tails said:

Oops an error. It was too late to edit it.


for i=1, #sorted do
  positions[i] = v.pos
end

-- should be

for i=1, #sorted do
  positions[i] = sorted[i].pos
end

 

 

  • Like 1
Link to comment
2 hours ago, Master_MTA said:

thx now i understood

 

Yeah, I just replaced the positions table with the sorted one, and then removed the first position. If you want to reuse the positions you could instead of removing the position, add use new variable that stores the current position index. Then every time you hit a marker you add 1 to it till you get to the end then you reset it.

Link to comment
Just now, Tails said:

Yeah, I just replaced the positions table with the sorted one, and then removed the first position. If you want to reuse the positions you could instead of removing the position, add use new variable that stores the current position index. Then every time you hit a marker you add 1 to it till you get to the end then you reset it.

yeah in the first time i thought it difficult but When I looked at it well i saw what does you did thx  

  • Like 1
Link to comment

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