Jump to content

[HELP] How to create marker with random position from table?


Tokio

Recommended Posts

44 minutes ago, <~KaMiKaZe~> said:

local marks = { coordenates of your marker, coordenates of your other marker } 

function markes()
markz = createMarker( marks[math.random(1, #marks)], "cylinder", 1.5, 255, 255, 0, 170 )
end

 

local markers = {}

function addMarker(x,y,z,type,size,r,g,b,a,visible)
    local self = {}
    self.x = x or 0
    self.y = y or 0
    self.z = z or 0
    self.type = type or 'checkpoint'
    self.size = size or 1
    self.r = r or 0
    self.g = g or 0
    self.b = b or 0
    self.a = a or 255
    self.visible = visible or root
    
    table.insert(markers,self)
    return self
end

function startMarkers()
    for i=1,#markers do
        local m = markers[i]
        if m.marker then
            if isElement(m.marker) then
                destroyElement(m.marker)
            end
        end
        m.marker = createMarker(m.x,m.y,m.z,m.type,m.size,m.r,m.g,m.b,m.a,m.visible)
    end
end

local marker1 = addMarker(0,0,0,'cylinder',1,0,255,255,root)
startMarkers()

Maybe this script isn't what you wanted, however it allows you to store markers in a table without triggering them. It allows you to trigger them whenever you want. That way you could do what you want with the table, you know adding positions, but this way you're adding the entire marker. And then creating it whenever you want.
I hope you find this helpful, have a nice day.

Here is what you were looking for,  I hope you have a nice day.

local positions = {
    {x=0,y=0,z=0},
    {x=1,y=1,z=1},-- use whatever positions u want
    {x=2,y=2,z=2}
}

function marker(type,size,r,g,b,a,visible)
    local type = type or 'cylinder'
    local size = size or 1
    local r,g,b,a = r,g,b,a or 255,255,255,255
    local visible = visible or root
    local pos = positions[math.random(1,#positions)]
    return createMarker(pos.x,pos.y,pos.z,type,size,r,g,b,a,visible)
end

local mark = marker()-- this allows u to not put values in if u dont want to.

 

Also this may help you for future scripts.

function getRandomFromTable(tab)
    if tab and tab[2] then
        local rand = math.random(1,#tab)
        return tab[rand]
    end
end
local pos = getRandomFromTable(positions)

 

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