Jump to content

Interactive dX Elements


Forrest

Recommended Posts

Posted

I've been contemplating learning how to script interactive dX GUI's for a while due to the better customization than the original MTA GUI's.

I found a small snippet floating around on the forum and decided to check it out, however the mathematic equation to check whether the cursor is within the rectangle has slightly confused me, if someone could help, that would be great.

local sX, sY = guiGetScreenSize() 
dxDrawRectangle(sX/4, sY/4, sX/8, sY/8, tocolor(0,255,0,255), false) 
  
local checkX = ( x > sX/4 and x < 2*sX/4-sX/8 ) 
local checkY = ( y > sY/4 and y < 2*sY/4-sY/8 ) 

The checkX and checkY math equations are what I'm having trouble with, if someone could explain how it works that would be great, thanks.

Posted

Try:

  
local checkX = ( x > sX/4 and x < sX/4+sX/8 ) 
local checkY = ( y > sY/4 and y < sY/4+sY/8 ) 
  

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
  • MTA Team
Posted

You are not posting the full script, anyway, what it is doing there is checking with "onClientClick" this variables:

string button, string state, int absoluteX, int absoluteY, float worldX, float worldY, float worldZ, element clickedWorld 

The X and Y positions in your script refer to the absoluteX and absoluteY positions in the event variables.

Example this would be the same thing but, with the onClientClick Variables.:

  
local sX, sY = guiGetScreenSize() 
addEventHandler ( "onClientClick", getRootElement(), 
function (button,state,absoluteX,absoluteY) 
local checkX = ( absoluteX > sX/4 and absoluteX < 2*sX/4-sX/8 ) 
local checkY = ( absoluteY > sY/4 and absoluteY < 2*sY/4-sY/8 ) 
end) 
function draw() 
dxDrawRectangle(sX/4, sY/4, sX/8, sY/8, tocolor(0,255,0,255), false) 
end 
addEventHandler ( "onClientRender", getRootElement(), draw ) 

So what it actually does, is that when you click on somewhere in the screen, the event handler triggers a function that checks the position of that click and resolves if you are actually clicking the dxRectangle or not.

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
Posted

If you're like me, and hate math. You could simply make use of a similar workaround as I do.

I simply create a regular GUI with the same shape as my DX Drawings, then set its alpha to 0. That way I can manipulate my DX Drawings using the already available GUI Functions/Events. :)

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

  • MTA Team
Posted
If you're like me, and hate math. You could simply make use of a similar workaround as I do.

I simply create a regular GUI with the same shape as my DX Drawings, then set its alpha to 0. That way I can manipulate my DX Drawings using the already available GUI Functions/Events. :)

+1 :D

@Forrest:

  
local checkX = ( absoluteX > sX/4 and absoluteX < 2*sX/4-sX/8 ) 
local checkY = ( absoluteY > sY/4 and absoluteY < 2*sY/4-sY/8 ) 

The sX/4 and sX/8 and sY/4 and sY/8 are the position and boundaries of the dxRectangle. So that's why you use it in your check function.What you do, is remove the position used to create the dxRectangle.

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 
  • MTA Team
Posted
Thanks for the help lads, just got in and booted up my dev server and gave it a shot, worked it all out etc. :)

Your welcome.

DevOps Engineer, Cloud Advocate & Security Engineer(Red Team) | Coffee, Containers & Burp

 

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