Jump to content

GUI help


Recommended Posts

hey guys, i need a little help here, im trying to make a good car colors script for anyone to use. i got the functionality down, i just need to make a color chart for noobs to see so they know what car color they want. here is an example of my script.

function colorChart ( theResource ) 
  
       if theResource ~= getThisResource() then return end 
  
       colorMenu = guiCreateWindow ( 0.15, 0.33, 0.7, 0.34, "The Color IDs", true ) 
  
       colorMenuCloseButton = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Close", true, colorMenu ) 
  
       guiWindowSetMovable ( colorMenu, false ) 
  
       guiWindowSetSizable ( colorMenu, false ) 
  
       guiCreateStaticImage ( 0.15, 0.33, 0.6, 0.33, colorchart.png, true, colorMenu ) 
  
  
  
       end 
  
  
end 
  
function windowClose ( ) 
  
      if ( colorMenu ) then 
          
           destroyElement ( colorMenu ) 
      
      end 
  
end 
  
addCommandHandler ( "colorids", colorChart ) 
addEventhandler ( "onClientGUIClick", colorMenuCloseButton, windowClose ) 

thats the client side script (not putting serverside, it works)

<meta> 
     <info author="masterOfPuppets" version="1.0" /> 
     <script src="color.lua" type="server" /> 
     <script src="colorgrid.lua" type="client" /> 
     <file src="img/colorchart.png" /> 
</meta> 

thats the xml. can anyone help me get the ID chart to work?

Link to comment
I would try to remove the (theResource) argument, the if check if theResource is ~= getThisResource and the end before end of the function.

Yes, theResource arg will be always "player" it will not be resource because that's how addCommandHandler works. So the function will always stop (return) after the check. Also, why do you destroy the window when you click the button? Hide it instead (guiSetVisible).

Link to comment

ok, with commands i was able to close the window, but i need to make it so the button does it. It wont do it though. could someone help me out here? the button does nothing.

function colorChart (  ) 
  
       showCursor ( true )       
          
       colormenu = guiCreateWindow ( 0.15, 0.53, 0.7, 0.34, "The Color IDs", true ) 
  
       closemenu = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Close", true, colormenu ) 
  
       guiWindowSetMovable ( colormenu, true ) 
  
       guiWindowSetSizable ( colormenu, true ) 
  
       guiCreateStaticImage ( 0.15, 0.33, 0.6, 0.33, "img/colorchart.png", true, colormenu ) 
  
        
  
        
  
  
end 
  
function windowClose ( ) 
  
      
          
           destroyElement ( colormenu ) 
      
           showCursor ( false ) 
  
end 
  
addCommandHandler ( "colorids", colorChart ) 
addEventHandler ( "onClientGUIClick", closemenu, windowClose ) 

Edited by Guest
Link to comment

Try this one:

function colorChart (  ) 
  
       showCursor ( true )       
          
       colormenu = guiCreateWindow ( 0.15, 0.53, 0.7, 0.34, "The Color IDs", true ) 
  
       closemenu = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Close", true, colormenu ) 
  
       addEventHandler ( "onClientGUIClick", closemenu, windowClose ) 
  
       guiWindowSetMovable ( colormenu, true ) 
  
       guiWindowSetSizable ( colormenu, true ) 
  
       guiCreateStaticImage ( 0.15, 0.33, 0.6, 0.33, "img/colorchart.png", true, colormenu ) 
  
end 
  
  
function windowClose ( ) 
       if source == closemenu then         
             destroyElement ( colormenu ) 
             removeEventHandler( "onClientGUIClick", closemenu, windowClose ) 
             showCursor ( false ) 
       end 
end 
  

Link to comment
Try this one:
function colorChart (  ) 
  
       showCursor ( true )       
          
       colormenu = guiCreateWindow ( 0.15, 0.53, 0.7, 0.34, "The Color IDs", true ) 
  
       closemenu = guiCreateButton ( 0.4, 0.85, 0.20, 0.15, "Close", true, colormenu ) 
  
       addEventHandler ( "onClientGUIClick", closemenu, windowClose ) 
  
       guiWindowSetMovable ( colormenu, true ) 
  
       guiWindowSetSizable ( colormenu, true ) 
  
       guiCreateStaticImage ( 0.15, 0.33, 0.6, 0.33, "img/colorchart.png", true, colormenu ) 
  
end 
  
  
function windowClose ( ) 
       if source == closemenu then         
             destroyElement ( colormenu ) 
             removeEventHandler( "onClientGUIClick", closemenu, windowClose ) 
             showCursor ( false ) 
       end 
end 
  

Instead of having to do the 'if source==closemenu' line, you can just set the last boolean of addEventHandler to false (i.e. getPropagated).

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