Jump to content

Advertisment Gui


PrivateKiller

Recommended Posts

Posted

Hello! I have a problem. I don't know how to merge this, to make it work. I'm using it in serverside. Please help me

function Advertisment(thePlayer, commandName, ...) 
        local players = getElementsByType("player") 
        local playerName = getPlayerName ( thePlayer ) 
        local chatContent = {...} 
        for index, player in ipairs ( players ) do 
            outputChatBox( "Advertisment from " .. playerName.. ": " ..table.concat ( chatContent, " "), player, 0, 190, 40) 
        end 
    end 
addCommandHandler( "ad", Advertisment ) 
  
  
GUIEditor = { 
    button = {}, 
    window = {}, 
    memo = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(455, 192, 343, 133, "Advert cost 500€. Click button below to buy it!", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetAlpha(GUIEditor.window[1], 1.00) 
  
        GUIEditor.memo[1] = guiCreateMemo(20, 38, 304, 58, "", false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(65, 102, 219, 21, "Buy Advert!", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.button[1], "default-bold-small")     
    end 
) 
  

Posted
I'm using it in serverside. Please help me

GUI is clientside.

Serverside:

function Advertisment(thePlayer, commandName, ...) 
        local players = getElementsByType("player") 
        local playerName = getPlayerName ( thePlayer ) 
        local chatContent = {...} 
        for index, player in ipairs ( players ) do 
            outputChatBox( "Advertisment from " .. playerName.. ": " ..table.concat ( chatContent, " "), player, 0, 190, 40) 
        end 
    end 
addCommandHandler( "ad", Advertisment ) 
  

Client:

GUIEditor = { 
    button = {}, 
    window = {}, 
    memo = {} 
} 
addEventHandler("onClientResourceStart", resourceRoot, 
    function() 
        GUIEditor.window[1] = guiCreateWindow(455, 192, 343, 133, "Advert cost 500€. Click button below to buy it!", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetAlpha(GUIEditor.window[1], 1.00) 
  
        GUIEditor.memo[1] = guiCreateMemo(20, 38, 304, 58, "", false, GUIEditor.window[1]) 
        GUIEditor.button[1] = guiCreateButton(65, 102, 219, 21, "Buy Advert!", false, GUIEditor.window[1]) 
        guiSetFont(GUIEditor.button[1], "default-bold-small")     
    end 
) 
  

What now? Help me please

  • Moderators
Posted

Study triggerClientEvent, which is about communication between serverside to clientside.

https://wiki.multitheftauto.com/wiki/TriggerClientEvent

Watch the examples with care.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

I watched some turtorials, and that's all what I did, but gui still won't open. Help please?

Client=

GUIEditor = { 
    button = {}, 
    window = {}, 
    memo = {} 
} 
  
function initGUI( ) 
 btnOutput = guiCreateButton(65, 102, 219, 21, "Buy Advert!", true) 
 addEventHandler ("inClientGUIClick", btnOutput, outputEditBox, false ) 
editBox=guiCreateEdit(20, 38, 304, 58, "Type your advert here", true) 
guiEditSetMaxLength ( editBox, 30 ) 
end 
  
 addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource()),initGUI ) 
  
function outputEditBox ( button ) 
  if button = "left" then 
    local text = guiGetText ( editBox ) 
    outputChatBox ( text )  
  end 
end 
  
 function() 
        GUIEditor.window[1] = guiCreateWindow(455, 192, 343, 133, "Advert cost 500. Click button below to buy it!", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetAlpha(GUIEditor.window[1], 1.00) 
  
        GUIEditor.memo[1] = guiCreateMemo(20, 38, 304, 58, "", false, GUIEditor.window[1]) 
        btnOutput = guiCreateButton(65, 102, 219, 21, "Buy Advert!", true) 
        guiSetFont(GUIEditor.button[1], "default-bold-small")     
    end 
) 
  

Serverside=

function Advertisment(thePlayer, commandName, ...) 
        local players = getElementsByType("player") 
        local playerName = getPlayerName ( thePlayer ) 
        local chatContent = {...} 
        for index, player in ipairs ( players ) do 
            outputChatBox( "Advertisment from " .. playerName.. ": " ..table.concat ( chatContent, " "), player, 0, 190, 40) 
        end 
    end 
addCommandHandler( "ad", Advertisment ) 
  

Posted

"inClientGUIClick" such event does not exist.

And you have a function to create GUI code without a event handler.

Why do you even have two set of GUI code anyway?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
"inClientGUIClick" such event does not exist.

And you have a function to create GUI code without a event handler.

Why do you even have two set of GUI code anyway?

How can I make it work then?

Posted
"inClientGUIClick" such event does not exist.

I don't get it... Seems that will not happen anything with my wish to learn scripting... :cry: I thought that someone will give me an example how to do it, or something like that...

Posted

Take a look at the difference between the codes (test my code and check if that is what you wanted, if it is then go to wiki and read about the functions).

Your client side:

GUIEditor = { 
    button = {}, 
    window = {}, 
    memo = {} 
} 
  
function initGUI( ) 
 btnOutput = guiCreateButton(65, 102, 219, 21, "Buy Advert!", true) 
 addEventHandler ("inClientGUIClick", btnOutput, outputEditBox, false ) 
editBox=guiCreateEdit(20, 38, 304, 58, "Type your advert here", true) 
guiEditSetMaxLength ( editBox, 30 ) 
end 
  
 addEventHandler("onClientResourceStart", getResourceRootElement( getThisResource()),initGUI ) 
  
function outputEditBox ( button ) 
  if button = "left" then 
    local text = guiGetText ( editBox ) 
    outputChatBox ( text ) 
  end 
end 
  
 function() 
        GUIEditor.window[1] = guiCreateWindow(455, 192, 343, 133, "Advert cost 500. Click button below to buy it!", false) 
        guiWindowSetSizable(GUIEditor.window[1], false) 
        guiSetAlpha(GUIEditor.window[1], 1.00) 
  
        GUIEditor.memo[1] = guiCreateMemo(20, 38, 304, 58, "", false, GUIEditor.window[1]) 
        btnOutput = guiCreateButton(65, 102, 219, 21, "Buy Advert!", true) 
        guiSetFont(GUIEditor.button[1], "default-bold-small")     
    end 
) 

Your server side:

function Advertisment(thePlayer, commandName, ...) 
        local players = getElementsByType("player") 
        local playerName = getPlayerName ( thePlayer ) 
        local chatContent = {...} 
        for index, player in ipairs ( players ) do 
            outputChatBox( "Advertisment from " .. playerName.. ": " ..table.concat ( chatContent, " "), player, 0, 190, 40) 
        end 
    end 
addCommandHandler( "ad", Advertisment ) 

My client side:

function GUI() 
    Window = guiCreateWindow(455, 192, 343, 133, "Advert costs 500. Click the button below to buy it!", false) 
    guiWindowSetSizable(Window, false) 
    guiSetAlpha(Window, 1.00) 
  
    Memo = guiCreateMemo(20, 38, 304, 58, "", false, Window) 
    Button = guiCreateButton(65, 102, 219, 21, "Buy Advert!", false, Window) 
    guiSetFont(Button, "default-bold-small")     
    showCursor(true) 
    addEventHandler("onClientGUIClick",Button,buttonClick,false) 
end 
addCommandHandler("ad",GUI) 
  
function buttonClick() 
    if getPlayerMoney(localPlayer) >= 500 then 
    local memoText = guiGetText(Memo) 
    triggerServerEvent("AD",localPlayer,localPlayer,memoText) 
    guiSetVisible(Window,false) 
    showCursor(false) 
    else 
    outputChatBox("#0000FF[AD]#00FF00 You need more money.",0,255,0,true) 
    end 
end 

My server side:

addEvent("AD",true) 
addEventHandler("AD",getRootElement(), 
function (p,text) 
        setPlayerMoney(p,getPlayerMoney(p)-500) 
        outputChatBox("#0000FF[AD] #FFFFFF"..getPlayerName(p)..": #00FF00"..text,root,0,255,0,true) 
    end 
) 

Looking for tutorials or information? check out: www.simpleask.co.uk

Posted
Hell no! God still loves me! Hihi, thanks manve1. I was looking for that ye...

No problem, but study what i have changed and what I've kept.

Of course! I'm reading mta wiki all day and study how to use some mail functions (most used)...

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