Joaovit13 Posted February 1, 2021 Posted February 1, 2021 (edited) Bom estou fazendo um painel usando dxDrawRectangle fiz um botão como eu posso usar o isMouseInPosition nele? Edited February 1, 2021 by Joaovit13
Other Languages Moderators androksi Posted February 1, 2021 Other Languages Moderators Posted February 1, 2021 (edited) E aí novamente. Presumindo que você tenha "criado um botão", funções DX não são tratadas da mesma forma que GUI. Em DX, você deve usar o evento onClientClick, onde ele recebe alguns parâmetros, sendo os dois primeiros o lado do botão que foi clicado (left, right; esquerda, direita) e o estado, que eu recomendo a você usar o up, em cliques casuais. Aqui um exemplo de uso: Spoiler local screenX, screenY = guiGetScreenSize() local isShowing = true function renderStuff() dxDrawRectangle(screenX - 120, screenY - 400, 120, 20, tocolor(35, 140, 95, 220), false) end -- Adiciona o evento para renderizar addEventHandler("onClientRender", root, renderStuff) -- Função onde ficará os clicks function clicks(button, state) if isShowing then -- Verifica se o painel está sendo mostrado e/ou ativo na tela do jogador, a variável está lá em cima if button == "left" and state == "up" then -- Verifica se o jogador clicou com o botão esquerdo e se ele fez o click completo (apertou, soltou) if isMouseInPosition(screenX - 120, screenY - 400, 120, 20) then --[[ Os parâmetros da função isMouseInPosition devem ser a posição do DX em questão caso contrário, os clicks irão serem detectados de forma incorreta veja a posição do dxDrawRectangle lá em cima ]] outputChatBox("Você clicou!", 0, 255, 0) end end end end -- Adiciona o evento dos clicks addEventHandler("onClientClick", root, clicks) -- isMouseInPosition 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 ) return ( ( cx >= x and cx <= x + width ) and ( cy >= y and cy <= y + height ) ) end Off-topic: evite criar mais um tópico sobre o mesmo assunto, você poderia ter usado este tópico para comentar a sua dúvida. Edited February 1, 2021 by andreisrw 1
Joaovit13 Posted February 1, 2021 Author Posted February 1, 2021 (edited) Assim é que como eu demorei pra falar minha dúvida pensei que ele já estava inválido e tinha que criar outro mals, mais muito obrigado. É eu estou utilizando esse sistema porém quando eu clico fora do do painel com ele fechado ele funciona -- Posição dos Dx dxDrawRectangle(screenW * 0.3133, screenH * 0.5768, screenW * 0.0836, screenH * 0.0794, tocolor(10, 2, 84, 254), false) dxDrawRectangle(screenW * 0.3133, screenH * 0.4089, screenW * 0.0836, screenH * 0.0794, tocolor(10, 2, 84, 254), false) -- Função de Clicar function clicar(button, state) if isShowing then if button == "left" and state == "up" then if isMouseInPosition(screenW * 0.3133, screenH * 0.4102, screenW * 0.3969, screenH * 0.4883) then outputChatBox("1",255,255,255,true) else isMouseInPosition(screenW * 0.3133, screenH * 0.5768, screenW * 0.3969, screenH * 0.6549) then outputChatBox("2",255,255,255,true) end end end end addEventHandler("onClientClick", root, clicar) Ele só ta aparecendo o 1 e com o painel fechado está dando para executar ele como consigo corrigir isso? Ah e fora que eu quero executar os 2, caso eu clicar no 1 digite o texto caso eu clique no 2 digite o texto 2. Edited February 1, 2021 by Joaovit13
Cr0wLey Posted February 2, 2021 Posted February 2, 2021 (edited) Você tem que colocar se o painel está true ou false exemplo: if painel == true then if isMouseInPosition(screenW * 0.3133, screenH * 0.4102, screenW * 0.3969, screenH * 0.4883) then com isso só vai poder clicar quando o painel estiver true. No caso quando estiver aberto. Edited February 2, 2021 by Cr0wLey 2
Joaovit13 Posted February 2, 2021 Author Posted February 2, 2021 Qual função eu utilizo para fechar o painel depois de aberto? testei o destroyElement só que ele fala que o primeiro argumento é nil
Joaovit13 Posted February 2, 2021 Author Posted February 2, 2021 if painel == true then removeEventHandler("onClientRender", root, abrirPainel) painel = false showCursor(false) Resolvido!
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