Andrew75t Posted August 22, 2020 Share Posted August 22, 2020 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
aka Blue Posted August 22, 2020 Share Posted August 22, 2020 https://wiki.multitheftauto.com/wiki/OnClientGUIClick Link to comment
Andrew75t Posted August 22, 2020 Author Share Posted August 22, 2020 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
Yaaruu Posted August 22, 2020 Share Posted August 22, 2020 54 minutes ago, Andrew75t said: local function BuyPistol() triggerServerEvent("Pistol",getLocalPlayer()) end I think you should change it to this : local function BuyPistol() triggerServerEvent("Pistol",resourceRoot,getLocalPlayer()) end Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now