Jump to content

Need some Help about GUI


Jonty

Recommended Posts

Hello I've been making a GUI first time doing this and I've got the code to work but I've tried using a button to hide the GUI after it is clicked. 

 

Can anyone help me, please? 

 

-- Made by Jonty / First Lua code for Tables. 

Skins = {
      "Cj - 0",
      "",
      ""
}

Vehicle = {
      "",
      ""
}

function setupSkinSelection (theResource)

-- Creats GUI window
spawnScreenMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "Find the ID's you want!", true )

-- Button 
spawnScreenOKButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Done", true, spawnScreenMenu )
      guiWindowSetMovable ( spawnScreenMenu, false )
      guiWindowSetSizable ( spawnScreenMenu, false )
 
 spawnScreenGridList = guiCreateGridList ( 0, 0.1, 1, 0.9, true, spawnScreenMenu )
 guiGridListSetSelectionMode ( spawnScreenGridList, 2 )
 
      guiGridListAddColumn ( spawnScreenGridList, "Skins", 0.3 )
      guiGridListAddColumn ( spawnScreenGridList, "Vehicle", 0.3 )
	  
	        for key,skinName in pairs(Skins) do

            local row = guiGridListAddRow ( spawnScreenGridList )
			
            guiGridListSetItemText ( spawnScreenGridList, row, 1, skinName, false, false )
      end
	  
	  -- Rows for the GUI window
	        row = 0
      for key,skinName in pairs(Vehicle) do
            guiGridListSetItemText ( spawnScreenGridList, row, 2, skinName, false, false )
            row = row + 1
      end
end

-- Command to launch the GUI
addCommandHandler('IDSelection',
	function()
		setupSkinSelection(true)
		showCursor ( true ) 
	end
)

addEventHandler('onClientGUIClick' , spawnScreenOKButton, 
function ( ) 
if ( source == 'Done'  ) then 
guiSetVisible (spawnScreenMenu , false)
showCursor ( false ) 
end 

 

 

 

Link to comment
-- Made by Jonty / First Lua code for Tables.
local sx,sy = guiGetScreenSize()
local sw,sh = 1360,780-- if u change the values in the relative() funcs, be sure to set this to your res and change the other ones as well.

function relative(x,y,w,h) -- this allows for perfect relative values, mta only sizes them to your res so it would be funky for other resolutions.
    x = x/sx*sw
    y = y/sy*sh
    w = w/sx*sw
    h = h/sy*sh
    return x,y,w,h
end

data = {
      {'CJ','Infernus',0,411}
}

local x1,y1,w1,h1 = relative(204,253,952,261)
spawnScreenMenu = guiCreateWindow(x1,y1,w1,h1,'Find the IDs you want!',false)
guiWindowSetMovable(spawnScreenMenu,false)
guiWindowSetSizable(spawnScreenMenu,false)

local x2,y2,w2,h2 = relative(9,26,933,195)
spawnScreenGridList = guiCreateGridList(x2,y2,w2,h2,false,spawnScreenMenu)
guiGridListAddColumn(spawnScreenGridList,'Skins',0.5)
guiGridListAddColumn(spawnScreenGridList,'Vehicle',0.48)

local x3,y3,w3,h3 = relative(381,222,190,30)
spawnScreenOKButton = guiCreateButton(x3,y3,w3,h3,'Done',false,spawnScreenMenu)
guiSetVisible(spawnScreenMenu,false)

for i=1,#data do
    local row = guiGridListAddRow(spawnScreenGridList)
    guiGridListSetItemText(spawnScreenGridList,row,1,data[i][1],false,false)
    guiGridListSetItemText(spawnScreenGridList,row,2,data[i][2],false,false)
end

-- Command to launch the GUI
addCommandHandler('idselection',function()
    if guiGetVisible(spawnScreenMenu) then
        guiSetVisible(spawnScreenMenu,false)
        showCursor(false)
    else
        guiSetVisible(spawnScreenMenu,true)
        showCursor(true)
    end
end)

addEventHandler('onClientGUIClick',spawnScreenOKButton,function()
    guiSetVisible(spawnScreenMenu,false)
    showCursor(false)
end)

I've added a relative function, you'll have to change the resolution as well as the numbers in the relative() functions to match your resolution, after that they should be working just fine, inputting absolute values and getting relative values, I just tested this code and it is working perfectly.

I did this whole relative thing because MTA relative values are only based off of your resolution, I made it so its based off of all resolutions, that way you wont have any problems with resizing or moving the GUI on another persons screen. It'll look the same on your screen as a phone screen haha.

Have a nice day.

Link to comment
29 minutes ago, ShayF said:

-- Made by Jonty / First Lua code for Tables.
local sx,sy = guiGetScreenSize()
local sw,sh = 1360,780-- if u change the values in the relative() funcs, be sure to set this to your res and change the other ones as well.

function relative(x,y,w,h) -- this allows for perfect relative values, mta only sizes them to your res so it would be funky for other resolutions.
    x = x/sx*sw
    y = y/sy*sh
    w = w/sx*sw
    h = h/sy*sh
    return x,y,w,h
end

data = {
      {'CJ','Infernus',0,411}
}

local x1,y1,w1,h1 = relative(204,253,952,261)
spawnScreenMenu = guiCreateWindow(x1,y1,w1,h1,'Find the IDs you want!',false)
guiWindowSetMovable(spawnScreenMenu,false)
guiWindowSetSizable(spawnScreenMenu,false)

local x2,y2,w2,h2 = relative(9,26,933,195)
spawnScreenGridList = guiCreateGridList(x2,y2,w2,h2,false,spawnScreenMenu)
guiGridListAddColumn(spawnScreenGridList,'Skins',0.5)
guiGridListAddColumn(spawnScreenGridList,'Vehicle',0.48)

local x3,y3,w3,h3 = relative(381,222,190,30)
spawnScreenOKButton = guiCreateButton(x3,y3,w3,h3,'Done',false,spawnScreenMenu)
guiSetVisible(spawnScreenMenu,false)

for i=1,#data do
    local row = guiGridListAddRow(spawnScreenGridList)
    guiGridListSetItemText(spawnScreenGridList,row,1,data[i][1],false,false)
    guiGridListSetItemText(spawnScreenGridList,row,2,data[i][2],false,false)
end

-- Command to launch the GUI
addCommandHandler('idselection',function()
    if guiGetVisible(spawnScreenMenu) then
        guiSetVisible(spawnScreenMenu,false)
        showCursor(false)
    else
        guiSetVisible(spawnScreenMenu,true)
        showCursor(true)
    end
end)

addEventHandler('onClientGUIClick',spawnScreenOKButton,function()
    guiSetVisible(spawnScreenMenu,false)
    showCursor(false)
end)

I've added a relative function, you'll have to change the resolution as well as the numbers in the relative() functions to match your resolution, after that they should be working just fine, inputting absolute values and getting relative values, I just tested this code and it is working perfectly.

I did this whole relative thing because MTA relative values are only based off of your resolution, I made it so its based off of all resolutions, that way you wont have any problems with resizing or moving the GUI on another persons screen. It'll look the same on your screen as a phone screen haha.

Have a nice day.

it works very well. Thank you very much for me help

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