Eelke Posted February 13, 2011 Share Posted February 13, 2011 (edited) I made a gate in a51 with keypad from this tut: https://wiki.multitheftauto.com/wiki/Scripting_the_GUI_-_Tutorial_2#Creating_the_GUI But the buttons dont work... this is my script.lua: function createKeypad() -- get the screen width and height local sWidth, sHeight = guiGetScreenSize() -- create the window, using some maths to find the centre of the screen local Width,Height = 142,276 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) keypadWindow = guiCreateWindow(X,Y,Width,Height,"Keypad",false) -- don't allow people to resize the keypad guiWindowSetSizable(keypadWindow,false) -- create buttons labeled 0-9, "*", "#", "Enter" and "C" (clear) keypadButton1 = guiCreateButton(13,68,37,36,"1",false,keypadWindow) keypadButton2 = guiCreateButton(53,68,37,36,"2",false,keypadWindow) keypadButton3 = guiCreateButton(93,68,37,36,"3",false,keypadWindow) keypadButton4 = guiCreateButton(13,108,37,36,"4",false,keypadWindow) keypadButton5 = guiCreateButton(53,108,37,36,"5",false,keypadWindow) keypadButton6 = guiCreateButton(93,108,37,36,"6",false,keypadWindow) keypadButton7 = guiCreateButton(13,148,37,36,"7",false,keypadWindow) keypadButton8 = guiCreateButton(53,148,37,36,"8",false,keypadWindow) keypadButton9 = guiCreateButton(93,148,37,36,"9",false,keypadWindow) keypadButtonAsterix = guiCreateButton(13,188,37,36,"*",false,keypadWindow) keypadButton0 = guiCreateButton(53,188,37,36,"0",false,keypadWindow) keypadButtonHash = guiCreateButton(93,188,37,36,"#",false,keypadWindow) keypadButtonExit = guiCreateButton(13,228,37,36,"Exit",false,keypadWindow) keypadButtonEnter = guiCreateButton(53,228,37,36,"Enter",false,keypadWindow) keypadButtonClear = guiCreateButton(93,228,37,36,"Clear",false,keypadWindow) -- create a gridlist to act as a backdrop on the kaypad display keypadGridlistDisplay = guiCreateGridList(13,25,117,33,false,keypadWindow) guiGridListSetSelectionMode(keypadGridlistDisplay,2) guiSetAlpha(keypadGridlistDisplay,0.6) -- create a label so we can write text on the keypad display keypadLabelDisplay = guiCreateLabel(14,26,115,30,"Enter Keycode.",false,keypadWindow) guiLabelSetColor(keypadLabelDisplay,255,000,000) guiLabelSetVerticalAlign(keypadLabelDisplay,"center") guiLabelSetHorizontalAlign(keypadLabelDisplay,"center",false) guiSetVisible(keypadWindow,false) end -- create the GUI when the resource starts addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),createKeypad) function updateDisplay(text) -- if we are passing some text if text then -- if its a digit or * or #, then append it to the end of the display if tonumber(text) or text == "*" or text == "#" then guiSetText(keypadLabelDisplay,guiGetText(keypadLabelDisplay) .. text) -- otherwise replace the display with the new text else guiSetText(keypadLabelDisplay,text) end -- if we pass nil, clear the display entirely else guiSetText(keypadLabelDisplay,"") end end local keypadCodes = { ["a51MainGateKeypadCode"] = "4455*#" } addEvent("verifyKeypadCode",true) addEventHandler("verifyKeypadCode",root,function(code,keypadID) if code then -- using the table we created earlier, check if the code supplied is the same as the code for this gate if code == keypadCodes[keypadID] then -- if it is, tell the client that it was successful triggerClientEvent(client,"onKeypadVerificationSuccessful",client,keypadID) else -- if it is not, tell the client that it was not successful triggerClientEvent(client,"onKeypadVerificationFailed",client,keypadID) end end end) addEvent("onKeypadVerificationSuccessful",true) addEventHandler("onKeypadVerificationSuccessful",root, function() -- hide the keypad and reset the display text ready for next time guiSetVisible(keypadWindow,false) updateDisplay("Enter Keycode.") showCursor(false,false) end ) addEvent("onKeypadVerificationFailed",true) addEventHandler("onKeypadVerificationFailed",root, function() -- update the display text to show the code was invalid updateDisplay("Invalid Keycode.") end ) addCommandHandler("a51gate",function() guiSetVisible(keypadWindow,true) showCursor(true,true) setElementData(keypadWindow,"keypadID","a51MainGateKeypadCode") end) addEventHandler("onKeypadVerificationSuccessful",root, -- keypadID is sent back from the server function(keypadID) -- get the gate object (this is where the id="a51MainGateKeypadCode" tag in the map file becomes useful) local gate = getElementByID(keypadID) -- if we found the object if gate then -- get the new position (as we defined in the map file) local x = tonumber(getElementData(gate,"newPosX")) local y = tonumber(getElementData(gate,"newPosY")) local z = tonumber(getElementData(gate,"newPosZ")) -- move the gate moveObject(gate,1500,x,y,z) -- get the original position x = tonumber(getElementData(gate,"posX")) y = tonumber(getElementData(gate,"posY")) z = tonumber(getElementData(gate,"posZ")) -- set a timer to close the gate in 5 seconds setTimer(moveObject,5000,1,gate,1500,x,y,z) end end ) Edited February 13, 2011 by Guest Link to comment
Castillo Posted February 13, 2011 Share Posted February 13, 2011 check in meta.xml, GUI elements are only client side, so should appear type="client" Link to comment
Eelke Posted February 13, 2011 Author Share Posted February 13, 2011 Someone can help? the gui doesnt even open anymore -.- 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