Jump to content

dx drawing functions


MAB

Recommended Posts

now i made this dx gui..how to toggle that gui with /skills command? and make sure that it appears only on the player how commanded only and disappear from the person who commanded screen only?

local sx,sy = guiGetScreenSize () 
local x,y = (sx/1280),(sy/768) 
  
function skills () 
dxDrawRectangle(x*381, y*196, x*521, y*373, tocolor(0, 0, 0, 100), false) 
end 
addEventHandler("onClientRender",root,skills) 
  
function page1 () 
dxDrawText("Weapon Skills", x*528, y*198, x*761, y*223, tocolor(255, 255, 255, 255), x*1.00, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Colt-45", x*391, y*265, x*481, y*283, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Desert-Eagle", x*390, y*325, x*541, y*344, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Swan-Off", x*391, y*385, x*497, y*403, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Shotgun", x*391, y*445, x*492, y*463, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Spaz-12", x*391, y*505, x*497, y*523, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawLine(x*743, y*264, x*743, y*283, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*264, x*743, y*264, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*283, x*860, y*283, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*283, x*860, y*264, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*265, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*324, x*743, y*343, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*324, x*743, y*324, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*343, x*860, y*343, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*343, x*860, y*324, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*325, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*384, x*743, y*403, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*384, x*743, y*384, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*403, x*860, y*403, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*403, x*860, y*384, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*385, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*444, x*743, y*463, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*444, x*743, y*444, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*463, x*860, y*463, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*463, x*860, y*444, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*445, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*504, x*743, y*523, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*504, x*743, y*504, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*523, x*860, y*523, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*523, x*860, y*504, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*505, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawText("Next", x*825, y*547, x*880, y*566, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
end 
addEventHandler("onClientRender",root,page1) 

Link to comment

You can use isEventHandlerAdded or a simple variable;

local sx,sy = guiGetScreenSize () 
local x,y = (sx/1280),(sy/768) 
local rendering = false         -- variable that will say if we're rendering or not  
  
function toggle ( ) 
    _G[ rendering and "removeEventHandler" or "addEventHandler" ] ( "onClientRender", root, skills ) 
    _G[ rendering and "removeEventHandler" or "addEventHandler" ] ( "onClientRender", root, page1 ) 
    --[[ 
        this (↑) is a simplification of 
         
        if rendering then 
            removeEventHandler ( "onClientRender", root, skills ); 
            removeEventHandler ( "onClientRender", root, page1 ); 
        else 
            addEventHandler ( "onClientRender", root, skills ); 
            addEventHandler ( "onClientRender", root, page1 ); 
        end 
    --]] 
    rendering = not rendering 
end 
addCommandHandler ( "skills", toggle ) 
  
function skills () 
dxDrawRectangle(x*381, y*196, x*521, y*373, tocolor(0, 0, 0, 100), false) 
end 
  
function page1 () 
    dxDrawText("Weapon Skills", x*528, y*198, x*761, y*223, tocolor(255, 255, 255, 255), x*1.00, "bankgothic", "left", "top", false, false, false, false, false) 
    dxDrawText("Colt-45", x*391, y*265, x*481, y*283, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
    dxDrawText("Desert-Eagle", x*390, y*325, x*541, y*344, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
    dxDrawText("Swan-Off", x*391, y*385, x*497, y*403, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
    dxDrawText("Shotgun", x*391, y*445, x*492, y*463, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
    dxDrawText("Spaz-12", x*391, y*505, x*497, y*523, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
    dxDrawLine(x*743, y*264, x*743, y*283, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*264, x*743, y*264, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*743, y*283, x*860, y*283, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*283, x*860, y*264, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawRectangle(x*744, y*265, x*116, y*18, tocolor(0, 0, 0, 100), false) 
    dxDrawLine(x*743, y*324, x*743, y*343, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*324, x*743, y*324, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*743, y*343, x*860, y*343, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*343, x*860, y*324, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawRectangle(x*744, y*325, x*116, y*18, tocolor(0, 0, 0, 100), false) 
    dxDrawLine(x*743, y*384, x*743, y*403, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*384, x*743, y*384, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*743, y*403, x*860, y*403, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*403, x*860, y*384, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawRectangle(x*744, y*385, x*116, y*18, tocolor(0, 0, 0, 100), false) 
    dxDrawLine(x*743, y*444, x*743, y*463, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*444, x*743, y*444, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*743, y*463, x*860, y*463, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*463, x*860, y*444, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawRectangle(x*744, y*445, x*116, y*18, tocolor(0, 0, 0, 100), false) 
    dxDrawLine(x*743, y*504, x*743, y*523, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*504, x*743, y*504, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*743, y*523, x*860, y*523, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawLine(x*860, y*523, x*860, y*504, tocolor(0, 0, 0, 255), x*1, false) 
    dxDrawRectangle(x*744, y*505, x*116, y*18, tocolor(0, 0, 0, 100), false) 
    dxDrawText("Next", x*825, y*547, x*880, y*566, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
end 

Link to comment

Better way

local sx,sy = guiGetScreenSize () 
local x,y = (sx/1280),(sy/768) 
lp = getLocalPlayer()  
  
  
function skills () 
if getElementData(lp,"skillsDX") == true then 
dxDrawRectangle(x*381, y*196, x*521, y*373, tocolor(0, 0, 0, 100), false) 
end 
end 
addEventHandler("onClientRender",root,skills) 
  
function page1 () 
if getElementData(lp,"skillsDX") == true then 
dxDrawText("Weapon Skills", x*528, y*198, x*761, y*223, tocolor(255, 255, 255, 255), x*1.00, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Colt-45", x*391, y*265, x*481, y*283, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Desert-Eagle", x*390, y*325, x*541, y*344, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Swan-Off", x*391, y*385, x*497, y*403, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Shotgun", x*391, y*445, x*492, y*463, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawText("Spaz-12", x*391, y*505, x*497, y*523, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
dxDrawLine(x*743, y*264, x*743, y*283, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*264, x*743, y*264, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*283, x*860, y*283, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*283, x*860, y*264, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*265, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*324, x*743, y*343, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*324, x*743, y*324, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*343, x*860, y*343, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*343, x*860, y*324, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*325, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*384, x*743, y*403, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*384, x*743, y*384, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*403, x*860, y*403, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*403, x*860, y*384, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*385, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*444, x*743, y*463, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*444, x*743, y*444, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*463, x*860, y*463, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*463, x*860, y*444, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*445, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawLine(x*743, y*504, x*743, y*523, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*504, x*743, y*504, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*743, y*523, x*860, y*523, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawLine(x*860, y*523, x*860, y*504, tocolor(0, 0, 0, 255), x*1, false) 
dxDrawRectangle(x*744, y*505, x*116, y*18, tocolor(0, 0, 0, 100), false) 
dxDrawText("Next", x*825, y*547, x*880, y*566, tocolor(255, 255, 255, 255), x*0.70, "bankgothic", "left", "top", false, false, false, false, false) 
end 
end 
addEventHandler("onClientRender",root,page1) 
  
  
function close() 
if not getElementData(lp,"skillsDX") == true then 
setElementData(lp,"skillsDX",true) 
else 
setElementData(lp,"skillsDX",false) 
end 
end 
addCommandHandler("skills",close) 
  
  
  
  
  

now open and close with /skills

Link to comment
Better way

it's not a "better way", you are generating traffic (which isn't necessary).

As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. [...]

--

what does _G mean? and ; ??

_G is a predefined variable which contains all the functions (and global variables) defined in the script (and the defaults too)

you can test it if you want...

for k, v in pairs ( _G ) do 
   print ( k, v ) 
end 

the semicolons don't change anything in the script (in some other programming languages it's mandatory to end an instruction).

i tried the function that u r talking about but it didn't work..

about isEventHandlerAdded, you have to define it in the script:

function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) 
    if  
        type( sEventName ) == 'string' and  
        isElement( pElementAttachedTo ) and  
        type( func ) == 'function'  
    then 
        local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) 
        if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then 
            for i, v in ipairs( aAttachedFunctions ) do 
                if v == func then 
                    return true 
                end 
            end 
        end 
    end 
  
    return false 
end 

hope u understand :roll:

Link to comment
Better way

it's not a "better way", you are generating traffic (which isn't necessary).

As element data is synced to all clients, it can generate a lot of network traffic and consume server CPU. [...]

--

what does _G mean? and ; ??

_G is a predefined variable which contains all the functions (and global variables) defined in the script (and the defaults too)

you can test it if you want...

for k, v in pairs ( _G ) do 
   print ( k, v ) 
end 

the semicolons don't change anything in the script (in some other programming languages it's mandatory to end an instruction).

i tried the function that u r talking about but it didn't work..

about isEventHandlerAdded, you have to define it in the script:

function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) 
    if  
        type( sEventName ) == 'string' and  
        isElement( pElementAttachedTo ) and  
        type( func ) == 'function'  
    then 
        local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) 
        if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then 
            for i, v in ipairs( aAttachedFunctions ) do 
                if v == func then 
                    return true 
                end 
            end 
        end 
    end 
  
    return false 
end 

hope u understand :roll:

i know it and that is the one i am saying that i have tried

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