ShayF2 Posted June 11, 2017 Share Posted June 11, 2017 I'm trying to make a DX Login system for my server. I ran into a snag. Only the username button for the login line changes color when you hover your mouse, but it only changes color when you hover over the register button. I'm new to client side scripting, I'm asking for help with this script. local x,y = guiGetScreenSize() local r = {} local g = {} local b = {} local a = {} local range = {} function isMouseWithinRangeOf(psx,pssx,psy,pssy) if not isCursorShowing() then return false end local cx,cy = getCursorPosition() cx,cy = cx*x,cy*y if cx >= psx and cx <= psx+pssx and cy >= psy and cy <= psy+pssy then return true,cx,cy else return false end end addEventHandler("onClientRender",root,function() showCursor(true) window = dxDrawRectangle(0,0,x,y,tocolor(0,0,0,255),false) mainText = dxDrawText("Welcome!\nPlease Login or Register",x*0.1603,y*0.0729,x*0.8338,y*0.1940,tocolor(255,255,255,255),1.30,"pricedown","center","center",false,false,false,false,false) if not r['loginUsernameBox'] then r['loginUsernameBox'] = 255 end if not g['loginUsernameBox'] then g['loginUsernameBox'] = 255 end if not b['loginUsernameBox'] then b['loginUsernameBox'] = 255 end if not a['loginUsernameBox'] then a['loginUsernameBox'] = 255 end loginUsernameBox = dxDrawRectangle(x*0.1676,y*0.2760,x*0.1735,y*0.0573,tocolor(r['loginUsernameBox'],g['loginUsernameBox'],b['loginUsernameBox'],a['loginUsernameBox']),false) range['loginUsernameBox'] = {isMouseWithinRangeOf(x*0.1676,x*0.1735,y*0.2760,y*0.3359),'loginUsernameBox'} loginUsernameText = dxDrawText("Username",x*0.1676,y*0.2760,x*0.3412,y*0.3359,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) if not r['loginPasswordBox'] then r['loginPasswordBox'] = 255 end if not g['loginPasswordBox'] then g['loginPasswordBox'] = 255 end if not b['loginPasswordBox'] then b['loginPasswordBox'] = 255 end if not a['loginPasswordBox'] then a['loginPasswordBox'] = 255 end loginPasswordBox = dxDrawRectangle(x*0.3603,y*0.2760,x*0.1735,y*0.0573,tocolor(r['loginPasswordBox'],g['loginPasswordBox'],b['loginPasswordBox'],a['loginPasswordBox']),false) range['loginPasswordBox'] = {isMouseWithinRangeOf(x*0.3603,x*0.1735,y*0.2760,y*0.0573),'loginPasswordBox'} loginPasswordText = dxDrawText("Password",x*0.3603,y*0.2760,x*0.5338,y*0.3359,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) if not r['loginBox'] then r['loginBox'] = 255 end if not g['loginBox'] then g['loginBox'] = 255 end if not b['loginBox'] then b['loginBox'] = 255 end if not a['loginBox'] then a['loginBox'] = 255 end loginBox = dxDrawRectangle(x*0.6257,y*0.2760,x*0.1735,y*0.0573,tocolor(r['loginBox'],g['loginBox'],b['loginBox'],a['loginBox']),false) range['loginBox'] = {isMouseWithinRangeOf(x*0.6257,x*0.1735,y*0.2760,y*0.0573),'loginBox'} loginText = dxDrawText("Login",x*0.6257,y*0.2760,x*0.7993,y*0.3359,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) if not r['registerUsernameBox'] then r['registerUsernameBox'] = 255 end if not g['registerUsernameBox'] then g['registerUsernameBox'] = 255 end if not b['registerUsernameBox'] then b['registerUsernameBox'] = 255 end if not a['registerUsernameBox'] then a['registerUsernameBox'] = 255 end registerUsernameBox = dxDrawRectangle(x*0.1676,y*0.4245,x*0.1735,y*0.0573,tocolor(r['registerUsernameBox'],g['registerUsernameBox'],b['registerUsernameBox'],a['registerUsernameBox']),false) range['registerUsernameBox'] = {isMouseWithinRangeOf(x*0.1676,x*0.1735,y*0.4245,y*0.0573),'registerUsernameBox'} registerUsernameText = dxDrawText("Username",x*0.1676,y*0.4245,x*0.3412,y*0.4844,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) if not r['registerEmailBox'] then r['registerEmailBox'] = 255 end if not g['registerEmailBox'] then g['registerEmailBox'] = 255 end if not b['registerEmailBox'] then b['registerEmailBox'] = 255 end if not a['registerEmailBox'] then a['registerEmailBox'] = 255 end registerEmailBox = dxDrawRectangle(x*0.1676,y*0.4974,x*0.1735,y*0.0573,tocolor(r['registerEmailBox'],g['registerEmailBox'],b['registerEmailBox'],a['registerEmailBox']),false) range['registerEmailBox'] = {isMouseWithinRangeOf(x*0.1676,x*0.1735,y*0.4974,y*0.0573),'registerEmailBox'} registerEmailText = dxDrawText("Email",x*0.1676,y*0.4974,x*0.3412,y*0.5573,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) if not r['registerPasswordBox'] then r['registerPasswordBox'] = 255 end if not g['registerPasswordBox'] then g['registerPasswordBox'] = 255 end if not b['registerPasswordBox'] then b['registerPasswordBox'] = 255 end if not a['registerPasswordBox'] then a['registerPasswordBox'] = 255 end registerPasswordBox = dxDrawRectangle(x*0.3603,y*0.4245,x*0.1735,y*0.0573,tocolor(r['registerPasswordBox'],g['registerPasswordBox'],b['registerPasswordBox'],a['registerPasswordBox']),false) range['registerPasswordBox'] = {isMouseWithinRangeOf(x*0.3603,x*0.1735,y*0.4245,y*0.0573),'registerPasswordBox'} registerPasswordText = dxDrawText("Password",x*0.3603,y*0.4245,x*0.5338,y*0.4844,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) if not r['registerRetypePasswordBox'] then r['registerRetypePasswordBox'] = 255 end if not g['registerRetypePasswordBox'] then g['registerRetypePasswordBox'] = 255 end if not b['registerRetypePasswordBox'] then b['registerRetypePasswordBox'] = 255 end if not a['registerRetypePasswordBox'] then a['registerRetypePasswordBox'] = 255 end registerRetypePasswordBox = dxDrawRectangle(x*0.3603,y*0.4974,x*0.1735,y*0.0573,tocolor(r['registerRetypePasswordBox'],g['registerRetypePasswordBox'],b['registerRetypePasswordBox'],a['registerRetypePasswordBox']),false) range['registerRetypePasswordBox'] = {isMouseWithinRangeOf(x*0.3603,x*0.1735,y*0.4974,y*0.0573),'registerRetypePasswordBox'} registerRetypePasswordText = dxDrawText("Repeat Password",x*0.3603,y*0.4974,x*0.5338,y*0.5573,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) if not r['registerBox'] then r['registerBox'] = 255 end if not g['registerBox'] then g['registerBox'] = 255 end if not b['registerBox'] then b['registerBox'] = 255 end if not a['registerBox'] then a['registerBox'] = 255 end registerBox = dxDrawRectangle(x*0.6257,y*0.4245,x*0.1735,y*0.0573,tocolor(r['registerBox'],g['registerBox'],b['registerBox'],a['registerBox']),false) range['registerBox'] = {isMouseWithinRangeOf(x*0.6257,x*0.1735,y*0.4245,y*0.0573),'registerBox'} registerText = dxDrawText("Register",x*0.6257,y*0.4245,x*0.7993,y*0.4844,tocolor(0,0,0,254),1.10,"default-bold","center","center",false,false,false,false,false) updatesBox = dxDrawRectangle(x*0.1676,y*0.5807,x*0.6588,y*0.3490,tocolor(255,255,255,255),false) updatesText = dxDrawText("Updates will be posted here!",x*0.1676,y*0.5807,x*0.8265,y*0.9297,tocolor(0,0,0,254),1.00,"default","left","top",false,false,false,false,false) rememberMeText = dxDrawText("Remember Me",x*0.6257,y*0.3490,x*0.7346,y*0.3841,tocolor(255,255,255,255),1.00,"default-bold","right","center",false,false,false,false,false) if not r['rememberMeOffBox'] then r['rememberMeOffBox'] = 255 end if not g['rememberMeOffBox'] then g['rememberMeOffBox'] = 255 end if not b['rememberMeOffBox'] then b['rememberMeOffBox'] = 255 end if not a['rememberMeOffBox'] then a['rememberMeOffBox'] = 255 end rememberMeOffBox = dxDrawRectangle(x*0.7706,y*0.3503,x*0.0272,y*0.0326,tocolor(r['rememberMeOffBox'],g['rememberMeOffBox'],b['rememberMeOffBox'],a['rememberMeOffBox']),false) range['rememberMeOffBox'] = {isMouseWithinRangeOf(x*0.7706,x*0.0272,y*0.3503,y*0.0326),'rememberMeOffBox'} rememberMeOffText = dxDrawText("Off",x*0.7706,y*0.3503,x*0.7993,y*0.3854,tocolor(0,0,0,254),1.00,"default-bold","center","center",false,false,false,false,false) if not r['rememberMeOnBox'] then r['rememberMeOnBox'] = 255 end if not g['rememberMeOnBox'] then g['rememberMeOnBox'] = 255 end if not b['rememberMeOnBox'] then b['rememberMeOnBox'] = 255 end if not a['rememberMeOnBox'] then a['rememberMeOnBox'] = 255 end rememberMeOnBox = dxDrawRectangle(x*0.7419,y*0.3503,x*0.0272,y*0.0326,tocolor(r['rememberMeOnBox'],g['rememberMeOnBox'],b['rememberMeOnBox'],a['rememberMeOnBox']),false) range['rememberMeOnBox'] = {isMouseWithinRangeOf(x*0.7419,x*0.0272,y*0.3503,y*0.0326),'rememberMeOnBox'} rememberMeOnText = dxDrawText("On",x*0.7419,y*0.3503,x*0.7706,y*0.3854,tocolor(0,0,0,254),1.00,"default-bold","center","center",false,false,false,false,false) end) links = { {loginUsernameText,loginUsernameBox,'loginUsernameBox'}, {loginPasswordText,loginPasswordBox,'loginPasswordBox'}, {loginText,loginBox,'loginBox'}, {registerUsernameText,registerUsernameBox,'registerUsernameBox'}, {registerEmailText,registerEmailBox,'registerEmailBox'}, {registerPasswordText,registerPasswordBox,'registerPasswordBox'}, {registerRetypePasswordText,registerRetypePasswordBox,'registerRetypePasswordBox'}, {registerText,registerBox,'registerBox'}, {rememberMeOffText,rememberMeOffBox,'rememberMeOffBox'}, {rememberMeOnText,rememberMeOnBox,'rememberMeOnBox'} } function getLink(text,box,generic) for i,v in pairs(links) do if v[1] == text or v[2] == box or v[3] == generic then return v[1],v[2],v[3] end end end addEventHandler('onClientRender',root,function() for i,v in pairs(range) do if v[1] == true then local text,box,generic = getLink(_,_,v[2]) if generic then r[generic] = 100 g[generic] = 100 b[generic] = 100 a[generic] = 255 end elseif v[1] == false then local text,box,generic = getLink(_,_,v[2]) if generic then r[generic] = 255 g[generic] = 255 b[generic] = 255 a[generic] = 255 end end end end) 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