..:D&G:.. Posted August 17, 2015 Share Posted August 17, 2015 Hey, I am using some triggers to "setGuiText", but it looks like it updates the same text for all players with that window open. How can I make it so it only updates for the player that triggered the event? Server side: triggerClientEvent ( getRootElement(), "showConversionResult", resourceRoot, from, to, tonumber ( amount ), results["rates"][to] ) client: function showConversionResult ( from, to, amount, result ) result = result * amount result = math.floor ( result + 0.5 ) guiSetText(currencyConversionResult, result) end addEvent ( "showConversionResult", true ) addEventHandler ( "showConversionResult", root, showConversionResult ) Link to comment
Moderators Citizen Posted August 17, 2015 Moderators Share Posted August 17, 2015 [quote name=..&G:..] triggerClientEvent ( getRootElement(), "showConversionResult", resourceRoot, from, to, tonumber ( amount ), results["rates"][to] ) Just replace getRootElement() by the player element you want to update his GUI. If you keep getRootElement() it will send that event to all connected players. Link to comment
..:D&G:.. Posted August 17, 2015 Author Share Posted August 17, 2015 I tried to use "client" as I saw on wiki, but it doesn't work, it says "String expected got nil" or something like that.. Link to comment
t3wz Posted August 18, 2015 Share Posted August 18, 2015 [quote name=..&G:..]I tried to use "client" as I saw on wiki, but it doesn't work, it says "String expected got nil" or something like that.. This is because client isn't defined (he 'appears' in the serverside when you use triggerServerEvent) this should work: triggerClientEvent ( thePlayer, "showConversionResult", thePlayer, from, to, tonumber ( amount ), results["rates"][to] ) Link to comment
..:D&G:.. Posted August 18, 2015 Author Share Posted August 18, 2015 [quote name=..&G:..]I tried to use "client" as I saw on wiki, but it doesn't work, it says "String expected got nil" or something like that.. This is because client isn't defined (he 'appears' in the serverside when you use triggerServerEvent) this should work: triggerClientEvent ( thePlayer, "showConversionResult", thePlayer, from, to, tonumber ( amount ), results["rates"][to] ) I know, and I used triggerServerEvent: triggerServerEvent ( "convertCurrency", resourceRoot, currencyInitialsFrom, currencyInitialsTo, amountText ) Maybe it's because of the "resourceRoot" thing? Link to comment
Moderators Citizen Posted August 18, 2015 Moderators Share Posted August 18, 2015 Ok from the fragments of code you provided, I think I guessed the steps: 1 - you show the gui to get user inputs 2 - then you triggerServerEvent to send the inputs with the "convertCurrency" event name. 3 - on the server-side the handler of that event will then call an api using fetchRemote. At this point the handler has access to the client variable that represents who triggered the "convertCurrency" event. 4 - the fetchRemote is executed and you receive the results in the callback function. At this point (so inside the callback function) you DO NOT have access to the client variable anymore. So you can't triggerClientEvent using the client variable as it doesn't exist anymore. If you want it inside your callback, you have to pass it to the callback aswell by adding client in the arguments list of the fetchRemote function. Then you will do your trigger on using that callback argument. If it's still not clear, show us your fetchRemote and the callback function. Regards, Citizen 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