BiSolpos Posted June 18, 2022 Share Posted June 18, 2022 (edited) hi I have a problem Alpha does not work and the page changes without fadein & fadeout code local screenW, screenH = guiGetScreenSize() local sizeX, sizeY = (540 * 1), (540 * 1) local posX, posY = (screenW / 2) - (sizeX / 2), (screenH / 2) - (sizeY / 2) local font = dxCreateFont ("Images/font.ttf", 15) local PageId = 1 local Alpha = 255 function isMouseWithinRangeOf (posX, posY, sizeX, sizeY) if isCursorShowing() == false then return false end local cx,cy = getCursorPosition() cx,cy = cx * screenW, cy * screenH if cx >= posX and cx <= posX + sizeX and cy >= posY and cy <= posY + sizeY then return true,cx,cy else return false end end function ShowLoginPanel() addEventHandler("onClientRender", getRootElement(), RenderLoginPanel) addEventHandler("onClientRender", getRootElement(), RenderButtons) showCursor (true) showChat (false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), ShowLoginPanel) EditBoxLogin = { {x = posX * 1.226, y = posY * 1.8, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textlog = "", name = "Username"}, {x = posX * 1.226, y = posY * 2.2, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textlog = "", hide = true, name = "Password"}, } EditBoxRegister = { {x = posX * 1.226, y = posY * 1.4, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textreg = "", name = "UsernameReg"}, {x = posX * 1.226, y = posY * 1.8, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textreg = "", hide = true, name = "PasswordReg"}, } ButtonLogin = { {x = posX * 1.188, y = posY * 3, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/login.png", text = "Log In", func = "pressLogin"}, {x = posX * 1.528, y = posY * 3, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/register.png", text = "Register", func = "pressRegisterBut"}, } ButtonRegister = { {x = posX * 1.188, y = posY * 3.2, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/login.png", text = "Back", func = "pressBack"}, {x = posX * 1.528, y = posY * 3.2, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/register.png", text = "Register", func = "pressRegister"}, } function RenderLoginPanel() if PageId == 1 then for i, eboxlog in ipairs(EditBoxLogin) do dxDrawImage (eboxlog.x, eboxlog.y, eboxlog.w, eboxlog.h,"Images/editbox.png",0,0,0, eboxlog.borderColor) if isMouseWithinRangeOf(eboxlog.x, eboxlog.y, eboxlog.w, eboxlog.h) then eboxlog.borderColor = tocolor(132, 0, 255) else eboxlog.borderColor = tocolor(171, 171, 171) end if eboxClickI == i then eboxlog.borderColor = tocolor(132, 0, 255) end if eboxlog.textlog then eboxlog.textlog = table.concat(textlog[i],"") if eboxlog.hide == true then dxDrawText (string.rep("•",#textlog[i],""), eboxlog.x + 25, eboxlog.y, eboxlog.w, eboxlog.h + eboxlog.y, tocolor(255,255,255), screenW/1600, font, "left", "center") else dxDrawText (table.concat(textlog[i],""), eboxlog.x + 25, eboxlog.y, eboxlog.w, eboxlog.h + eboxlog.y, tocolor(255,255,255), screenW/1600, font, "left", "center") end end end elseif PageId == 2 then for i, eboxreg in ipairs(EditBoxRegister) do dxDrawImage (eboxreg.x, eboxreg.y, eboxreg.w, eboxreg.h,"Images/editbox.png",0,0,0, eboxreg.borderColor) if isMouseWithinRangeOf(eboxreg.x, eboxreg.y, eboxreg.w, eboxreg.h) then eboxreg.borderColor = tocolor(132, 0, 255) else eboxreg.borderColor = tocolor(171, 171, 171) end if eboxClickI == i then eboxreg.borderColor = tocolor(132, 0, 255) end if eboxreg.textreg then eboxreg.textreg = table.concat(textreg[i],"") if eboxreg.hide == true then dxDrawText (string.rep("•",#textreg[i],""), eboxreg.x + 25, eboxreg.y, eboxreg.w, eboxreg.h + eboxreg.y, tocolor(255,255,255), screenW/1600, font, "left", "center") else dxDrawText (table.concat(textreg[i],""), eboxreg.x + 25, eboxreg.y, eboxreg.w, eboxreg.h + eboxreg.y, tocolor(255,255,255), screenW/1600, font, "left", "center") end end end end end function RenderButtons() if PageId == 1 then for i, btnlog in ipairs(ButtonLogin) do if btnlog.back then dxDrawImage (btnlog.x, btnlog.y, btnlog.w, btnlog.h, btnlog.back) end if btnlog.text then dxDrawText (btnlog.text, btnlog.x, btnlog.y, btnlog.w + btnlog.x, btnlog.h + btnlog.y, tocolor(255,255,255), screenW/1600, font, "center", "center") end end elseif PageId == 2 then for i, btnreg in ipairs(ButtonRegister) do if btnreg.back then dxDrawImage (btnreg.x, btnreg.y, btnreg.w, btnreg.h, btnreg.back) end if btnreg.text then dxDrawText (btnreg.text, btnreg.x, btnreg.y, btnreg.w + btnreg.x, btnreg.h + btnreg.y, tocolor(255,255,255), screenW/1600, font, "center", "center") end end end end function onClick (button, state) if (button == "left" and state == "down") then eboxClickI = false return false end if PageId == 1 then for i, eboxlog in pairs(EditBoxLogin) do if isMouseWithinRangeOf(eboxlog.x, eboxlog.y, eboxlog.w, eboxlog.h) then eboxClickI = i return true end end for i, btnlog in pairs(ButtonLogin) do if isMouseWithinRangeOf(btnlog.x, btnlog.y, btnlog.w, btnlog.h) then if btnlog.func then loadstring("return "..btnlog.func.."()")() end end end elseif PageId == 2 then for i, eboxreg in pairs(EditBoxRegister) do if isMouseWithinRangeOf(eboxreg.x, eboxreg.y, eboxreg.w, eboxreg.h) then eboxClickI = i return true end end for i, btnreg in pairs(ButtonRegister) do if isMouseWithinRangeOf(btnreg.x, btnreg.y, btnreg.w, btnreg.h) then if btnreg.func then loadstring("return "..btnreg.func.."()")() end end end end end addEventHandler("onClientClick", getRootElement(), onClick) function pressRegisterBut() Alpha = 0 addEventHandler("onClientRender", getRootElement(), movePanelOut) end function pressBack() Alpha = 0 addEventHandler("onClientRender", getRootElement(), movePanelIn) end function movePanelOut() Alpha = math.min(Alpha + 5, 255) PageId = 2 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelOut) end end function movePanelIn() Alpha = math.min(Alpha + 5, 255) PageId = 1 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelIn) end end Thank you Edited June 18, 2022 by BiSolpos Link to comment
Moderators Vinyard Posted June 18, 2022 Moderators Share Posted June 18, 2022 Hi, I've moved your thread into the main Scripting section as this is the right place to request scripting-related help. 2 Link to comment
AngelAlpha Posted June 19, 2022 Share Posted June 19, 2022 14 hours ago, BiSolpos said: hi I have a problem Alpha does not work and the page changes without fadein & fadeout code local screenW, screenH = guiGetScreenSize() local sizeX, sizeY = (540 * 1), (540 * 1) local posX, posY = (screenW / 2) - (sizeX / 2), (screenH / 2) - (sizeY / 2) local font = dxCreateFont ("Images/font.ttf", 15) local PageId = 1 local Alpha = 255 function isMouseWithinRangeOf (posX, posY, sizeX, sizeY) if isCursorShowing() == false then return false end local cx,cy = getCursorPosition() cx,cy = cx * screenW, cy * screenH if cx >= posX and cx <= posX + sizeX and cy >= posY and cy <= posY + sizeY then return true,cx,cy else return false end end function ShowLoginPanel() addEventHandler("onClientRender", getRootElement(), RenderLoginPanel) addEventHandler("onClientRender", getRootElement(), RenderButtons) showCursor (true) showChat (false) end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), ShowLoginPanel) EditBoxLogin = { {x = posX * 1.226, y = posY * 1.8, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textlog = "", name = "Username"}, {x = posX * 1.226, y = posY * 2.2, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textlog = "", hide = true, name = "Password"}, } EditBoxRegister = { {x = posX * 1.226, y = posY * 1.4, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textreg = "", name = "UsernameReg"}, {x = posX * 1.226, y = posY * 1.8, w = 300, h = 60, borderColor = tocolor(171, 171, 171, Alpha), textreg = "", hide = true, name = "PasswordReg"}, } ButtonLogin = { {x = posX * 1.188, y = posY * 3, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/login.png", text = "Log In", func = "pressLogin"}, {x = posX * 1.528, y = posY * 3, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/register.png", text = "Register", func = "pressRegisterBut"}, } ButtonRegister = { {x = posX * 1.188, y = posY * 3.2, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/login.png", text = "Back", func = "pressBack"}, {x = posX * 1.528, y = posY * 3.2, w = 160, h = 50, borderColor = tocolor(255, 167, 0, Alpha), back = "Images/register.png", text = "Register", func = "pressRegister"}, } function RenderLoginPanel() if PageId == 1 then for i, eboxlog in ipairs(EditBoxLogin) do dxDrawImage (eboxlog.x, eboxlog.y, eboxlog.w, eboxlog.h,"Images/editbox.png",0,0,0, eboxlog.borderColor) if isMouseWithinRangeOf(eboxlog.x, eboxlog.y, eboxlog.w, eboxlog.h) then eboxlog.borderColor = tocolor(132, 0, 255) else eboxlog.borderColor = tocolor(171, 171, 171) end if eboxClickI == i then eboxlog.borderColor = tocolor(132, 0, 255) end if eboxlog.textlog then eboxlog.textlog = table.concat(textlog[i],"") if eboxlog.hide == true then dxDrawText (string.rep("•",#textlog[i],""), eboxlog.x + 25, eboxlog.y, eboxlog.w, eboxlog.h + eboxlog.y, tocolor(255,255,255), screenW/1600, font, "left", "center") else dxDrawText (table.concat(textlog[i],""), eboxlog.x + 25, eboxlog.y, eboxlog.w, eboxlog.h + eboxlog.y, tocolor(255,255,255), screenW/1600, font, "left", "center") end end end elseif PageId == 2 then for i, eboxreg in ipairs(EditBoxRegister) do dxDrawImage (eboxreg.x, eboxreg.y, eboxreg.w, eboxreg.h,"Images/editbox.png",0,0,0, eboxreg.borderColor) if isMouseWithinRangeOf(eboxreg.x, eboxreg.y, eboxreg.w, eboxreg.h) then eboxreg.borderColor = tocolor(132, 0, 255) else eboxreg.borderColor = tocolor(171, 171, 171) end if eboxClickI == i then eboxreg.borderColor = tocolor(132, 0, 255) end if eboxreg.textreg then eboxreg.textreg = table.concat(textreg[i],"") if eboxreg.hide == true then dxDrawText (string.rep("•",#textreg[i],""), eboxreg.x + 25, eboxreg.y, eboxreg.w, eboxreg.h + eboxreg.y, tocolor(255,255,255), screenW/1600, font, "left", "center") else dxDrawText (table.concat(textreg[i],""), eboxreg.x + 25, eboxreg.y, eboxreg.w, eboxreg.h + eboxreg.y, tocolor(255,255,255), screenW/1600, font, "left", "center") end end end end end function RenderButtons() if PageId == 1 then for i, btnlog in ipairs(ButtonLogin) do if btnlog.back then dxDrawImage (btnlog.x, btnlog.y, btnlog.w, btnlog.h, btnlog.back) end if btnlog.text then dxDrawText (btnlog.text, btnlog.x, btnlog.y, btnlog.w + btnlog.x, btnlog.h + btnlog.y, tocolor(255,255,255), screenW/1600, font, "center", "center") end end elseif PageId == 2 then for i, btnreg in ipairs(ButtonRegister) do if btnreg.back then dxDrawImage (btnreg.x, btnreg.y, btnreg.w, btnreg.h, btnreg.back) end if btnreg.text then dxDrawText (btnreg.text, btnreg.x, btnreg.y, btnreg.w + btnreg.x, btnreg.h + btnreg.y, tocolor(255,255,255), screenW/1600, font, "center", "center") end end end end function onClick (button, state) if (button == "left" and state == "down") then eboxClickI = false return false end if PageId == 1 then for i, eboxlog in pairs(EditBoxLogin) do if isMouseWithinRangeOf(eboxlog.x, eboxlog.y, eboxlog.w, eboxlog.h) then eboxClickI = i return true end end for i, btnlog in pairs(ButtonLogin) do if isMouseWithinRangeOf(btnlog.x, btnlog.y, btnlog.w, btnlog.h) then if btnlog.func then loadstring("return "..btnlog.func.."()")() end end end elseif PageId == 2 then for i, eboxreg in pairs(EditBoxRegister) do if isMouseWithinRangeOf(eboxreg.x, eboxreg.y, eboxreg.w, eboxreg.h) then eboxClickI = i return true end end for i, btnreg in pairs(ButtonRegister) do if isMouseWithinRangeOf(btnreg.x, btnreg.y, btnreg.w, btnreg.h) then if btnreg.func then loadstring("return "..btnreg.func.."()")() end end end end end addEventHandler("onClientClick", getRootElement(), onClick) function pressRegisterBut() Alpha = 0 addEventHandler("onClientRender", getRootElement(), movePanelOut) end function pressBack() Alpha = 0 addEventHandler("onClientRender", getRootElement(), movePanelIn) end function movePanelOut() Alpha = math.min(Alpha + 5, 255) PageId = 2 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelOut) end end function movePanelIn() Alpha = math.min(Alpha + 5, 255) PageId = 1 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelIn) end end Thank you function updateBtnColor () for i, v in ipairs (ButtonRegister) do v.borderColor = tocolor(255, 167, 0, Alpha) end end function pressRegisterBut() Alpha = 0 updateBtnColor () addEventHandler("onClientRender", getRootElement(), movePanelOut) end function pressBack() Alpha = 0 updateBtnColor () addEventHandler("onClientRender", getRootElement(), movePanelIn) end function movePanelOut() Alpha = math.min(Alpha + 5, 255) updateBtnColor () PageId = 2 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelOut) end end function movePanelIn() Alpha = math.min(Alpha + 5, 255) updateBtnColor () PageId = 1 if tonumber(Alpha) == 255 then removeEventHandler("onClientRender", getRootElement(), movePanelIn) end end 1 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