huyjvguyen Posted August 5, 2015 Posted August 5, 2015 how to give player money on click button client function panel() w = guiCreateWindow(x,y,w,h,"money",false) b =guiCreateButton(x,y,w,h,"moneyb", true, w) function trigger() triggerServerEvent("moneyhere") --it's right ?? end addEventHandler("onClientGUIClick", b, trigger) -- it is right? end serrver function givemoney(thePlayer) if name then givePlayerMoney(thePlayer, 10000) end end addEvent("moneyhere",true) addEventHandler("moneyhere", getLocalPlayer(), givemoney) -- and this??? give player money when they click button b on w
Danz Posted August 5, 2015 Posted August 5, 2015 As far as i'm concerned you don't even need the Server-side event to give money, you can give money to the player client-side function panel() w = guiCreateWindow(x,y,w,h,"money",false) b =guiCreateButton(x,y,w,h,"moneyb", true, w) end function trigger () if source == b then givePlayerMoney(10000, localPlayer) end end addEventHandler("onClientGUIClick", guiRoot, trigger) If you have further problems than this, please post the full code
DNL291 Posted August 5, 2015 Posted August 5, 2015 The money will not be synchronized with the server side, it will be only set to the client. -- Client-side function panel() w = guiCreateWindow(x,y,w,h,"money",false) b = guiCreateButton(x,y,w,h,"moneyb", false, w) showCursor(true) addEventHandler("onClientGUIClick", b, function() triggerServerEvent("moneyhere", localPlayer) destroyElement(w) showCursor(false) end, false) end -- Server-side function givemoney() if source == client then givePlayerMoney(source, 10000) end end addEvent("moneyhere",true) addEventHandler("moneyhere", root, givemoney) 1
AleksCore Posted September 5, 2016 Posted September 5, 2016 I don't clearly understand why need this check: if source == client then But this small check helped me to fix my trouble. Thanks!
Walid Posted September 5, 2016 Posted September 5, 2016 (edited) You should use the global variable client serverside instead of passing the localPlayer by parameter. -- Client-side function panel() w = guiCreateWindow(x,y,w,h,"money",false) b = guiCreateButton(x,y,w,h,"moneyb", false, w) showCursor(true) addEventHandler("onClientGUIClick", b, function() triggerServerEvent("moneyhere", resourceRoot) destroyElement(w) showCursor(false) end, false) end -- Server-side function givemoney() givePlayerMoney(client, 10000) end addEvent("moneyhere",true) addEventHandler("moneyhere", resourceRoot, givemoney) Edited September 5, 2016 by Walid
AleksCore Posted September 5, 2016 Posted September 5, 2016 (edited) Got problems in my script when changed second argument for "triggerServerEvent" to "resourceRoot" and removed "if source == client then " check. So I use the same way as in @DNL291's example. Mystery. Server receive different userdata, but it should be the same, because the same player element passed. P.S. outputChatBox( tostring(client) ) Edited September 5, 2016 by AleksCore
Walid Posted September 5, 2016 Posted September 5, 2016 For triggerServerEvent, client is always set. i.e.: triggerServerEvent("EventName" , localPlayer) source is localPlayer client is localPlayer triggerServerEvent("EventName" , resourceRoot or root) source is resourceRoot or root client is localPlayer 1
AleksCore Posted September 7, 2016 Posted September 7, 2016 Yes, I know. Thanks anyways! Mystery was in my mistake. Event was triggering 'onClientColShapeHit' and I totally forgot to make sure hitElement == localPlayer.
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