MetaGamer Posted November 27, 2011 Share Posted November 27, 2011 I want to know how to make a QUIZ system in MTA. In SA-MP it was very easy. For e.j. What are you? A) Human B) Male c) Guy D) Gal Link to comment
unknooooown Posted November 27, 2011 Share Posted November 27, 2011 I want to know how to make a QUIZ system in MTA. In SA-MP it was very easy. For e.j. What are you? A) Human B) Male c) Guy D) Gal There are a lot of different ways of doing this. Do you want it to be pure text, do you want a gui for it or something else? Give some more details on what your idea is and I will try to explain how you can make it. You are gonna have to script it yourself, but I don't mind pointing you in the right direction. Link to comment
MetaGamer Posted November 27, 2011 Author Share Posted November 27, 2011 I want it to be in a GUI. It's hard to make 15 gui's for each questions and getting the button click. It's a lengthy process. Link to comment
unknooooown Posted November 27, 2011 Share Posted November 27, 2011 I want it to be in a GUI. It's hard to make 15 gui's for each questions and getting the button click. It's a lengthy process. You wouldnt have to use 15 different gui's I know that it would seem like the most logic solution, but there is a way around that function openCustomGui(msg) local gui = {} gui._placeHolders = {} local screenWidth, screenHeight = guiGetScreenSize() local windowWidth, windowHeight = 200, 131 local left = screenWidth/2 - windowWidth/2 local top = screenHeight/2 - windowHeight/2 gui["_root"] = guiCreateWindow(left, top, windowWidth, windowHeight, msg, false) guiWindowSetSizable(gui["_root"], false) gui["pushButton"] = guiCreateButton(20, 95, 150, 23, "button", false, gui["_root"]) --addEventHandler("onClientGUIClick", gui["pushButton"], closeWindow, false) gui["label"] = guiCreateLabel(15, 27, 171, 61, "textToDisplay", false, gui["_root"]) guiLabelSetHorizontalAlign(gui["label"], "center", false) guiLabelSetVerticalAlign(gui["label"], "center") return gui, windowWidth, windowHeight end This function will be called every time you use 'openCustomGui(argument) Look at the code below for an example. function setCustomGuiTextMessage() randomMsg = 0 for i=1,15 do randomMsg = randomMsg + 1 openCustomGui(randomMsg) end end addCommandHandler("setCustomGuiTextMessage",setCustomGuiTextMessage) This result would make the GUI trigger 15 times, with a new message, in this case just a number, for every time the window is opened. From 1-15. Like this, we dont have to create many differeny guis for each message. As long as we know there is room for the message, we are good to go! If I were to change for i=1,15 do to for i=1,15000 do , then 15000 new windows would be opened, but we still only have ONE main window that we needed to create. Tell me if it makes sense to you Link to comment
MetaGamer Posted November 27, 2011 Author Share Posted November 27, 2011 awesome. But how to create 4 buttons on the window and detect which button has been clicked? Link to comment
unknooooown Posted November 27, 2011 Share Posted November 27, 2011 awesome. But how to create 4 buttons on the window and detect which button has been clicked? You could do something like: gui["pushButton1"] = guiCreateButton(20, 95, 150, 23, "button", false, gui["_root"]) gui["pushButton2"] = guiCreateButton(40, 95, 150, 23, "button", false, gui["_root"]) gui["pushButton3"] = guiCreateButton(60, 95, 150, 23, "button", false, gui["_root"]) gui["pushButton4"] = guiCreateButton(80, 95, 150, 23, "button", false, gui["_root"]) addEventHandler("onClientGUIClick", gui["pushButton1"], func1, false) addEventHandler("onClientGUIClick", gui["pushButton2"], func2, false) addEventHandler("onClientGUIClick", gui["pushButton3"], func3, false) addEventHandler("onClientGUIClick", gui["pushButton4"], func4, false) function func1() outputChatBox("Pressed pushButton1 and triggered function func1") end -- function func2() outputChatBox("Pressed pushButton2 and triggered function func2") end -- function func3() outputChatBox("Pressed pushButton3 and triggered function func3") end -- function func4() outputChatBox("Pressed pushButton4 and triggered function func4") end Again, this is just to show you how it can be done. This isnt the best way of doing it ( I would never do it like this for a script. ), but it can give you an idea of how you should do it yourself. UPDATE. Just wanted to add a more clean way of detecting the buttons. gui["pushButton1"] = guiCreateButton(20, 95, 150, 23, "button", false, gui["_root"]) addEventHandler("onClientGUIClick",root, detectBtn, false) -- In this function you can add all the if checks you want. Doesnt matter if there is one or 1000000 buttons in there : - P function detectBtn() if source == gui["pushButton1"] then outputChatBox("Button pressed") end end NOTE: When using onClientGUIClick: The source of this event is the GUI element that was clicked. Link to comment
MetaGamer Posted November 27, 2011 Author Share Posted November 27, 2011 You man is my saviour. 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