Jump to content

keypress to open a gui window ??? help requested !


Recommended Posts

For anyone out there, i have tried using the mta wiki scripting tutorials but i am lost. let me start from the top...

I made a very simple gui using the resource "guieditor". It's really neat and easy to use but when it saves it's code you have to do some manual work to get it up and running. This is regarding the status page im trying to make.

*I made a folder named "status"

*inside is a file i made called meta.xml which contains the following:

------------------------------------------------------------------------------------

*i made a file called statusgui.lua which i put the code that guieditor output into a text file:

GUIEditor_Window = {}

GUIEditor_TabPanel = {}

GUIEditor_Tab = {}

GUIEditor_Button = {}

GUIEditor_Label = {}

GUIEditor_Window[1] = guiCreateWindow(324,162,673,753,"MainTitleName",false)

GUIEditor_TabPanel[1] = guiCreateTabPanel(9,21,652,722,false,GUIEditor_Window[1])

GUIEditor_Tab[1] = guiCreateTab("Tab1",GUIEditor_TabPanel[1])

GUIEditor_Button[1] = guiCreateButton(443,631,198,45,"Button1",false,GUIEditor_Tab[1])

GUIEditor_Label[1] = guiCreateLabel(11,10,628,59,"-]alw[-Deftones",false,GUIEditor_Tab[1])

guiLabelSetColor(GUIEditor_Label[1],255,255,255)

guiLabelSetVerticalAlign(GUIEditor_Label[1],"top")

guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false)

guiSetFont(GUIEditor_Label[1],"sa-header")

GUIEditor_Tab[2] = guiCreateTab("Tab2",GUIEditor_TabPanel[1])

GUIEditor_Tab[3] = guiCreateTab("Tab3",GUIEditor_TabPanel[1])

------------------------------------------------------------------------------------

SOOO... how do i program this gui window to open upon a keypress like F6? I've tried using the files on our server as refference but i couldnt figure it out.

so far all i know is i need a "addcommandhandler". So i added this and altered it based on a wiki gui tutorial:

function OpenStatusWindow()

guiSetVisible(OpenStatusWindow,true)

showCursor(true,true)

end

addCommandHandler("status",OpenStatusWindow)

---------------------------------------------------------------------------------

I'm guessing that the only thing im doing wrong is not declaring what "OpenStatusWindow" should mean to the system but this is where i get lost. i know the above code is meant to allow you to use /status to open the window but i dont know why its not working.

If anyone knows, any help would be appreciated.

Link to comment

put your lua code into tags!

[ lua] [ /lua]

-- isn't this
guiSetVisible(OpenStatusWindow,true)
-- should be:
guiSetVisible(GUIEditor_Window[1], true)

your gui element isn't called OpenStatusWindow -- this is your function name..

next time post whole code, not random parts.. and put them into lua tags

Link to comment

okay sorry about that. i've made the adjustment you suggested. Stilll nada.

here is my complete lua code:

--This is the code for the status gui
--The following code programs /status to open the gui window
 
function OpenStatusWindow()
 
guiSetVisible(GUIEditor_Window[1],true)
 
showCursor(true,true)
end
 
addCommandHandler("status",OpenStatusWindow)
 
 
--This is the output code provided by the guieditor resource by R3mp
GUIEditor_Window = {}
GUIEditor_TabPanel = {}
GUIEditor_Tab = {}
GUIEditor_Button = {}
GUIEditor_Label = {}
 
GUIEditor_Window[1] = guiCreateWindow(324,162,673,753,"MainTitleName",false)
GUIEditor_TabPanel[1] = guiCreateTabPanel(9,21,652,722,false,GUIEditor_Window[1])
GUIEditor_Tab[1] = guiCreateTab("Tab1",GUIEditor_TabPanel[1])
GUIEditor_Button[1] = guiCreateButton(443,631,198,45,"Button1",false,GUIEditor_Tab[1])
GUIEditor_Label[1] = guiCreateLabel(11,10,628,59,"-]alw[-Deftones",false,GUIEditor_Tab[1])
guiLabelSetColor(GUIEditor_Label[1],255,255,255)
guiLabelSetVerticalAlign(GUIEditor_Label[1],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false)
guiSetFont(GUIEditor_Label[1],"sa-header")
GUIEditor_Tab[2] = guiCreateTab("Tab2",GUIEditor_TabPanel[1])
GUIEditor_Tab[3] = guiCreateTab("Tab3",GUIEditor_TabPanel[1])

and just in case, here is my meta.xml:

<meta>
<info author="-]alw[-Deftones" type="gamemode" name="Status" description="A status page used to display stats for the rpg racing server"/>
<script src="statusgui.lua" type="client"/>
 
meta>

So the goal is to get the window to open with /status. I know in the future i would need to bind a key to onClientResourceStart and unbind onClientResourceStop if i want to use F6. (thanks woovie), but thats only when i can get /status to work.

Link to comment

As you arent explicitly hiding it, the gui should be visible as soon as you join the server. I just tried the code myself and its working fine

Make sure you are restarting the resource between changes, and check for debugscript errors (log in as admin, type '/debugscript 3')

I think its also good practice to put gui into onClientResourceStart handles, rather than leaving it like it is now:

function createGUI()
   GUIEditor_Window = {}
   GUIEditor_TabPanel = {}
   GUIEditor_Tab = {}
   GUIEditor_Button = {}
   GUIEditor_Label = {}
 
   GUIEditor_Window[1] = guiCreateWindow(324,162,673,753,"MainTitleName",false)
   GUIEditor_TabPanel[1] = guiCreateTabPanel(9,21,652,722,false,GUIEditor_Window[1])
   GUIEditor_Tab[1] = guiCreateTab("Tab1",GUIEditor_TabPanel[1])
   GUIEditor_Button[1] = guiCreateButton(443,631,198,45,"Button1",false,GUIEditor_Tab[1])
   GUIEditor_Label[1] = guiCreateLabel(11,10,628,59,"-]alw[-Deftones",false,GUIEditor_Tab[1])
guiLabelSetColor(GUIEditor_Label[1],255,255,255)
guiLabelSetVerticalAlign(GUIEditor_Label[1],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false)
guiSetFont(GUIEditor_Label[1],"sa-header")
   GUIEditor_Tab[2] = guiCreateTab("Tab2",GUIEditor_TabPanel[1])
   GUIEditor_Tab[3] = guiCreateTab("Tab3",GUIEditor_TabPanel[1])
end
addEventHandler("onClientResourceStart",resourceRoot,createGUI)

Link to comment

UPDATE:

I removed the type="gamemode" from the meta.

<meta>
<info author="-]alw[-Deftones" name="Status" description="A status page used to display stats"/>
<script src="statusgui.lua" type="client"/>
 
meta>

... and now the window shows up, now. yippie!!!

But, it opens by default when i join the server, which is not quite right yet.

I feel like im getting closer.

Link to comment

UPDATE: /Status now opens the window!!!!!

Here is the code so far:

--This is the code for the status gui
--The following code programs /status to open the gui window
 
function OpenStatusWindow()
guiSetVisible(GUIEditor_Window[1],true)
showCursor(true,true)
end
 
addCommandHandler("status",OpenStatusWindow)
 
--This is the output code provided by the guieditor resource by R3mp
--It is kept within a function to output as a onClientResourceStart arguement
function createGUI()
GUIEditor_Window = {}
GUIEditor_TabPanel = {}
GUIEditor_Tab = {}
GUIEditor_Button = {}
GUIEditor_Label = {}
 
GUIEditor_Window[1] = guiCreateWindow(324,162,673,753,"MainTitleName",false)
GUIEditor_TabPanel[1] = guiCreateTabPanel(9,21,652,722,false,GUIEditor_Window[1])
GUIEditor_Tab[1] = guiCreateTab("Tab1",GUIEditor_TabPanel[1])
GUIEditor_Button[1] = guiCreateButton(443,631,198,45,"Button1",false,GUIEditor_Tab[1])
GUIEditor_Label[1] = guiCreateLabel(11,10,628,59,"-]alw[-Deftones",false,GUIEditor_Tab[1])
guiLabelSetColor(GUIEditor_Label[1],255,255,255)
guiLabelSetVerticalAlign(GUIEditor_Label[1],"top")
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false)
guiSetFont(GUIEditor_Label[1],"sa-header")
GUIEditor_Tab[2] = guiCreateTab("Tab2",GUIEditor_TabPanel[1])
GUIEditor_Tab[3] = guiCreateTab("Tab3",GUIEditor_TabPanel[1])
 
--Hide the window by default at start until called
guiSetVisible(GUIEditor_Window[1],false)
end
 
addEventHandler("onClientResourceStart",resourceRoot,createGUI)

so now /status opens, no debug errors. but now id like to be able to close the window with a command. would i be able to assign it to close using the same command? im supposed i would need to mix in some if/then statements.

or...

addEventHandler("onClientResourceStop" ------------but i dunno what to add to this lol

Link to comment
this will use the command to toggle the window open/closed
function OpenStatusWindow()
guiSetVisible(not guiGetVisible(GUIEditor_Window[1]),true)
showCursor(true,true)
end

for an explanation on 'not', see here

- You don't want to hide GUI and show cursor (you want to hide it when you hide window).

- Also, you need GUI element as first argument in guiSetVisible.

- You also, don't need 2nd argument in showCursor since by default it's true.

So many "errors" in such short code.

function OpenStatusWindow()
guiSetVisible( GUIEditor_Window[1], not guiGetVisible( GUIEditor_Window[1] ) )
showCursor( guiGetVisible( GUIEditor_Window[1] ) )
end

Link to comment
this will use the command to toggle the window open/closed
function OpenStatusWindow()
guiSetVisible(not guiGetVisible(GUIEditor_Window[1]),true)
showCursor(true,true)
end

for an explanation on 'not', see here

- You don't want to hide GUI and show cursor (you want to hide it when you hide window).

- Also, you need GUI element as first argument in guiSetVisible.

- You also, don't need 2nd argument in showCursor since by default it's true.

So many "errors" in such short code.

function OpenStatusWindow()
guiSetVisible( GUIEditor_Window[1], not guiGetVisible( GUIEditor_Window[1] ) )
showCursor( guiGetVisible( GUIEditor_Window[1] ) )
end

YES ! It worked great!

Thank you guys very much for this. It's very difficult to learn this stuff but i think i get the idea. I need to learn quite abit more about how to correctly code these functions and everything. This may turn out to be a pretty fun hobby.

I cant wait to finish this resource and show you guys!

Link to comment

I got the keybinds working too!

--It is kept within a function to output as a onClientResourceStart arguement
function createGUI()
 
bindKey("F6","down",OpenStatusWindow)
 
--This is the output code provided by the guieditor resource by R3mp
GUIEditor_Window = {}
GUIEditor_TabPanel = {}
GUIEditor_Tab = {}
GUIEditor_Button = {}

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