Jump to content

[HELP]Loop for markers


Recommended Posts

Good Day to all, im trying to make a loop for a markers,these markers are in a table, but only appears 1... see my code, a lot of thanks

markers = { createMarker(345.52288818359, 165.7333984375, 1014.1875, "cylinder", 1.5, 255, 255, 0, 150), 
            createMarker(347.45263671875, 167.09187316895, 1007.3828125, "cylinder", 1.5, 255, 255, 0, 150), 
            createMarker(349.38757324219, 167.09187316895, 1007.3828125, "cylinder", 1.5, 255, 255, 0, 150), 
            createMarker(349.40020751953, 167.09187316895, 1007.3828125, "cylinder", 1.5, 255, 255, 0, 150), 
            createMarker(347.81915283203, 167.09187316895, 1007.3828125, "cylinder", 1.5, 255, 255, 0, 150), 
            createMarker(345.10681152344, 167.09187316895, 1007.3828125, "cylinder", 1.5, 255, 255, 0, 150), 
            createMarker(349.04412841797, 167.09187316895, 1007.3828125, "cylinder", 1.5, 255, 255, 0, 150)} 
            for i, marker in ipairs( markers ) do 
                setElementDimension(marker, 200) 
                setElementInterior(marker, 3) 
            end 

Link to post

Hello there,

Your code is totally messy, No need to repeat the function "createMarker" all the time, loop is making all datas inside a table in one function and in short way

I made this part for you , to learn from it

local markers = { 
 {345.52288818359, 165.7333984375, 1014.1875}, 
 {347.45263671875, 167.09187316895, 1007.3828125}, 
 {349.38757324219, 167.09187316895, 1007.3828125}, 
 {349.40020751953, 167.09187316895, 1007.3828125}, 
 {347.81915283203, 167.09187316895, 1007.3828125},  
 {345.10681152344, 167.09187316895, 1007.3828125}, 
 {349.04412841797, 167.09187316895, 1007.3828125} 
} 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, val in ipairs(markers) do 
        local marker = createMarker(val[1], val[2], val[3]-1, "cylinder", 1.5, 255, 255, 0, 150) 
        setElementInterior(marker, 3) 
        setElementDimension(marker, 200) 
    end 
end) 

Edited by Guest
Link to post
Oh thanks! but if someone hit for example the first marker how can i define it for destroy only these marker? really thanks carim

You can define them inside the table like that

local markers = { 
 {345.52288818359, 165.7333984375, 1014.1875,"Marker1"}, 
 {347.45263671875, 167.09187316895, 1007.3828125,"Marker2"}, 
 {349.38757324219, 167.09187316895, 1007.3828125,"Marker3"}, 
 {349.40020751953, 167.09187316895, 1007.3828125,"Marker4"}, 
 {347.81915283203, 167.09187316895, 1007.3828125,"Marker5"}, 
 {345.10681152344, 167.09187316895, 1007.3828125,"Marker6"}, 
 {349.04412841797, 167.09187316895, 1007.3828125,"Marker7"} 
} 
   
  

Link to post
So, i can call it when i define the function whit the event handler onMarkerHit? like
function exampleFunction() 
    outputChatBox("You are in the Marker1") 
addEventHandler("onMarkerHit", Marker1, exampleFunction 

Thanks!

Like that not possible

Link to post

Try something like that

local markers = { 
 {345.52288818359, 165.7333984375, 1014.1875,"Marker1"}, 
 {347.45263671875, 167.09187316895, 1007.3828125,"Marker2"}, 
 {349.38757324219, 167.09187316895, 1007.3828125,"Marker3"}, 
 {349.40020751953, 167.09187316895, 1007.3828125,"Marker4"}, 
 {347.81915283203, 167.09187316895, 1007.3828125,"Marker5"}, 
 {345.10681152344, 167.09187316895, 1007.3828125,"Marker6"}, 
 {349.04412841797, 167.09187316895, 1007.3828125,"Marker7"} 
}  
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, val in ipairs(markers) do 
        local marker = createMarker(val[1], val[2], val[3]-1, "cylinder", 1.5, 255, 255, 0, 150) 
        setElementInterior(marker, 3) 
        setElementDimension(marker, 200) 
        addEventHandler("onMarkerHit",marker,onMarkerHit) 
    end 
end)  
  
function onMarkerHit(hitPlayer, dim) 
     if not dim then return end  
     if   getElementType ( hitPlayer ) == 'player'  then 
     for index, val in ipairs(markers) do 
     outputChatBox("You are in the".. tostring(val[4]) .." !",hitPlayer,255,0,0) 
      end 
   end 
end 

Link to post

I don't think this way is possible because, I tested that it shows all the markers name on the table not one of them in this case you don't have to use loop, just create markers and for each marker set dimension..etc to be able to control them aswell.

Link to post

I think it doesnt work because the markers got created when you click on a gui and it trigger to server see the code

function serverStartBank(p,character) 
    model = getElementModel(p) 
    setTimer( 
    function() 
        fadeCamera ( p, false, 1.0, 0, 0, 0 )  
        setTimer ( fadeCameraDelayed, 1000, 1, p ) 
        setTimer( 
        function() 
            setElementPosition(p, 388.89999389648, 173.5, 1008.4000244141) 
            setElementModel ( p, character ) 
            setElementDimension(p, 200) 
            setElementInterior(p, 3) 
            doorBank = createObject(2951, 371.70001220703, 166.5, 1007.4000244141) 
            setElementInterior(doorBank, 3) 
            setElementDimension(doorBank, 200) 
            bankCol = createColCuboid(344.32071, 157.6675, 1013.6558, 6, 8.75, 2) 
            setElementInterior(bankCol, 3) 
            setElementDimension(bankCol, 200) 
            --Marker of safe 
    local markers = { 
            {345.52288818359, 165.7333984375, 1014.1875,"bankCash1"}, 
            {347.29931640625, 165.44149780273, 1014.1875,"bankCash2"}, 
            {349.47421264648, 165.72450256348, 1014.1875,"bankCash3"}, 
            {349.45764160156, 162.66996765137, 1014.1875,"bankCash4"}, 
            {348.2170715332, 160.21328735352, 1014.1875,"bankCash5"}, 
            {345.10858154297, 162.65562438965, 1014.1875,"bankCash6"}, 
            {349.04412841797, 167.09187316895, 1014.1875,"bankCash7"} 
                            } 
  
        for index, val in ipairs(markers) do 
            local marker = createMarker(val[1], val[2], val[3]-1, "cylinder", 1.5, 255, 255, 0, 150) 
            setElementInterior(marker, 3) 
            setElementDimension(marker, 200) 
            addEventHandler("onMarkerHit",marker,onMarkerHit) 
        end 
  
        end, 1000, 1) 
    end 
    ,6000,1) 
end 
addEvent( "serverStartBank", true ) 
addEventHandler("serverStartBank", root , serverStartBank) 
function onMarkerHit(hitPlayer, dim) 
     if not dim then return end 
     if   getElementType ( hitPlayer ) == 'player'  then 
     for index, val in ipairs(markers) do 
     outputChatBox("You are in the".. tostring(val[4]) .." !",hitPlayer,255,0,0) 
      end 
   end 
end 
  

Link to post

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