Jump to content

help please


Karem197

Recommended Posts

help please
How do I make the dx button when you press it deduct money and give you a random code or random text according to what I want?

function walker()
  dxDrawRectangle(124, 109, 1094, 584, tocolor(0, 0, 0, 69), true)
  dxDrawImage(837, 241, 381, 452, "images/examples/1.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
  dxDrawImage(822, 99, 396, 599, "images/examples/5.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
  dxDrawImage(183, 411, 629, 266, "images/examples/3.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
  dxDrawImage(185, 115, 627, 328, "images/examples/4.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
  dxDrawImage(403, 119, 206, 46, "images/examples/6.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
  dxDrawImage(231, 619, 123, 40, "images/examples/2.png", 0, 0, 0, tocolor(255, 255, 255, 255), true)
  dxDrawRectangle(232, 623, 122, 32, tocolor(0, 0, 0, 39), true)
  button = guiCreateButton(232, 623, 122, 32, "button", false) 
  guiSetAlpha(button, 0) 
  dxDrawRectangle( 232, 623, 122, 32, tocolor(0, 0, 0, 39), true)
end

 

Link to comment

Hello Karem197,

you seem to use CEGUI as a button instead of DX. For that reason I will not go into details about DX GUI creation. If you want to learn more about creating your own GUI systems then read about UI layouts, layout engines and UI design.

To handle clicks you should use the onClientGUIClick event using the button variable as base element and propagate = false, like this...

    ...
    dxDrawRectangle(232, 623, 122, 32, tocolor(0, 0, 0, 39), true)
    local button = guiCreateButton(232, 623, 122, 32, "button", false) 
    addEventHandler("onClientGUIClick", button,
        function()
            outputChatBox("clicked the button");
            -- TODO: add or remove money from the local player.
        end, false
    )
    guiSetAlpha(button, 0) 
    dxDrawRectangle( 232, 623, 122, 32, tocolor(0, 0, 0, 39), true)
end

In order to to handle the player money you should tell the server about it using event handling. You can generate a random number by using the Lua math.random function. This way you can create an integer in the range of [m,n) where m and n are parameters to math.random.

To generate a random text you can sequentially generate random integers in the inclusive range of [48,57] or [65,90] or [97,122] and calculate the ASCII character using the string.char function and concatenate the ASCII characters. This way you get a (pseudo) randomly generated string. It is best to ask the server for random strings because you could implement the use of a better RNG than Luas on it.

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