Jump to content

Give the weapon by pressing the button


Andrew75t

Recommended Posts

Hello all. I made a dialog box and made a "BUY WEAPON" button in it. But I don’t know how to buy a weapon when the button is pressed

-- WEAPON WHOP GUI--
local window_weapon_shop = guiCreateWindow(0.225, 0.225, 0.60, 0.60, "Weapon Shop", true) 
guiWindowSetSizable(window_weapon_shop, false) 
guiSetVisible(window_weapon_shop,false) 
-- buttons --
local button_weapon_shop_PISTOL = guiCreateButton(0.040, 0.355, 0.20, 0.060, "450$ BUY GUN", true, window_weapon_shop) 
-- CLOSE WINDOW--
local button_weapon_shop_close = guiCreateButton(0.37, 0.875, 0.25, 0.075, "Close window", true, window_weapon_shop)
  
addEvent("showGUI",true) 
addEventHandler("showGUI",getRootElement(), 
function () 
    if ( guiGetVisible(window_weapon_shop) == false ) then 
    guiSetVisible(window_weapon_shop,true) 
    showCursor(true) 
    end 
end) 

local function click()
	guiSetVisible(window_weapon_shop, false)
	showCursor(false, false)
end
addEventHandler("onClientGUIClick", button_weapon_shop_close, click, false)

 

Link to comment

Thank you.Everything works for me, but I think there are errors in the code. What do you advise?

I read the wiki, looked at examples and this is what came out for me:

Client:

local function BuyPistol()
	triggerServerEvent("Pistol",getLocalPlayer()) 
end
addEventHandler("onClientGUIClick", button_weapon_shop_PISTOL, BuyPistol, false)

Server: 

addEvent("Pistol", true)
addEventHandler("Pistol",root,
function()
local PlayerMoney = getPlayerMoney(source)
 if ( PlayerMoney >= 2000) then
    takePlayerMoney(source,2000)
    giveWeapon ( source ,  22, 30, true )
    outputChatBox ( "#00FF00* [ "..getPlayerName(source) .." #00FF00] Has Bought Pistol ", source, 255, 0, 0, true )
else
    outputChatBox("need more money.", source, 255, 0, 0, true )
end
end)

 

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