Jump to content

[Help] How to make the changing pages in a dashboard?


AlvarO

Recommended Posts

I was scripting and tried to make a dashboard, the design is done etc.. but when I tried to make different pages and make them changing when a player clicks in a button, it dosn't changes, I hope I explained myself, my english is not so good.

  
--I tried this: 
function showPage(thePage) 
    if thePage == "homepage" then 
        openHomepage() 
        closePersonalStats() 
    elseif thePage == "personalStats" then 
        openPersonalStats() 
        closeHomepage() 
    end 
end 
  

Link to comment

There are different pages, i'll post them all:

--Core page

  
local dxfont_0 = dxCreateFont("font/font.ttf", 16) 
local dxfont_1 = dxCreateFont("font/font.ttf", 12) 
  
local visible = false 
local sX, sY = guiGetScreenSize() 
local playerMoney = getPlayerMoney(localPlayer) or 0 
local state = "homepage" 
local alpha = 0 
  
function drawCore() 
    dxDrawRectangle((383/1366)*sX, (150/768)*sY, (600/1366)*sX, (450/768)*sY, tocolor(0, 0, 0, 150), false) 
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  
    name = getPlayerName(localPlayer) 
    dxDrawText(name, x*320, y*(pos+height-45), x*505, y*326, tocolor(255, 255, 255, 255), x*0.9, "default-bold", "left", "center", false, false, true, true, false) 
    dxDrawImage( (400/1366)*sX, (160/768)*sY, (50/1366)*sX, (50/768)*sY, "img/profile.png", 0, 0, 0 ) 
    dxDrawText(name, (490/1366)*sX, (167/768)*sY, (505/1366)*sX, (326/768)*sY, tocolor(255, 255, 255, 255), sX*0.9, dxfont_0, "left", "center", false, false, true, true, false) 
    dxDrawText ("Money: "..playerMoney.."$", (458/1366)*sX, (180/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), 1, dxfont_0) 
     
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ 
  
    if isMouseInPosition ((395/1366)*sX, (230/768)*sY, (160/1366)*sX, (35/768)*sY) then 
        dxDrawRectangle((395/1366)*sX, (230/768)*sY, (160/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 25)) 
    end 
    dxDrawImage((400/1366)*sX, (233/768)*sY, (25/1366)*sX, (25/768)*sY, "img/home.png", 0, 0, 0 ) 
    dxDrawText ("Home", (460/1366)*sX, (245/768)*sY, x, y, tocolor ( 255, 102, 0, 255 ), 1, dxfont_0, "center", "center", false, false, true, true, false) 
  
    if isMouseInPosition ((395/1366)*sX, (280/768)*sY, (160/1366)*sX, (35/768)*sY) then 
        dxDrawRectangle((395/1366)*sX, (280/768)*sY, (160/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 25)) 
    end 
    dxDrawImage( (400/1366)*sX, (283/768)*sY, (25/1366)*sX, (25/768)*sY, "img/pie-chart.png", 0, 0, 0 ) 
    dxDrawText ("Personal Stats", (487/1366)*sX, (295/768)*sY, x, y, tocolor ( 240, 120, 90, 255 ), (0.9/1366)*sX, dxfont_0, "center", "center", false, false, true, true, false) 
  
    if isMouseInPosition ((395/1366)*sX, (330/768)*sY, (160/1366)*sX, (35/768)*sY) then 
        dxDrawRectangle((395/1366)*sX, (330/768)*sY, (160/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 25)) 
    end 
    dxDrawImage( (400/1366)*sX, (333/768)*sY, (25/1366)*sX, (25/768)*sY, "img/trophy.png", 0, 0, 0 ) 
    dxDrawText ("Achievements", (487/1366)*sX, (345/768)*sY, x, y, tocolor ( 248, 216, 93, 255 ), (0.9/1366)*sX, dxfont_0, "center", "center", false, false, true, true, false) 
  
    if isMouseInPosition ((395/1366)*sX, (380/768)*sY, (160/1366)*sX, (35/768)*sY) then 
        dxDrawRectangle((395/1366)*sX, (380/768)*sY, (160/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 25)) 
    end 
    dxDrawImage( (400/1366)*sX, (383/768)*sY, (25/1366)*sX, (25/768)*sY, "img/graph.png", 0, 0, 0 ) 
    dxDrawText ("Leaderboard", (487/1366)*sX, (395/768)*sY, x, y, tocolor ( 240, 155, 34, 255 ), (0.9/1366)*sX, dxfont_0, "center", "center", false, false, true, true, false) 
  
    if isMouseInPosition ((395/1366)*sX, (430/768)*sY, (160/1366)*sX, (35/768)*sY) then 
        dxDrawRectangle((395/1366)*sX, (430/768)*sY, (160/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 25)) 
    end 
    dxDrawImage( (400/1366)*sX, (433/768)*sY, (25/1366)*sX, (25/768)*sY, "img/map.png", 0, 0, 0 ) 
    dxDrawText ("Mapshop", (487/1366)*sX, (445/768)*sY, x, y, tocolor ( 157, 167, 207, 255 ), 1, dxfont_0, "center", "center", false, false, true, true, false) 
     
    if isMouseInPosition ((395/1366)*sX, (480/768)*sY, (160/1366)*sX, (35/768)*sY) then 
        dxDrawRectangle((395/1366)*sX, (480/768)*sY, (160/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 25)) 
    end 
    dxDrawImage( (400/1366)*sX, (483/768)*sY, (25/1366)*sX, (25/768)*sY, "img/car.png", 0, 0, 0 ) 
    dxDrawText ("Car customization", (487/1366)*sX, (495/768)*sY, x, y, tocolor ( 182, 212, 237, 255 ), (0.75/1366)*sX, dxfont_0, "center", "center", false, false, true, true, false) 
  
    if isMouseInPosition ((395/1366)*sX, (530/768)*sY, (160/1366)*sX, (35/768)*sY) then 
        dxDrawRectangle((395/1366)*sX, (530/768)*sY, (160/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 25)) 
    end 
    dxDrawImage( (400/1366)*sX, (533/768)*sY, (25/1366)*sX, (25/768)*sY, "img/settings.png", 0, 0, 0 ) 
    dxDrawText ("Settings", (487/1366)*sX, (545/768)*sY, x, y, tocolor ( 68, 68, 68, 255 ), 1, dxfont_0, "center", "center", false, false, true, true, false) 
  
    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
     
    showPage("homepage") 
end 
  
function joinPersonalStats (button, state, absoluteX, absoluteY, wx, wy, wz, clickedElement) 
    if state == "down" then 
        if isMouseInPosition ((395/1366)*sX, (280/768)*sY, (160/1366)*sX, (35/768)*sY) then 
            openPage("personalStats") 
        end 
    end 
end 
addEventHandler ("onClientClick", getRootElement(), joinPersonalStats) 
  
bindKey("u", "down", 
function() 
    if visible == true then 
        visible = false 
        removeEventHandler("onClientRender", getRootElement(), drawCore) 
        showCursor(false) 
    else 
        visible = true 
        addEventHandler("onClientRender", getRootElement(), drawCore) 
        showCursor(true) 
    end 
end 
) 
  
function isMouseInPosition (x, y, width, height) 
    if (not isCursorShowing ()) then 
        return false 
    end 
    local sx, sy = guiGetScreenSize () 
    local cx, cy = getCursorPosition () 
    local cx, cy = (cx * sx), (cy*sy) 
    if (cx >= x and cx <= x + width) and (cy >= y and cy <= y + height) then 
        return true 
    else 
        return false 
    end 
end 
  
addEventHandler('onClientPlayerJoin', root, 
    function() 
        outputChatBox('[JOIN] #FFFFFF' .. getPlayerName(source) .. '#FFFFFF has joined the game.', 255, 102, 0,true) 
    end 
) 
  
addEventHandler('onClientPlayerChangeNick', root, 
    function(oldNick, newNick) 
        outputChatBox('[NICK] #FFFFFF' .. oldNick .. ' #FFFFFFis now known as #FFFFFF' .. newNick, 255, 102, 0,true) 
    end 
) 
  
addEventHandler('onClientPlayerQuit', root, 
    function(reason) 
        outputChatBox('[QUIT] #FFFFFF' .. getPlayerName(source) .. ' #FFFFFFhas left the game #FF6600[' .. reason .. '].', 255, 102, 0,true) 
    end 
) 
  
  

--Homepage

  
local sX, sY = guiGetScreenSize() 
local dxfont_0 = dxCreateFont("font/font.ttf", 16) 
local dxfont_1 = dxCreateFont("font/font.ttf", 12) 
  
  
function openHomepage() 
    --  200 = interpolateBetween( 255, 0, 0, 0, 0, 0, 1500, "Linear" ) 
    dxDrawImage( (880/1366)*sX, (160/768)*sY, (25/1366)*sX, (25/768)*sY, "img/home.png", 0, 0, 0, tocolor(255, 255, 255, 255) ) 
    dxDrawText ("Home", (915/1366)*sX, (158/768)*sY, x, y, tocolor ( 255, 102, 0, 255 ), 1, dxfont_0) 
  
    dxDrawImage( (560/1366)*sX, (235/768)*sY, (375/1366)*sX, (115/768)*sY, "img/header.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
    dxDrawEmptyRec((560/1366)*sX, (235/768)*sY, (375/1366)*sX, (115/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
    dxDrawRectangle((560/1366)*sX, (315/768)*sY, (375/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 200), false) 
    dxDrawText ("NEWS: Read our latest news in our website [url=http://www.shc-clan.com]www.shc-clan.com[/url]!, (565/1366)*sX, (320/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
  
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  
    dxDrawEmptyRec((560/1366)*sX, (375/768)*sY, (165/1366)*sX, (175/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
    dxDrawText ("Latest clanwars", (595/1366)*sX, (380/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
    dxDrawText ("SHC 14 - 6 xS//", (595/1366)*sX, (400/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
    dxDrawText ("SHC 15 - 5 eo3//", (595/1366)*sX, (420/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
    dxDrawText ("SHC 13 - 7 iR|", (595/1366)*sX, (440/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
    dxDrawText ("SHC 9 - 11 xN#", (595/1366)*sX, (460/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
    dxDrawText ("SHC 16 - 4 [GoD]", (595/1366)*sX, (480/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
    dxDrawText ("SHC 10 - 11 |6s", (595/1366)*sX, (500/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
    dxDrawText ("Visit our website for more", (570/1366)*sX, (530/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
  
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  
    if isMouseInPosition ((740/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY) then 
        dxDrawRectangle((740/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(150, 150, 150, 75)) 
    end 
    dxDrawEmptyRec((740/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
    dxDrawImage( (760/1366)*sX, (415/768)*sY, (50/1366)*sX, (50/768)*sY, "img/notebook.png", 0, 0, 0, tocolor(255, 255, 255, 255)) 
  
    if isMouseInPosition ((845/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY) then 
        dxDrawRectangle((845/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(150, 150, 150, 75)) 
    end 
    dxDrawEmptyRec((845/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
    dxDrawImage( (865/1366)*sX, (415/768)*sY, (50/1366)*sX, (50/768)*sY, "img/team.png", 0, 0, 0, tocolor(255, 255, 255, 255) ) 
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
  
    dxDrawEmptyRec((740/1366)*sX, (495/768)*sY, (195/1366)*sX, (55/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
    dxDrawText ("www.shc-clan.com", (763/1366)*sX, (510/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (1/1366)*sX, dxfont_0) 
end 
  
function closeHomepage() 
    removeEventHandler("onClientRender", getRootElement(), openHomepage) 
end 
  
function dxDrawEmptyRec(startX, startY, endX, endY, color, width, postGUI) 
    dxDrawLine ( startX, startY, startX+endX, startY, color, width, postGUI ) 
    dxDrawLine ( startX, startY, startX, startY+endY, color, width, postGUI ) 
    dxDrawLine ( startX, startY+endY, startX+endX, startY+endY,  color, width, postGUI ) 
    dxDrawLine ( startX+endX, startY, startX+endX, startY+endY, color, width, postGUI ) 
end 
  

--Personal stats page

  
local sX, sY = guiGetScreenSize() 
local dxfont_0 = dxCreateFont("font/font.ttf", 16) 
local dxfont_1 = dxCreateFont("font/font.ttf", 12) 
  
function openPersonalStats() 
    dxDrawRectangle((560/1366)*sX, (315/768)*sY, (375/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 200), false) 
    dxDrawText ("Personal stats:", (565/1366)*sX, (320/768)*sY, x, y, tocolor ( 255, 255, 255, 200 ), (0.7/1366)*sX, dxfont_0) 
end 
  
function closePersonalStats() 
    removeEventHandler("onClientRender", getRootElement(), openPersonalStats) 
end 
  

And the other file is the one i posted before.

Thanks guys for you help :)

Link to comment

I didn't understand that, but i though you told me to use onClientRender event handler instead of the function name, isn't it right?

By the way, I obtained this error:

ERROR: dashboard\core.lua:71: attempt to call global 'openPage' (a nil value)

Link to comment

To show them =

    function showPage(thePage) 
    if thePage == "homepage" then 
        CloseThePersonStats() 
        OpenTheHomePage() 
    elseif thePage == "personalStats" then 
        CloseTheHomePage() 
        OpenThePersonStats() 
    end 
end 

Personal stats -

    local sX, sY = guiGetScreenSize() 
    local dxfont_0 = dxCreateFont("font/font.ttf", 16) 
    local dxfont_1 = dxCreateFont("font/font.ttf", 12) 
  
    function OpenThePersonStats() 
          if not personOpen then 
            personOpen  = true 
        addEventHandler("onClientRender", getRootElement(), openPersonalStats) 
        end 
    end 
     
    function CloseThePersonStats() 
           personOpen  = false 
        removeEventHandler("onClientRender", getRootElement(), openPersonalStats) 
    end 
     
     
     
      
    function openPersonalStats() 
        dxDrawRectangle((560/1366)*sX, (315/768)*sY, (375/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 200), false) 
        dxDrawText ("Personal stats:", (565/1366)*sX, (320/768)*sY, x, y, tocolor ( 255, 255, 255, 200 ), (0.7/1366)*sX, dxfont_0) 
    end 

Home page -

    local sX, sY = guiGetScreenSize() 
    local dxfont_0 = dxCreateFont("font/font.ttf", 16) 
    local dxfont_1 = dxCreateFont("font/font.ttf", 12) 
      
  
HomeOpen = false 
  
    function OpenTheHomePage() --- OPEN IT 
        if not HomeOpen then 
          HomeOpen = true 
        addEventHandler("onClientRender", getRootElement(), openHomepage) 
         end 
    end 
     
    function CloseTheHomePage() --- CLOSE IT 
        HomeOpen  = false 
        removeEventHandler("onClientRender", getRootElement(), openHomepage) 
    end 
     
    function openHomepage() 
        --  200 = interpolateBetween( 255, 0, 0, 0, 0, 0, 1500, "Linear" ) 
        dxDrawImage( (880/1366)*sX, (160/768)*sY, (25/1366)*sX, (25/768)*sY, "img/home.png", 0, 0, 0, tocolor(255, 255, 255, 255) ) 
        dxDrawText ("Home", (915/1366)*sX, (158/768)*sY, x, y, tocolor ( 255, 102, 0, 255 ), 1, dxfont_0) 
      
        dxDrawImage( (560/1366)*sX, (235/768)*sY, (375/1366)*sX, (115/768)*sY, "img/header.png", 0, 0, 0, tocolor(255, 255, 255, 255), false) 
        dxDrawEmptyRec((560/1366)*sX, (235/768)*sY, (375/1366)*sX, (115/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
        dxDrawRectangle((560/1366)*sX, (315/768)*sY, (375/1366)*sX, (35/768)*sY, tocolor(255, 102, 0, 200), false) 
        dxDrawText ("NEWS: Read our latest news in our website [url=http://www.shc-clan.com!]http://www.shc-clan.com![/url], (565/1366)*sX, (320/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0)) 
      
        ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
      
        dxDrawEmptyRec((560/1366)*sX, (375/768)*sY, (165/1366)*sX, (175/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
        dxDrawText ("Latest clanwars", (595/1366)*sX, (380/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
        dxDrawText ("SHC 14 - 6 xS//", (595/1366)*sX, (400/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
        dxDrawText ("SHC 15 - 5 eo3//", (595/1366)*sX, (420/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
        dxDrawText ("SHC 13 - 7 iR|", (595/1366)*sX, (440/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
        dxDrawText ("SHC 9 - 11 xN#", (595/1366)*sX, (460/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
        dxDrawText ("SHC 16 - 4 [GoD]", (595/1366)*sX, (480/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
        dxDrawText ("SHC 10 - 11 |6s", (595/1366)*sX, (500/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
        dxDrawText ("Visit our website for more", (570/1366)*sX, (530/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (0.7/1366)*sX, dxfont_0) 
      
        ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
      
        if isMouseInPosition ((740/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY) then 
            dxDrawRectangle((740/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(150, 150, 150, 75)) 
        end 
        dxDrawEmptyRec((740/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
        dxDrawImage( (760/1366)*sX, (415/768)*sY, (50/1366)*sX, (50/768)*sY, "img/notebook.png", 0, 0, 0, tocolor(255, 255, 255, 255)) 
      
        if isMouseInPosition ((845/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY) then 
            dxDrawRectangle((845/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(150, 150, 150, 75)) 
        end 
        dxDrawEmptyRec((845/1366)*sX, (375/768)*sY, (90/1366)*sX, (115/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
        dxDrawImage( (865/1366)*sX, (415/768)*sY, (50/1366)*sX, (50/768)*sY, "img/team.png", 0, 0, 0, tocolor(255, 255, 255, 255) ) 
        ---------------------------------------------------------------------------------------------------------------------------------------------------------------- 
      
        dxDrawEmptyRec((740/1366)*sX, (495/768)*sY, (195/1366)*sX, (55/768)*sY, tocolor(255, 102, 0, 200), 1, false) 
        dxDrawText ("[url=http://www.shc-clan.com]http://www.shc-clan.com[/url]", (763/1366)*sX, (510/768)*sY, x, y, tocolor ( 255, 255, 255, 255 ), (1/1366)*sX, dxfont_0) 
    end 
      
      
    function dxDrawEmptyRec(startX, startY, endX, endY, color, width, postGUI) 
        dxDrawLine ( startX, startY, startX+endX, startY, color, width, postGUI ) 
        dxDrawLine ( startX, startY, startX, startY+endY, color, width, postGUI ) 
        dxDrawLine ( startX, startY+endY, startX+endX, startY+endY,  color, width, postGUI ) 
        dxDrawLine ( startX+endX, startY, startX+endX, startY+endY, color, width, postGUI ) 
    end 
  
  
 

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