esporta05 Posted July 23, 2014 Share Posted July 23, 2014 Hello wonderful MTA:SA community. I was working on a Ammu Nation script and I get stucked with some problems. So if you guys can tell me whats wrong with my script I will really appreciate it. the command based one working perfectly without any problems but the other one which is getting triggered by the gui button s not working. Here is the debugscript: http://i.imgur.com/XiFcI4f.png function buygun (player) local m4money = 2000 local money = getPlayerMoney(player) if (money >= m4money) then giveWeapon ( player, 31, 100, true ) takePlayerMoney ( player, m4money ) else outputChatBox ("You havent got enough money to buy this weapon!", source) end end addCommandHandler ("m4", buygun) -- -- -- function buym4 (player) local money = getPlayerMoney(player) local m4money = 2000 if ( money >= m4money ) then giveWeapon ( player, 31, m4ammo, true) else outputChatBox ("You havent got enough money to buy this!", source) end end addEvent("buym4",true) addEventHandler("buym4",getRootElement(),buym4) -- Steps: -- Give weps with command |Done -- Take money while giving weps with command |Done -- Establish connections between your client sided script and server sided script. |Done -- Make a simple button and sell weps from that button when it get clicked | Having errors -- Make a simple gui window and add all neccesary weps. | Not Finished -- Make a marker and set visible the GUI when the player hits to that marker | Not Finished Here is the function script that use in my client sided script for triggering the server sided buym4 function: function buym4 () triggerServerEvent ( "buym4", getRootElement(), "buym4" ) end addEventHandler ( "onClientGUIClick", M4.button, buym4, false ) Link to comment
Et-win Posted July 23, 2014 Share Posted July 23, 2014 function buym4 (toBuy) local money = getPlayerMoney(source) local m4money = 2000 if ( money >= m4money ) then giveWeapon ( source, 31, m4ammo, true) else outputChatBox ("You havent got enough money to buy this!", source) end end addEvent("buym4",true) addEventHandler("buym4",getRootElement(),buym4) -- Steps: -- Give weps with command |Done -- Take money while giving weps with command |Done -- Establish connections between your client sided script and server sided script. |Done -- Make a simple button and sell weps from that button when it get clicked | Having errors -- Make a simple gui window and add all neccesary weps. | Not Finished -- Make a marker and set visible the GUI when the player hits to that marker | Not Finished function buym4 () triggerServerEvent ( "buym4", getLocalPlayer(), "buym4" ) end addEventHandler ( "onClientGUIClick", M4.button, buym4, false ) Please try to understand what I did. Link to comment
esporta05 Posted July 23, 2014 Author Share Posted July 23, 2014 Thank you for helping me, I understand from this, using player could create some problems to me. I should use source rather than player on server side scripting. But I dont understand why you put toBuy argument to the function. It is working without it too. btw it worked. Thank you again and if you explain me why you use toBuy argument i will really appreciate it Link to comment
Et-win Posted July 24, 2014 Share Posted July 24, 2014 triggerServerEvent ( "buym4", getLocalPlayer(), "buym4" ) You are sending '"buyme4"' withing the trigger (Last argument) and I left it there just incase you need it for further scripting. This is why I changed 'player' to 'toBuy' but 'toBuy' can be somethings else random too. If not needed, you can remove it. 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