Jump to content

Recommended Posts

Posted

few days ago i created a script in which when i do /getnrg i get nrg and when i do /getfcr i get fcr

then i though of creating a gui

pic of the gui

http://i.imgur.com/tr2aKBy.png

code:

  
GUIEditor = { 
    button = {}, 
    window = {}, 
    label = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") 
  
        GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) 
        GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1])     
    end 
) 

my problem is that how do i link those command to those buttons?

like when i click on get nrg button the server automatically does /getnrg and give me nrg

Posted

You can use the function

executeCommandHandler 

Use onClientGUIClick to link the button to a function.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted (edited)

i got another problem can anyone help ??

my bind key is not working for the gui

here is my code

  
  
  
GUIEditor = { 
    button = {}, 
    window = {}, 
    label = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") 
  
        GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) 
        GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1])     
      
    end 
) 
  
bindKey("F2","down", 
            function () 
                 
                guiSetText(GUIEditor.label[1],tostring(getElementData(localPlayer,"window[1]"))) 
                if visbWndw then 
                    guiSetVisible(GUIEditor.window[1],false) 
                    showCursor(false) 
                else 
                    guiSetVisible(GUIEditor.window[1],true) 
                    showCursor(true) 
                end 
                visbWndw = not visbWndw 
            end) 
    end 
) 

can any find why it's not working ?

Edited by Guest
Posted
addEvent('startdraw',true) 
addEvent('stopdraw',true) 
local screenx,screeny = guiGetScreenSize() 
  
GUIEditor = { 
    button = {}, 
    window = {}, 
    label = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") 
        GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) 
        GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1])      
    end 
) 
  
bindKey ( "F2", "down", 
    function ( ) 
        local state = ( not guiGetVisible ( GUIEditor.window[1] ) ) 
        guiSetVisible ( GUIEditor.window[1], state ) 
        showCursor ( state ) 
    end 
) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

can you fix this i just made for linking the button to the command, sorry if i'm asking too many question , i am not that good lua scripter.

addEventHandler ( "onClientGUIClick", GUIEditor.button[1], getnrggui, false ) 
  
  
  function getnrggui () 
    executeCommandHandler("getnrg",playersource) 
end 

the commands are in server side so not sure if it will work

Posted

You can't execute server-side commands from the client side.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

The addEventHandler has to go inside the function where you create the GUI.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

new code

  
addEvent('startdraw',true) 
addEvent('stopdraw',true) 
local screenx,screeny = guiGetScreenSize() 
  
GUIEditor = { 
    button = {}, 
    window = {}, 
    label = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(222, 217, 378, 192, "get bike", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetProperty(GUIEditor.window[1], "CaptionColour", "FFFA1818") 
        GUIEditor.button[1] = guiCreateButton(57, 88, 109, 57, "GET NRG", false, GUIEditor.window[1]) 
        GUIEditor.button[2] = guiCreateButton(224, 93, 126, 52, "GET FCR", false, GUIEditor.window[1]) 
        GUIEditor.label[1] = guiCreateLabel(87, 4, 206, 15, "", false, GUIEditor.window[1])     
    end 
addEventHandler ( "onClientGUIClick", GUIEditor.button[1], getnrggui, false ) 
end 
) 
  
bindKey ( "F2", "down", 
    function ( ) 
        local state = ( not guiGetVisible ( GUIEditor.window[1] ) ) 
        guiSetVisible ( GUIEditor.window[1], state ) 
        showCursor ( state ) 
    end 
) 
  
function getnrggui () 
    triggerServerEvent ( "getbike", localPlayer ) 
end) 

not working

Posted

You got 1 extra end before addEventHandler, remove it.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Maybe you can, but I'm not sure how good is it.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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