Jump to content

[HELP] onClientClick with two buttons?


NeVada

Recommended Posts

Hey guys, I have some problem with my panel.

So, first of all, I did a small panel with two buttons. I can close the panel, but I don't know how to make a next page. 

How could I make a next page? Should I disappear the first page, and then create another one?

Here's my code:

local thePlayer = getLocalPlayer()
local x, y = guiGetScreenSize(thePlayer)
local pS = [[randomtext]]
-------------------------------------------------------------------------------------------
function drawInformation()
  dxDrawRectangle(x/3, y/3, 500, 450, tocolor(0, 0, 0, 125))
  dxDrawRectangle(x/3, y/3, 500, 20, tocolor(0, 0, 0, 125))
  dxDrawRectangle(x/2.8, y/1.4, 100, 30, tocolor(0, 0, 0, 125))
  dxDrawRectangle(x/1.6, y/1.4, 100, 30, tocolor(0, 0, 0, 125))

  dxDrawText("Welcome to the help panel!", x/2.3, y/2.8, tocolor(75, 108, 213, 115))
  dxDrawText(pS, x/2.8, y/2.6)
  dxDrawText("Close", x/2.6, y/1.39, tocolor(75, 108, 213, 125))
  dxDrawText("Next", x/1.54, y/1.39, tocolor(75, 108, 213, 125))
end
-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------
function showThings()
  addEventHandler("onClientRender", root, drawThings)
  addEventHandler("onClientClick", getRootElement(), onClickThing)
  showCursor(true)
  outputChatBox("t")
end
addCommandHandler("test", showThings)

function disappearThings()
  removeEventHandler("onClientRender", root, drawThings)
  removeEventHandler("onClientClick", getRootElement(), onClickThing)
  showCursor(false)
  outputChatBox("t.")
end
---------------------------------------------------------------------------------------------
function onClickThing(button, state, absoluteX, absoluteY, worldX, worldZ, clickedElement)
  if (state == "down") then
    if (absoluteX >= x/2.8) and (absoluteX <= x/2.8 + 100) and (absoluteY >= y/1.4) and (absoluteY <= y/1.4 + 100) then
      disappearThings()
    end
  end
end

 

Edited by NeVada
t
Link to comment

I've finally made it! And it wasn't so hard haha. Maybe it's a bit amateurish.

function drawNextPage()
  dxDrawRectangle(x/3, y/3, 500, 450, tocolor(0, 0, 0, 125))
  dxDrawRectangle(x/3, y/3, 500, 20, tocolor(0, 0, 0, 125))
end

function showFirst()
  addEventHandler("onClientRender", root, drawNextPage)
  addEventHandler("onClientClick", getRootElement(), onClickNext)
  showCursor(true)
end

function onClickNext(button, state, absoluteX, absoluteY, worldX, worldZ, clickedElement)
  if (state == "down") then
    if (absoluteX >= x/1.6) and (absoluteX <= x/1.6 + 100) and (absoluteY >= y/1.4) and (absoluteY <= y/1.4 + 100) then
      disappearThings()
      showFirst()
    end
  end
end

 

  • Like 1
Link to comment
  • Discord Moderators

use a function instead, because u'll use it a lot in the future.
and, if i would be u, i would use a variable like:

local currentPanelName = "information"

And, then under render I would use an if statement, like:

if (currentPanelName=="information") then
  --// Ur code here
elseif (currentPanelName=="panel2") then
  --// Ur code here
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...