DynamicBan Posted September 5, 2014 Share Posted September 5, 2014 I made a shop panel which can be used while playing a game mode like DM, tdm ect. (this is just a part of the script, everything else works fine ) Client function buyWindowFunctions ( ) if ( source == closeButton ) then guiSetVisible ( buyWindow, false ) showCursor ( false,false ) elseif ( source == buyButton ) then triggerServerEvent ("giveWeapon", localPlayer, 30, 30 ) end end addEventHandler ("onClientGUIClick", root, buyWindowFunctions ) Whenever I press "buy" it gives me an AK-47 with 30 bullets. I made a gridlist with a few weapons. I want to make it so that it does give me the item I press on the gridlist. But I have no idea how or what function/event is needed to make it work like that. elseif ( source == buyButton ) then triggerServerEvent ("giveWeaponToPlayer", localPlayer, 30, 30 ) I do know that this is wrong and whenever I press the buy button it would give me an AK with 30 bullets. Instead of first clicking the item on the gridlist and than pressing buy. I would like to know how to make it so when I press an item on the gridlist and than the buybutton it would give me the item I selected on the gridlist. Server addEvent ("giveWeapon", true ) addEventHandler ("giveWeapon", root, function ( weapon, ammo ) if weapon then giveWeapon ( client, tonumber ( weapon ), ( tonumber ( ammo ) ), true ) end end ) Link to comment
Anubhav Posted September 5, 2014 Share Posted September 5, 2014 onClientGUIClick on gridlist would work? Link to comment
DynamicBan Posted September 5, 2014 Author Share Posted September 5, 2014 here is the full client script Weapons = { "Shotgun", "Sawn-Off", "SPAZ-12" } Price = { "$2400", "$4800", "$6600" } function createWindow ( ) local sWidth, sHeight = guiGetScreenSize ( ) local Width, Height = 400, 325 local X = (sWidth/2) - (Width/2) local Y = (sHeight/2) - (Height/2) buyWindow = guiCreateWindow ( X, Y, Width, Height, "Shop", false ) buyButton = guiCreateButton ( 0, 275, 175, 100, "Buy", false, buyWindow ) buyButton1 = guiCreateButton ( 215, 275, 175, 100, "Close", false, buyWindow ) buyGridlist = guiCreateGridList ( 0, 20, 575, 250, false, buyWindow ) guiGridListAddColumn ( buyGridlist, "Weapons", 0.5 ) guiGridListAddColumn ( buyGridlist, "Price", 0.45 ) for key, itemName in pairs ( Weapons ) do local row = guiGridListAddRow ( buyGridlist ) guiGridListSetItemText ( buyGridlist, row, 1, itemName, false, false ) end row = 0 for key, itemName in pairs ( Price ) do guiGridListSetItemText ( buyGridlist, row, 2, itemName, false, false ) row = row + 1 guiSetVisible ( buyWindow, false ) end end addEventHandler ( "onClientResourceStart", getResourceRootElement (), createWindow ) function buttonClicks ( button, state ) if button == "left" and state == "up" then if getElementType ( source ) == "gui-button" then triggerEvent ("onWindowButtonClicked", source, getElementData ( buyWindow, "itemID" ) ) end end end addEventHandler ( "onClientGUIClick", getRootElement ( ), buttonClicks, true ) addCommandHandler ("shop", function () guiSetVisible ( buyWindow, true ) showCursor ( true,true ) end) function buyWindowFunctions ( ) if ( source == buyButton1 ) then guiSetVisible ( buyWindow, false ) showCursor ( false,false ) elseif ( source == buyButton ) then triggerServerEvent ("giveWeaponToPlayer", localPlayer, 30, 30 ) triggerServerEvent ("takePlayerMoney", localPlayer, 2400 ) end end addEventHandler ("onClientGUIClick", root, buyWindowFunctions ) Link to comment
Ab-47 Posted September 5, 2014 Share Posted September 5, 2014 Use; onClientGUIClick and guiGridListGetSelectedItem Link to comment
DynamicBan Posted September 5, 2014 Author Share Posted September 5, 2014 Thanks Ab, it works now 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