Jump to content

Marker table problem


Bean666

Recommended Posts

yes i have markers visible at the same time because it's a loot system

anyways , when i click the "M4" Button in the second marker, it destroys the first marker from the table, no errors,

but when i do it first to the 1st marker from table, i press M4 Button, it destroys the current marker "first marker", no errors, but when the first marker is destroyed, i go to second marker, pressed M4 Button, doesnt destroy the second marker and

this is the error:

Client line 13 Bad Argument @ 'destroyElement' [Expected element at argument 1]

Link to comment

Use This :

local spots = { 
    { 2490.173828125, -1670.1630859375, 12.3 }, 
    { 2492.6298828125, -1675.1650390625, 12.3 } 
} 
  
GUIEditor = { 
    button = {}, 
    window = {} 
} 
        window = guiCreateWindow(0.38, 0.28, 0.26, 0.48, "Loot Point", true) 
        guiWindowSetSizable(window, false) 
  
        guiSetVisible(window, false) 
        button = guiCreateButton(0.25, 0.22, 0.49, 0.20, "M4", true, window) 
        guiSetFont(button, "default-bold-small") 
        cancel = guiCreateButton(0.25, 0.60, 0.49, 0.20, "Cancel", true, window) 
        guiSetFont(cancel, "default-bold-small")     
  
addEventHandler ( "onClientResourceStart",resourceRoot,  
  
    function (  ) 
  
    for k,v in ipairs( spots ) do 
  
    marker = createMarker ( v[1],v[2],v[3], "Cylinder", 1, 255, 255, 255, 100 ) 
  
    addEventHandler ( "onClientMarkerHit", marker, MarkerHit ) 
  
    end 
end  
    ) ; 
  
  
function MarkerHit ( hitPlayer ) 
  
    if ( hitPlayer == localPlayer ) then 
  
    guiSetVisible( window, true ) 
  
    showCursor( true ) 
  
    end 
end 
  
addEventHandler("onClientGUIClick",button,function() 
    if ( source == button ) then 
     
    guiSetVisible( window , false ) 
     
    showCursor( false ) 
  
    if isElement ( marker ) then destroyElement( marker ) end 
     
       end 
   end ) 
Link to comment

Try with resourceRoot and element data like this :

local spots = { 
    { 2490.173828125, -1670.1630859375, 12.3 }, 
    { 2492.6298828125, -1675.1650390625, 12.3 } 
} 
  
GUIEditor = { 
    button = {}, 
    window = {} 
} 
  
        window = guiCreateWindow(0.38, 0.28, 0.26, 0.48, "Loot Point", true) 
        guiWindowSetSizable(window, false) 
  
        guiSetVisible(window, false) 
        button = guiCreateButton(0.25, 0.22, 0.49, 0.20, "M4", true, window) 
        guiSetFont(button, "default-bold-small") 
        cancel = guiCreateButton(0.25, 0.60, 0.49, 0.20, "Cancel", true, window) 
        guiSetFont(cancel, "default-bold-small")     
  
for k,v in ipairs( spots ) do 
        marker = createMarker ( v[1],v[2],v[3], "Cylinder", 1, 255, 255, 255, 100 ) 
end 
  
function MarkerHit ( hitPlayer, matchingDimension ) 
if (hitPlayer == localPlayer) then 
guiSetVisible(window, true) 
showCursor(true) 
    setElementData( localPlayer, 'm', source) 
    end 
end 
addEventHandler ( "onClientMarkerHit", resourceRoot, MarkerHit ) 
  
addEventHandler("onClientGUIClick",button,function() 
    if ( source == button) then 
           guiSetVisible(window,false) 
           showCursor(false) 
           destroyElement(getElementData(localPlayer, 'm') ) 
       end 
   end ) 
Link to comment

i used this and it works for the normal marker, how to make it work on the table?

EDIT: I noticed a problem in this Code. it only recovers in the first time i destroy it , the second time i destroy it it doesnt recover anymore, this needs a table maybe?

local bankmarker = createMarker( 2493.93823, -1665.07031, 13.34375, "cylinder", 1.5, 255, 0, 0, 255 ) 
  
addEventHandler("onClientElementDestroy", getRootElement(), 
function () 
    if getElementType(source) == "marker" and source == bankmarker then 
    setTimer ( function() 
    local bankmarker = createMarker( 2493.93823, -1665.07031, 13.34375, "cylinder", 1.5, 255, 0, 0, 255 ) 
    end,3000,1) 
end 
end 
) 

Link to comment

function MarkerHit ( hitPlayer, matchingDimension ) 
if (hitPlayer == localPlayer) then 
guiSetVisible(window, true) 
showCursor(true) 
    setElementData( localPlayer, 'm', { source_ = source, pos = {getElementPosition (source) } } ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", resourceRoot, MarkerHit ) 
  
addEventHandler("onClientGUIClick",button,function() 
    if ( source == button) then 
           guiSetVisible(window,false) 
           showCursor(false) 
           destroyElement(getElementData(localPlayer, 'm').source_ ) 
       end 
   end ) 
  
addEventHandler("onClientElementDestroy", resourceRoot,function () 
    if getElementType(source) == "marker" and getElementData( localPlayer, 'm' ).source_ == source then 
        local x,y,z = unpack (getElementData( localPlayer, 'm' ).pos) 
            setTimer ( function() 
                local bankmarker = createMarker( x, y, z, "cylinder", 1.5, 255, 0, 0, 255 ) 
            end,3000,1) 
        end 
    end 
) 

Note: resourceRoot for all markers in the script!

Link to comment

anyways i got one more prob, i want this loot system to have multiple weapons, i tried to make another table and GUis of different weapons, but it doesnt work, it just shows me the M4 GUI.

if i make another table of markers ,it shows me just the M4 GUI. this is my very last problem now. each marker i make , it' shows the Same GUI, i think it's because of the resourceroot ,

i think it's easier in serverside?

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