Jump to content

GUI Checkbox and buttons


proracer

Recommended Posts

Hello, I was creating a code so when player ticks the checkbox and presses the button he will agree with rules and if he does not ticks checkbox and immediately presses button it won't close window.

The problem is that when I press checkbox and press the button it won't close the window.Don't bother reading the start.

You can easily start reading from 25 to 40.

Code:

function drawRulesGUI() 
  
--- Using GUI Script Editor 
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Memo = {} 
GUIEditor_Checkbox = {} 
GUIEditor_Label = {} 
showCursor(true,true) 
GUIEditor_Window[1] = guiCreateWindow(493,126,850,620,"TripleX Clan Server Rules [MUST READ!]",false) 
guiWindowSetSizable(GUIEditor_Window[1],false) 
guiWindowSetMovable(GUIEditor_Window[1],false) 
GUIEditor_Memo[1] = guiCreateMemo(13,81,828,465,"1. Do not cheat or use any 3rd party mod.\n\n2. Do not swear and insult our players or admins.\n\n3. We do not allow spamming and flooding the chat.\n\n4. Please respect all players and admins.\n\n5. If you want to join our clan please post it on our site.\n\n6. If you have any suggestions about server/site or scripts\n\n   post it on our site.\n\n\n  [ Coming GUI based Suggestions tab.]\n\n\n   Have fun!",false,GUIEditor_Window[1]) 
guiMemoSetReadOnly(GUIEditor_Memo[1], true) 
GUIEditor_Checkbox[1] = guiCreateCheckBox(224,548,39,20,"",false,false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel(23,551,361,26,"I have read and I accept the rules.",false,GUIEditor_Window[1]) 
guiLabelSetColor(GUIEditor_Label[1],255,255,255) 
guiLabelSetVerticalAlign(GUIEditor_Label[1],"top") 
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Button[1] = guiCreateButton(14,576,231,35,"I accept the rules.",false,GUIEditor_Window[1]) 
guiSetFont(GUIEditor_Button[1],"default-bold-small") 
  
addEventHandler ("onClientGUIClick", GUIEditor_Button[1], drawRulesGUI) 
  
-- This segment of code is if player does not select checkbox and presses the button 
function rulesCheckBoxAndButton(button, state) 
if guiCheckBoxGetSelected(GUIEditor_Checkbox[1]) == false and button == "left" and state == "up" then 
return  
end 
-- This segment of code is if playe selects checkbox and presses the button 
if guiCheckBoxGetSelected(GUIEditor_Checkbox[1]) == true and button == "left" and state == "up" then 
guiSetVisible(GUIEditor_Window[1], false) 
showCursor(false, false) 
outputChatBox("Thank you for accepting our rules.") 
end 
end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), drawRulesGUI) 
  
  
  
-- Direct X Drawing 
addEventHandler("onClientRender",root, 
    function() 
        dxDrawText("Player Rules",536.0,172.0,817.0,217.0,tocolor(255,0,0,255),0.8,"bankgothic","top","left",false,false,false) 
        dxDrawLine(497.0,201.0,1341.0,201.0,tocolor(255,0,0,255),1.0,false) 
    end 
) 

Link to comment

So, you made that if he clicked button, it would draw all windows again, when it should do a checkbox check function, like:

addEventHandler ("onClientGUIClick", GUIEditor_Button[1], function (button, state) 
   if button == "left" and state == "up" then 
     if guiCheckBoxGetSelected(GUIEditor_Checkbox[1]) == false then --checkbox not selected 
             return  
     else -- checkbox selected 
             guiSetVisible(GUIEditor_Window[1], false) 
             showCursor(false, false) 
             outputChatBox("Thank you for accepting our rules.")            
     end 
  end 
end,false) 

Link to comment

Give a name to function which draws text and other stuff:

-- Direct X Drawing 
function drawText() 
        dxDrawText("Player Rules",536.0,172.0,817.0,217.0,tocolor(255,0,0,255),0.8,"bankgothic","top","left",false,false,false) 
        dxDrawLine(497.0,201.0,1341.0,201.0,tocolor(255,0,0,255),1.0,false) 
end 
addEventHandler("onClientRender",root,drawText) 

Then remove text with

removeEventHandler("onClientRender",root,drawText) 

Keep in mind that players using different resolution may not see text and lines drawn properly, you need a fix for that.

Edited by Guest
Link to comment

I edited the script a little but now it doesn't show. :cry:

function drawRulesGUI() 
  
--- Using GUI Script Editor 
  
GUIEditor_Window = {} 
GUIEditor_Button = {} 
GUIEditor_Memo = {} 
GUIEditor_Checkbox = {} 
GUIEditor_Label = {} 
local sWidth,sHeight = 1920, 1080 
showCursor(true,true) 
GUIEditor_Window[1] = guiCreateWindow( 
(sWidth-493)/sWidth, 
(sHeight-126)/sHeight, 
(sWidth-850)/sWidth, 
(sHeight-620)/sHeight, 
"TripleX Clan Server Rules [MUST READ!]",false) 
guiWindowSetSizable(GUIEditor_Window[1],false) 
guiWindowSetMovable(GUIEditor_Window[1],false) 
GUIEditor_Memo[1] = guiCreateMemo( 
(sWidth-13)/sWidth, 
(sHeight-81)/sHeight, 
(sWidth-828)/sWidth, 
(sHeight-465)/sHeight, 
"1. Do not cheat or use any 3rd party mod.\n\n2. Do not swear and insult our players or admins.\n\n3. We do not allow spamming and flooding the chat.\n\n4. Please respect all players and admins.\n\n5. If you want to join our clan please post it on our site.\n\n6. If you have any suggestions about server/site or scripts\n\n   post it on our site.\n\n\n  [ Coming GUI based Suggestions tab.]\n\n\n   Have fun!",false,GUIEditor_Window[1]) 
guiMemoSetReadOnly(GUIEditor_Memo[1], true) 
GUIEditor_Checkbox[1] = guiCreateCheckBox( 
(sWidth-224)/sWidth, 
(sHeight-548)/sHeight, 
(sWidth-17)/sWidth, 
(sHeight-17)/sHeight, 
"",false,false,GUIEditor_Window[1]) 
GUIEditor_Label[1] = guiCreateLabel( 
(sWidth-23)/sWidth, 
(sHeight-551)/sHeight, 
(sWidth-361)/sWidth, 
(sHeight-26)/sHeight, 
"I have read and I accept the rules.",false,GUIEditor_Window[1]) 
guiLabelSetColor(GUIEditor_Label[1],255,255,255) 
guiLabelSetVerticalAlign(GUIEditor_Label[1],"top") 
guiLabelSetHorizontalAlign(GUIEditor_Label[1],"left",false) 
guiSetFont(GUIEditor_Label[1],"default-bold-small") 
GUIEditor_Button[1] = guiCreateButton( 
(sWidth-14)/sWidth, 
(sHeight-576)/sHeight, 
(sWidth-231)/sWidth, 
(sHeight-35)/sHeight, 
"I accept the rules.",false,GUIEditor_Window[1]) 
guiSetFont(GUIEditor_Button[1],"default-bold-small") 
  
addEventHandler ("onClientGUIClick", GUIEditor_Button[1], function (button, state) 
   if button == "left" and state == "up" then 
     if guiCheckBoxGetSelected(GUIEditor_Checkbox[1]) == false then --checkbox not selected 
             return 
     else -- checkbox selected 
             guiSetVisible(GUIEditor_Window[1], false) 
             showCursor(false, false) 
             outputChatBox("Thank you for accepting our rules.")           
     end 
  end 
end,false) 
end 

GUI doesn't show... no errors.

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