Jump to content

need help with triggerServerEvent and addEvent


huyjvguyen

Recommended Posts

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

Link to comment

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

Link to comment

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) 
  

  • Like 1
Link to comment
  • 1 year later...

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 by Walid
Link to comment

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 by AleksCore
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...