Jump to content

button problem


Bluntz-X

Recommended Posts

hi all i am new in lua i have problem my button not working how i can open it Like this is button

  GUIEditor.button[1] = guiCreateButton(9, 81, 73, 37, "Rules", false, GUIEditor.window[1])    

when player press button it show this

  GUIEditor.memo[1] = guiCreateMemo(186, 149, 389, 338, "\nbbabaabaaba", false)  

i am using this

onClientGUIClick 

hope you can help me

Link to comment
function initGUI( ) 
    -- Create our button 
     button = guiCreateButton(311, 254, 162, 19, "Rules", false)     
  
    addEventHandler ( "onClientGUIClick", button, outputEditBox, false ) 
  
     GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "", false) 
      
     guiWindowSetSizable(GUIEditor.window[1], false) 
  
       
     GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) 
      
     guiMemoSetReadOnly(GUIEditor.memo[1], true) 
end 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) 

Link to comment
  
function initGUI( ) 
    -- Create our button 
     button = guiCreateButton(311, 254, 162, 19, "Rules", false)     
  
    
  
     GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "", false) 
      
     guiWindowSetSizable(GUIEditor.window[1], false) 
  
      
     GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) 
      
     guiMemoSetReadOnly(GUIEditor.memo[1], true) 
end 
addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource( ) ), initGUI ) 
  
function onClick() 
guiSetVisible(GUIEditor.memo[1],true) 
end 
 addEventHandler ( "onClientGUIClick", button, onClick ) 
  

Link to comment

Try this.

GUIEditor = { 
    window = {}, 
    memo = {}, 
    button = {} 
} 
  
 addEventHandler( "onClientResourceStart", resourceRoot, 
function () 
    -- Create our button          
     GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "Rules", false) 
     GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "Rules", false, GUIEditor.window[1])      
     guiWindowSetSizable(GUIEditor.window[1], true) 
     GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) 
     guiSetVisible(GUIEditor.memo[1],false) 
     guiMemoSetReadOnly(GUIEditor.memo[1], true) 
      showCursor (true) 
       
       
 function hmm () 
 if guiGetVisible (GUIEditor.memo[1]) == true then 
guiSetVisible (GUIEditor.memo[1],false) 
else 
guiSetVisible(GUIEditor.memo[1],true) 
end 
end 
end) 
addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false )  

not tested but as i see it should work.

Link to comment
  • Moderators
Try this.
GUIEditor = { 
    window = {}, 
    memo = {}, 
    button = {} 
} 
  
 addEventHandler( "onClientResourceStart", resourceRoot, 
function () 
    -- Create our button          
     GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "Rules", false) 
     GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "Rules", false, GUIEditor.window[1])      
     guiWindowSetSizable(GUIEditor.window[1], true) 
     GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) 
     guiSetVisible(GUIEditor.memo[1],false) 
     guiMemoSetReadOnly(GUIEditor.memo[1], true) 
      showCursor (true) 
       
       
 function hmm () 
 if guiGetVisible (GUIEditor.memo[1]) == true then 
guiSetVisible (GUIEditor.memo[1],false) 
else 
guiSetVisible(GUIEditor.memo[1],true) 
end 
end 
end) 
addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false )  

not tested but as i see it should work.

No it doesn't. The variable hmm isn't defined when the addEventHandler ( "onClientGUIClick") is attached. Also the button hasn't been created yet.

Because onClientResourceStart get triggered after the code has been loaded.

    GUIEditor = { 
        window = {}, 
        memo = {}, 
        button = {} 
    } 
      
     addEventHandler( "onClientResourceStart", resourceRoot, 
    function () 
        -- Create our button         
         GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "Rules", false) 
         GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "Rules", false, GUIEditor.window[1])     
         guiWindowSetSizable(GUIEditor.window[1], true) 
         GUIEditor.memo[1] = guiCreateMemo(9, 22, 521, 327, "/n button not working", false, GUIEditor.window[1]) 
         guiSetVisible(GUIEditor.memo[1],false) 
         guiMemoSetReadOnly(GUIEditor.memo[1], true) 
          showCursor (true) 
          
          
     function hmm () --<< 1 
     if guiGetVisible (GUIEditor.memo[1]) == true then 
    guiSetVisible (GUIEditor.memo[1],false) 
    else 
    guiSetVisible(GUIEditor.memo[1],true) 
    end 
    end 
 addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false ) --<< 2 
    end) -- end function (onClientResourceStart) 
  
  
    --addEventHandler ( "onClientGUIClick", GUIEditor.button[1], hmm, false )  

Link to comment
  • 4 weeks later...

hi i am come back again with more help i make lock button but lock system is server side how i can lock car

function () 
        -- Create our button         
         GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "lock", false) 
         GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "lock", false, GUIEditor.window[1])     

function lockcar ( thePlayer ) 
    playervehicle = getPlayerOccupiedVehicle ( thePlayer )   -- define 'playervehicle' as the vehicle the player is in 
    if ( playervehicle ) then                                -- if a player is in a vehicle 
        if isVehicleLocked ( playervehicle ) then            -- and if the vehicle is already locked 
            setVehicleLocked ( playervehicle, false )        -- unlock it 
        else                                                 -- otherwise (if it isn't locked)  
            setVehicleLocked ( playervehicle, true )         -- lock it 
        end 
    end 
end 
  
function bindLockOnSpawn ( theSpawnpoint )                     -- when a player spawns 
    bindKey ( source, "l", "down", "Lock car", lockcar )     -- bind the 'l' key to the 'lockcar' function 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn )     -- add an e 

thanks for help

Link to comment
addEventHandler ( "onClientGUIClick", GUIEditor.button[1], 
    function () 
        if ( source == GUIEditor.button[1] ) then 
            triggerServerEvent ( "lockCar", localPlayer, localPlayer ) 
        end 
    end 
) 

That was clientside, now serverside:

function lockcar ( thePlayer ) 
    playervehicle = getPlayerOccupiedVehicle ( thePlayer )   -- define 'playervehicle' as the vehicle the player is in 
    if ( playervehicle ) then                                -- if a player is in a vehicle 
        if isVehicleLocked ( playervehicle ) then            -- and if the vehicle is already locked 
            setVehicleLocked ( playervehicle, false )        -- unlock it 
        else                                                 -- otherwise (if it isn't locked) 
            setVehicleLocked ( playervehicle, true )         -- lock it 
        end 
    end 
end 
addEvent ( "lockCar", true ) 
addEventHandler ( "lockCar", root, lockcar ) 
  
function bindLockOnSpawn ( theSpawnpoint )                     -- when a player spawns 
    bindKey ( source, "l", "down", "Lock car", lockcar )     -- bind the 'l' key to the 'lockcar' function 
end 
addEventHandler ( "onPlayerSpawn", getRootElement(), bindLockOnSpawn ) 

Link to comment
  
GUIEditor.window[1] = guiCreateWindow(166, 127, 540, 359, "lock", false) 
GUIEditor.button[1] = guiCreateButton(311, 254, 162, 19, "lock", false, GUIEditor.window[1]) 
addEventHandler("onClientGUIClick",GUIEditor.button[1],function() 
    triggerServerEvent("onPlayerRequestLock",localPlayer) 
end,false) 
  

  
addEvent("onPlayerRequestLock",true) 
addEventHandler("onPlayerRequestLock",root,function() 
    local vehicle = getPedOccupiedVehicle(client) 
    if vehicle then 
        setVehicleLocked(vehicle,not isVehicleLocked(vehicle)) 
    else 
        outputChatBox("You are not inside a vehicle!",client) 
    end 
end) 
  

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