arris Posted July 19, 2009 Share Posted July 19, 2009 So im been working on a player menu for a little while and the problem im having is when the player press m the menu doesn't come up. Does anybody know what code i should use and also this player menu is work in progress. heres the code Window = {} Button = {} function changeState( source ) if getGuiVisible(Window[1]) then getSetVisible(Window[1]),false showCursor(false) else Window[1] = guiCreateWindow(618,138,512,595,"Player Menu",false) Button[1] = guiCreateButton(0.7348,0.3395,0.2551,0.0627,"Fix Vehicle $200",true,Window[1]) Button[2] = guiCreateButton(0.7368,0.4225,0.2551,0.0627,"Full Health $200",true,Window[1]) Button[3] = guiCreateButton(0.7368,0.5074,0.2551,0.0627,"Suicide",true,Window[1]) Button[4] = guiCreateButton(0.6883,0.8764,0.2895,0.0978,"Close",true,Window[1]) guiSetFont(Button[4],"sa-header") Label[1] = guiCreateLabel(0.004,0.0018,0.6761,0.0886,"Killingzone RPG",true,Window[1]) guiLabelSetColor(Label[1],255,255,255) guiLabelSetVerticalAlign(Label[1],"top") guiLabelSetHorizontalAlign(Label[1],"left",false) guiSetFont(Label[1],"sa-header") Label[2] = guiCreateLabel(0.7571,0.6605,0.1356,0.0332,"Your Health",true,Window[1]) guiLabelSetColor(Label[2],255,255,255) guiLabelSetVerticalAlign(Label[2],"top") guiLabelSetHorizontalAlign(Label[2],"left",false) Label[3] = guiCreateLabel(0.753,0.7528,0.1559,0.0314,"Vehicle Health",true,Window[1]) guiLabelSetColor(Label[3],255,255,255) guiLabelSetVerticalAlign(Label[3],"top") guiLabelSetHorizontalAlign(Label[3],"left",false) Progress[1] = guiCreateProgressBar(0.6356,0.6919,0.3563,0.0406,true,Window[1]) Progress[2] = guiCreateProgressBar(0.6356,0.7786,0.3603,0.048,true,Window[1]) Memo[1]= guiCreateMemo(0.0385,0.1236,0.5668,0.2804,"Hello and Welcome to Killingzone RPG.\\n\\nIn this server you can buy house, cars, and even weapons.\\n\\nOwner:\\n[NRNS]Coolboy\\n\\nScripters:\\n[NRNS]Coolboy\\n**ArmGuy**G",true,Window[1]) guiMemoSetReadOnly(Memo[1],true) Memo[2] = guiCreateMemo(0.0466,0.4539,0.5648,0.3598,"Rules:\\n\\nThere is no hacking in this server you will be banned.\\n\\nRespeact other players.\\n",true,Window[1]) guiMemoSetReadOnly(Memo[2],true) guiWindowSetSizable(Window[1],false) addEventHandler ( "onClientGUIClick", Button[1], fix vehicle $200 ) addEventHandler ( "onClientGUIClick", Button[2], full health $200 ) addEventHandler ( "onClientGUIClick", Button[3], suicide ) addEventHandler ( "onClientGUIClick", Button[4], close ) guiSetVisible(Window[1],true) showCursor(true) end end addCommandHandler("cp",changeState) function onStart() bindKey ("m", "down", changeState ) end addEventHandler("onClientResourceStart",getRootElement(),onStart) function close(button,state) if button == "left" and state =="down" then if guiGetVisible(Window[1]) then guiSetVisible(Winow[1]),false showCursor(false) end end end Link to comment
Remp Posted July 19, 2009 Share Posted July 19, 2009 you misspelled guiGetVisible in the changeState function, and you also placed the closing bracket in the wrong place, it should be guiSetVisible(Window[1],false) not guiSetVisible(Window[1]),false your function names in the onClientGUIClick handlers cannot contain spaces, so "full health" will be invalid and should be changed to something without spaces (such as fullhealth or full_health) you will probably also want to create your gui in your onStart function, currently you will recreate the gui every time you want to show it which is not ideal try this code: Window = {} Button = {} function changeState( ) if guiGetVisible(Window[1]) then guiSetVisible(Window[1],false) showCursor(false) else guiSetVisible(Window[1],true) showCursor(true) end end addCommandHandler("cp",changeState) function onStart() Window[1] = guiCreateWindow(618,138,512,595,"Player Menu",false) Button[1] = guiCreateButton(0.7348,0.3395,0.2551,0.0627,"Fix Vehicle $200",true,Window[1]) Button[2] = guiCreateButton(0.7368,0.4225,0.2551,0.0627,"Full Health $200",true,Window[1]) Button[3] = guiCreateButton(0.7368,0.5074,0.2551,0.0627,"Suicide",true,Window[1]) Button[4] = guiCreateButton(0.6883,0.8764,0.2895,0.0978,"Close",true,Window[1]) guiSetFont(Button[4],"sa-header") Label[1] = guiCreateLabel(0.004,0.0018,0.6761,0.0886,"Killingzone RPG",true,Window[1]) guiLabelSetColor(Label[1],255,255,255) guiLabelSetVerticalAlign(Label[1],"top") guiLabelSetHorizontalAlign(Label[1],"left",false) guiSetFont(Label[1],"sa-header") Label[2] = guiCreateLabel(0.7571,0.6605,0.1356,0.0332,"Your Health",true,Window[1]) guiLabelSetColor(Label[2],255,255,255) guiLabelSetVerticalAlign(Label[2],"top") guiLabelSetHorizontalAlign(Label[2],"left",false) Label[3] = guiCreateLabel(0.753,0.7528,0.1559,0.0314,"Vehicle Health",true,Window[1]) guiLabelSetColor(Label[3],255,255,255) guiLabelSetVerticalAlign(Label[3],"top") guiLabelSetHorizontalAlign(Label[3],"left",false) Progress[1] = guiCreateProgressBar(0.6356,0.6919,0.3563,0.0406,true,Window[1]) Progress[2] = guiCreateProgressBar(0.6356,0.7786,0.3603,0.048,true,Window[1]) Memo[1]= guiCreateMemo(0.0385,0.1236,0.5668,0.2804,"Hello and Welcome to Killingzone RPG.\n\nIn this server you can buy house, cars, and even weapons.\n\nOwner:\n[NRNS]Coolboy\n\nScripters:\n[NRNS]Coolboy\n**ArmGuy**G",true,Window[1]) guiMemoSetReadOnly(Memo[1],true) Memo[2] = guiCreateMemo(0.0466,0.4539,0.5648,0.3598,"Rules:\n\nThere is no hacking in this server you will be banned.\n\nRespeact other players.\n",true,Window[1]) guiMemoSetReadOnly(Memo[2],true) guiWindowSetSizable(Window[1],false) guiSetVisible(Window[1],false) addEventHandler ( "onClientGUIClick", Button[1], fixvehicle) addEventHandler ( "onClientGUIClick", Button[2], fullhealth) addEventHandler ( "onClientGUIClick", Button[3], suicide ) addEventHandler ( "onClientGUIClick", Button[4], close ) bindKey ("m", "down", changeState ) end addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),onStart) function close(button,state) if button == "left" and state =="down" then if guiGetVisible(Window[1]) then guiSetVisible(Window[1],false) showCursor(false) end end end remember to always double check for spelling errors in your code as these are very common causes of problems Link to comment
50p Posted July 19, 2009 Share Posted July 19, 2009 Use debug window! Don't just come here and ask why it doesn't work. You won't learn if you don't want to and it seems like you don't want to. Read a lot of wiki, read a lot of lua documentation. I have sent those links many times, even in one of your topics, AFAIR. And I'll say that again, use debug window ("/debugscript 3"). Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now