Jump to content

[Question] Adding/Getting elements for a table


kieran

Recommended Posts

Hello, I am doing my first "big" script, basically the first useful one haha...

I create blips for locations in a table, then set a timer, but I have forgot how to add and retrieve elements (in this case the blips) and was wondering if someone could help, only have the needed code to keep it easy to read.

Client side script

local ATM_Locations = {
	{1505.16626, -1750.68909, 13.54688},--1
	{1690.0927734375, -2334.8369140625, 13.546875},--2
	{1951.19543, -2175.53784, 13.55421},--3
	{2041.50390625, -1430.728515625, 17.1640625},--4
	{1878.06372, 2073.94067, 11.06250},--5
	{2280.76465, 2431.10596, 10.82031},--6
	{2020.86316, 1016.50653, 10.82031},--7
	{-1210.31104, 1834.64917, 41.92969},--8
	{174.82074, 1175.05469, 14.75781},--9
	{1380.58093, 260.50055, 19.56693},--10
	{1238.48145, 327.90039, 19.75551},--11
	{1626.68469, 1815.06384, 10.82031}--12
}

blips = false

local Blips = {}

function blips()
    for i=1,#ATM_Locations do 
        local x,y,z = ATM_Locations[i][1],ATM_Locations[i][2],ATM_Locations[i][3]
        Blips[i] =  createBlip ( x, y, z, 3, 2)
		blips = true
		setTimer( destroyBlips, 10000, 1)
    end
end

addCommandHandler( "ATM", blips, false )


function destroyBlips()
	if (blips == true) then
		destroyElement(Blips) 
	end
end

Don't pay attention to blip type, will change later haha.

Link to comment
  • Moderators
for i = 1, #Blips do
	local blip = Blips[i]
	if isElement(blip) then
		destroyElement(blip)
	end
end

 

 

Please also take a look at: (which can come in handy if you want to destroy multiple elements in once)

 

If you destroy a parent element, all child elements will also be destroyed.

 

 

 

Edited by IIYAMA
  • Thanks 1
Link to comment
local ATM_Locations = {
	{1505.16626, -1750.68909, 13.54688},--1
	{1690.0927734375, -2334.8369140625, 13.546875},--2
	{1951.19543, -2175.53784, 13.55421},--3
	{2041.50390625, -1430.728515625, 17.1640625},--4
	{1878.06372, 2073.94067, 11.06250},--5
	{2280.76465, 2431.10596, 10.82031},--6
	{2020.86316, 1016.50653, 10.82031},--7
	{-1210.31104, 1834.64917, 41.92969},--8
	{174.82074, 1175.05469, 14.75781},--9
	{1380.58093, 260.50055, 19.56693},--10
	{1238.48145, 327.90039, 19.75551},--11
	{1626.68469, 1815.06384, 10.82031}--12
}

blips = {}

local Blips = {}

function blips()
	for i=1,#ATM_Locations do 
		local x,y,z = ATM_Locations[i][1],ATM_Locations[i][2],ATM_Locations[i][3]
		Blips[i] = createBlip (x,y,z,3,2)
		blips[player] = true
		setTimer(function()
			if blips[player] then
				if blips[player] == true then
					for i,v in pairs(Blips) do
						destroyElement(v)
					end
					blips[player] = false
				end
			end
		end,10000,1)
	end
end
addCommandHandler('ATM',blips,false)

 

Edited by shay103
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...