Sign in to follow this  
Scyrix

[Help] Only 1 marker show gui

Recommended Posts

Hello,

So i just started my journey with Lua and wanted to create an simple "info pickup". Basically you hit the pickup ((invisible marker)) and you see the info gui and i wanted to make few of these pickups around the map so i used a table to store the coordinates there but i found out that only 1 marker show the gui and other doesn't. I would like all the markers to show the same gui.

Spoiler
local ok = false
local markery = {  
    { -2413.51171875-602.2509765625 , 132.5625-1 }, 
    { -2412.392578125-590.11328125 , 132.6484375-1 } 
 
for k,v in ipairs( markery ) do 
    marki = createMarker ( v[1],v[2],v[3], "cylinder"2255255255255 ) 
    createPickup( v[1],v[2],v[3],3,1239,2000)
end 
 
addEventHandler("onClientMarkerHit",marki,function(player)
    if (player == localPlayerthen
        if (not ok) then
            ok = true
            addEventHandler("onClientRender",root,gui)
 
        end
    end
end)
 
addEventHandler("onClientMarkerLeave",marki,function( player )
    if (player == localPlayerthen
        if ( ok ) then
            ok = false
        end
    end 
end)
local screenW, screenH = guiGetScreenSize()
function gui()
    if (not ok) then
    removeEventHandler("onClientRender",root,gui)
        return false
    end
    dxDrawLine((screenW * 0.2526- 1, (screenH * 0.3190- 1, (screenW * 0.2526- 1, screenH * 0.4922tocolor(000255), 1false)
    dxDrawLine(screenW * 0.7101, (screenH * 0.3190- 1, (screenW * 0.2526- 1, (screenH * 0.3190- 1tocolor(000255), 1false)
    dxDrawLine((screenW * 0.2526- 1, screenH * 0.4922, screenW * 0.7101, screenH * 0.4922tocolor(000255), 1false)
    dxDrawLine(screenW * 0.7101, screenH * 0.4922, screenW * 0.7101, (screenH * 0.3190- 1tocolor(000255), 1false)
    dxDrawRectangle(screenW * 0.2526, screenH * 0.3190, screenW * 0.4575, screenH * 0.1732tocolor(212025262), false)
    dxDrawText("Informacja", screenW * 0.3338, screenH * 0.3854, screenW * 0.6120, screenH * 0.4583tocolor(255255255255), 1.00"bankgothic""center""top"falsefalsefalsefalsefalse)
end

 

Share this post


Link to post
local ok = false
local screenW, screenH = guiGetScreenSize()
local markery = {  
    { -2413.51171875, -602.2509765625 , 132.5625-1,true}, 
    { -2412.392578125, -590.11328125 , 132.6484375-1,true} 
} 
local marki = nil
 
for k,v in ipairs( markery ) do 
    marki = createMarker ( v[1],v[2],v[3], "cylinder", 2, 255, 255, 255, 255 ) 
    createPickup( v[1],v[2],v[3],3,1239,2000)
    setElementData(marki, "markery:gui", v[4])
end 
 


---=-=-=-=-=-=-=-=-=-=-=-=
-- enter marker 
function MarkerEnter(theElement, matchingDimension)
     if ( theElement == localPlayer ) and ok == false and getElementData(source, "markery:gui") == true then
     	setElementData(localPlayer, "markerygui:player", true)
        ok = true
        addEventHandler("onClientRender",root,gui)
    end
end
addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerEnter )


---=-=-=-=-=-=-=-=-=-=-=-=
-- leave marker 
function MarkerLeave(theElement, matchingDimension)
     if ( theElement == localPlayer ) and ok == true and getElementData(source, "markerygui:player") == true then
     	setElementData(localPlayer, "markerygui:player", false)
        ok = false
        removeEventHandler("onClientRender",root,gui)
    end
end
addEventHandler ( "onClientMarkerLeave", getRootElement(), MarkerLeave )



function gui()
    dxDrawLine((screenW * 0.2526) - 1, (screenH * 0.3190) - 1, (screenW * 0.2526) - 1, screenH * 0.4922, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.7101, (screenH * 0.3190) - 1, (screenW * 0.2526) - 1, (screenH * 0.3190) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine((screenW * 0.2526) - 1, screenH * 0.4922, screenW * 0.7101, screenH * 0.4922, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.7101, screenH * 0.4922, screenW * 0.7101, (screenH * 0.3190) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawRectangle(screenW * 0.2526, screenH * 0.3190, screenW * 0.4575, screenH * 0.1732, tocolor(2, 120, 252, 62), false)
    dxDrawText("Informacja", screenW * 0.3338, screenH * 0.3854, screenW * 0.6120, screenH * 0.4583, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "center", "top", false, false, false, false, false)
end

try this

Edited by Felix5k
  • Like 1

Share this post


Link to post
Just now, Scyrix said:

yeah it works but it does not remove the gui after i leave the marker 

 

local ok = false
local screenW, screenH = guiGetScreenSize()
local markery = {  
    { -2413.51171875, -602.2509765625 , 132.5625-1,true}, 
    { -2412.392578125, -590.11328125 , 132.6484375-1,true} 
} 
local marki = nil
 
for k,v in ipairs( markery ) do 
    marki = createMarker ( v[1],v[2],v[3], "cylinder", 2, 255, 255, 255, 255 ) 
    createPickup( v[1],v[2],v[3],3,1239,2000)
    setElementData(marki, "markery:gui", v[4])
end 
 


---=-=-=-=-=-=-=-=-=-=-=-=
-- enter marker 
function MarkerEnter(theElement, matchingDimension)
     if ( theElement == localPlayer ) and ok == false and getElementData(source, "markery:gui") == true then
     	setElementData(localPlayer, "markerygui:player", true)
        ok = true
        addEventHandler("onClientRender",root,gui)
    end
end
addEventHandler ( "onClientMarkerHit", getRootElement(), MarkerEnter )


---=-=-=-=-=-=-=-=-=-=-=-=
-- leave marker 
function MarkerLeave(theElement, matchingDimension)
     if ( theElement == localPlayer ) and ok == true and getElementData(localPlayer, "markerygui:player") == true then
     	setElementData(localPlayer, "markerygui:player", false)
        ok = false
        removeEventHandler("onClientRender",root,gui)
    end
end
addEventHandler ( "onClientMarkerLeave", getRootElement(), MarkerLeave )



function gui()
    dxDrawLine((screenW * 0.2526) - 1, (screenH * 0.3190) - 1, (screenW * 0.2526) - 1, screenH * 0.4922, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.7101, (screenH * 0.3190) - 1, (screenW * 0.2526) - 1, (screenH * 0.3190) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine((screenW * 0.2526) - 1, screenH * 0.4922, screenW * 0.7101, screenH * 0.4922, tocolor(0, 0, 0, 255), 1, false)
    dxDrawLine(screenW * 0.7101, screenH * 0.4922, screenW * 0.7101, (screenH * 0.3190) - 1, tocolor(0, 0, 0, 255), 1, false)
    dxDrawRectangle(screenW * 0.2526, screenH * 0.3190, screenW * 0.4575, screenH * 0.1732, tocolor(2, 120, 252, 62), false)
    dxDrawText("Informacja", screenW * 0.3338, screenH * 0.3854, screenW * 0.6120, screenH * 0.4583, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "center", "top", false, false, false, false, false)
end

now should work

Edited by Felix5k
  • Like 1

Share this post


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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.