Vaux42 Posted February 28, 2012 Share Posted February 28, 2012 Hi, at the moment i'm scripting a new gamemode, and a component involves a GUI that lets you purchase weapons, items and vehicles. If i scripted it normally with IF statements, the script would have to go through all weapons, items and vehicles to find the button you clicked. As a result, i'm trying to limit its search range by making it only do a certain set of if statements for each tab, for example if the "Weapons" tab is open and you click a button, it will jump to a set of "if's" for which weapon button was clicked. Here is my client script at the moment, but the Purchase doesn't work function onClientGUIClick (button, state, absoluteX, absoluteYe) if selectedTab == TabItems then if (source == WepBtnSHOVEL) then money = getPlayerMoney (source) if (money >= 300) then player = getLocalPlayer() outputChatBox ("You bought a SHOVEL for $300",225,225,0) takePlayerMoney(300) triggerServerEvent ("GiveSHOVEL",getLocalPlayer(),GiveSHOVEL) else outputChatBox ("Your funds are too low") end elseif (source == WepBtnKATANA) then money = getPlayerMoney (source) if (money >= 500) then player = getLocalPlayer() outputChatBox ("You bought a KATANA for $500",225,225,0) takePlayerMoney(500) triggerServerEvent ("GiveKATANA",getLocalPlayer(),GiveKATANA) else outputChatBox ("Your funds are too low") end end end if (source == StephCloseBtn) then guiSetVisible (StephMission, false) showCursor (false) end end addEventHandler ("onClientGUIClick", getRootElement(), onClientGUIClick) Here's the Server element: function GiveSHOVEL () giveWeapon (source,6,1,true) end addEvent("GiveSHOVEL",true) addEventHandler("GiveSHOVEL",getRootElement(),GiveSHOVEL) function GiveKATANA () giveWeapon (source,8,1,true) end addEvent("GiveKATANA",true) addEventHandler("GiveKATANA",getRootElement(),GiveKATANA) What's wrong with it? Thanks Link to comment
Castillo Posted February 28, 2012 Share Posted February 28, 2012 Never use takePlayerMoney client side, because it'll not really take it. -- client side: function onClientGUIClick (button, state, absoluteX, absoluteYe) local selectedTab = guiGetSelectedTab(myTabPanel) -- Specify your tab panel here. local money = getPlayerMoney () if (selectedTab == TabItems) then if (source == WepBtnSHOVEL) then if (money >= 300) then outputChatBox ("You bought a SHOVEL for $300",225,225,0) triggerServerEvent ("GiveSHOVEL",localPlayer) else outputChatBox ("Your funds are too low") end elseif (source == WepBtnKATANA) then if (money >= 500) then outputChatBox ("You bought a KATANA for $500",225,225,0) triggerServerEvent ("GiveKATANA",localPlayer) else outputChatBox ("Your funds are too low") end end end if (source == StephCloseBtn) then guiSetVisible (StephMission, false) showCursor (false) end end addEventHandler ("onClientGUIClick", getRootElement(), onClientGUIClick) -- server side: function GiveSHOVEL () giveWeapon (source,6,1,true) takePlayerMoney(source,300) end addEvent("GiveSHOVEL",true) addEventHandler("GiveSHOVEL",getRootElement(),GiveSHOVEL) function GiveKATANA () giveWeapon (source,8,1,true) takePlayerMoney(source,500) end addEvent("GiveKATANA",true) addEventHandler("GiveKATANA",getRootElement(),GiveKATANA) Link to comment
Vaux42 Posted February 28, 2012 Author Share Posted February 28, 2012 Thanks heaps for that, it works perfectly 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