Jump to content

On click icon


Recommended Posts

local imgTable = {
 {"LV - Hospital", 652, 131, 10, 9},
 {"LV - DM Area", 608, 93, 10, 9},
}


 for index, imgTable in ipairs(imgTable) do
  blipImg = guiCreateStaticImage(imgTable[2], imgTable[3], imgTable[4], imgTable[5], "images/1.png", false, mapImg)
  addEventHandler("onClientGUIClick", blipImg, onClickBlip, false)

end

function onClickBlip()
 local x,  y = guiGetPosition(blipImg, false)
 for index, blips in ipairs(imgTable) do
  if x == blips[2] and y == blips[3] then
   if (blipImage2) then
    destroyElement(blipImage2)
   end
   blipImage2 = guiCreateStaticImage(blips[2], blips[3], blips[4], blips[5], "images/2.png", false, mapImg)
  end
 end
end

 

So okay, everything is working but I want it, once I click any icon it will be replaced with another icon on its place, look at my code

Edited by Leo Messi
Link to comment

You'll need to first create a function before the GUI is created.  Now use GuiGetPosition to get the position of the image clicked (in your new function the image will be the source that triggered it), after this you just destroy the image (in new function) like this: destroyElement (source)

Why create a function BEFORE the GUI is made I hear you ask?  Well the way a computer reads code is top to bottom, so if you try pass a function, boolean or variable before it knows that it's there, it will get confused and say it's not there.  Simple!

Now that you have got the position of that image when you clicked it (remember you need "x,y = guiGetPosition (source)"), you can create your new image there.

If you need an example I can try (please try yourself first), but I am very lazy today.  Also please use these for code '<>' it helps us see your code more clearly as it is colored, just like in notepad++.  I hope this helps you! :D 

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