Hell-Mate Posted November 24, 2014 Share Posted November 24, 2014 Hello community, i just wanna ask about server only functions, as you all know getAccountData is server only function the ques is, how to use it client side ?? What i mean ? simply i wanna set a gui label with guiSetText ( label, the define of the account data( at server side ) ) i tried to make it with a local define and failed and tried to remove local and make it not local and also same error which is attempt to concatenate a nil value. I hope anyone can help me example .. server function getnum( thePlayer ) local theacc= getPlayerAccount ( thePlayer ) dataNum= getAccountData ( theacc, "data", mydata) or 0 outputChatBox ( "Your data number is: "..tonumber(dataNum), thePlayer, 0,255,0 ) end addCommandHandler ( "datanum", getnum) Client addEventHandler( "onClientGUIClick", root, function () if source == data.button[3] then guiSetText ( label1, "you data number is : "..tonumber(dataNum) ) end end ) Link to comment
Anubhav Posted November 25, 2014 Share Posted November 25, 2014 Element data or trigger. setElementData and use getElementData thier or use trigger Link to comment
Dealman Posted November 25, 2014 Share Posted November 25, 2014 You can use triggerClientEvent to transfer the data to a client. triggerClientEvent and triggerServerEvent are key functions for communicating between clients and the server. Definitely worth reading up on those Link to comment
Hell-Mate Posted November 25, 2014 Author Share Posted November 25, 2014 triggering didnt help, same error, as triggering won't get defines from server side it will just start functions on the client event .. anymore answers to my ques ? Link to comment
Saml1er Posted November 25, 2014 Share Posted November 25, 2014 triggering didnt help, same error, as triggering won't get defines from server side it will just start functions on the client event .. anymore answers to my ques ? Show us your code. If we see that you at least tried. We'll fix it for you. Link to comment
Hell-Mate Posted November 25, 2014 Author Share Posted November 25, 2014 Server function datas () local theacc = getPlayerAccount ( source ) local mydata = getAccountData ( theacc, "myData", datano ) or 0 end addEvent ("getTheData", true) addEventHandler ("getTheData", root, datas) Client addEventHandler( "onClientGUIClick", root, function () if source == data.button[3] then triggerServerEvent( "getTheData", localPlayer) guiSetText ( datalabel, "Your life time iron : "..tonumber(mydata) ) end end ) Link to comment
xTravax Posted November 25, 2014 Share Posted November 25, 2014 --server function datas () local theacc = getPlayerAccount ( client ) local mydata = getAccountData ( theacc, "myData", datano ) or 0 triggerClientEvent("data",client,client,mydata) end addEvent ("getTheData", true) addEventHandler ("getTheData", root, datas) --Client addEvent("data".true) function theData(data) data = mydata end addEventHandler("data",root,theData) addEventHandler( "onClientGUIClick", root, function () if source == data.button[3] then triggerServerEvent( "getTheData", localPlayer) guiSetText ( datalabel, "Your life time iron : "..tonumber(mydata) ) end end ) Link to comment
Dealman Posted November 25, 2014 Share Posted November 25, 2014 You did some things wrong, you'll have to read about triggering events a bit further - play around with it. Just make some test functions to transmit data back and forth - once you get used to it, it's pretty easy to understand. You also used getAccountData wrong. Try this; Server: function sendTheData_Handler() local theAccount = getPlayerAccount(client); local theData = (getAccountData(theAccount, "myData") or 0); -- When using getAccountData, you don't need a 3rd argument. Only when you set data. if(theData) then triggerClientEvent(client, "sendTheData", root); -- Send the data back to the client. end end addEvent ("getTheData", true); addEventHandler ("getTheData", root, sendTheData_Handler); Client: -- Trigger the server event, which gets the Account Data. addEventHandler("onClientGUIClick", root, function() if(source == data.button[3]) then triggerServerEvent("getTheData", localPlayer); end end) -- This client event will be triggered if data was retrieved without error. The server transmit the data to this function (playerData). function retrieveTheData_Handler(playerData) if(playerData ~= nil) then guiSetText(datalabel, "Your life time iron: "..tonumber(playerData)); end end addEvent("sendTheData", true); addEventHandler("sendTheData", root, retrieveTheData_Handler); Link to comment
Saml1er Posted November 25, 2014 Share Posted November 25, 2014 addEventHandler( "onClientGUIClick", root, function (b,s) if b == "left" and state == "up" if source == data.button[3] then triggerServerEvent( "getTheData",resourceRoot, localPlayer)-- res root uses less cpu and event will be heard within the same resource. end end end ) addEvent ("getTheData", true) addEventHandler ("getTheData", root, function ( d) guiSetText ( datalabel, "Your life time iron : "..d) -- you don't need to convert it into a number, string will also work end) function datas (p) if p ~= client then return end local theacc = getPlayerAccount ( p ) local mydata = getAccountData ( theacc, "myData", datano ) or 0 if not mydata then return end triggerServerEvent ( p, "getTheData",p,mydata) end addEvent ("getTheData", true) addEventHandler ("getTheData", root, datas) EDIT: When I finishd writing the code then found that dealman already posted. Link to comment
qaisjp Posted November 25, 2014 Share Posted November 25, 2014 (edited) Element data. Do not use element data to send these kinds of things. Edited December 2, 2014 by Guest Link to comment
Hell-Mate Posted November 25, 2014 Author Share Posted November 25, 2014 You did some things wrong, you'll have to read about triggering events a bit further - play around with it. Just make some test functions to transmit data back and forth - once you get used to it, it's pretty easy to understand. You also used getAccountData wrong.Try this; Server: function sendTheData_Handler() local theAccount = getPlayerAccount(client); local theData = (getAccountData(theAccount, "myData") or 0); -- When using getAccountData, you don't need a 3rd argument. Only when you set data. if(theData) then triggerClientEvent(client, "sendTheData", root); -- Send the data back to the client. end end addEvent ("getTheData", true); addEventHandler ("getTheData", root, sendTheData_Handler); Client: -- Trigger the server event, which gets the Account Data. addEventHandler("onClientGUIClick", root, function() if(source == data.button[3]) then triggerServerEvent("getTheData", localPlayer); end end) -- This client event will be triggered if data was retrieved without error. The server transmit the data to this function (playerData). function retrieveTheData_Handler(playerData) if(playerData ~= nil) then guiSetText(datalabel, "Your life time iron: "..tonumber(playerData)); end end addEvent("sendTheData", true); addEventHandler("sendTheData", root, retrieveTheData_Handler); tried it, no error but the label not get set, the reason that there is no error is that u put a check if it nill or not .. when i removed the check i got the same error. Link to comment
Anubhav Posted November 26, 2014 Share Posted November 26, 2014 Replace tonumber to tostring! Link to comment
Hell-Mate Posted November 26, 2014 Author Share Posted November 26, 2014 Replace tonumber to tostring! the data is a number not characters or else .. so it have to be number AFAIK Link to comment
Dealman Posted November 26, 2014 Share Posted November 26, 2014 No, he is indeed right - I missed that. A label needs a string, a number is not a string. Therefore you need to convert the number to a string using tostring. Link to comment
Hell-Mate Posted November 26, 2014 Author Share Posted November 26, 2014 No, he is indeed right - I missed that.A label needs a string, a number is not a string. Therefore you need to convert the number to a string using tostring. it sets it as nil EDIT: Saml1er code worked fine but it was having some errors and i fixed it. Thanks, Lock. Link to comment
Saml1er Posted November 26, 2014 Share Posted November 26, 2014 No, he is indeed right - I missed that.A label needs a string, a number is not a string. Therefore you need to convert the number to a string using tostring. Well I think this works. local str = ''..1 Now it's "1". : D @Shadex: Great. I missed getAccountData. I'm sure you fixed it look at dealman's post. Oh well who cares you got it working. 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