heroes9898 Posted May 31, 2014 Share Posted May 31, 2014 How can I get a returned value from the triggered client event? Or is there any possibility to do this? example: local x = triggerClientEvent(player, "getPlayerOriginalX", root, ..) Link to comment
heroes9898 Posted May 31, 2014 Author Share Posted May 31, 2014 I know, is there no way to do something like this? Link to comment
Moderators Citizen Posted May 31, 2014 Moderators Share Posted May 31, 2014 Here is an example: server: addEvent("onGetPlayerOriginalXResponse") function s_getPlayerOriginalX( response ) if not response then triggerClientEvent(player, "onGetPlayerOriginalXRequest", player) else -- do something with the response: outputChatBox("The PlayerOriginalX is: "..response) end end addEventHandler("onGetPlayerOriginalXResponse", root, s_getPlayerOriginalX) client: addEvent("onGetPlayerOriginalXRequest", true) function c_getPlayerOriginalX() local response = 2 triggerClientEvent("onGetPlayerOriginalXResponse", localPlayer, 2) end addEventHandler("onGetPlayerOriginalXRequest", root, c_getPlayerOriginalX) The s_getPlayerOriginalX cannot return anything. It only cans do stuff for you with the response. I don't know what you are trying to do, but according to your event name (getPlayerOriginalX) it looks like you are trying to get a position that is stored in the client-side. If it's what you are trying to do, please use element datas instead ! In short, element datas are like variables stored in a player element and automatically synced with bot sides (client and server sides): client: -- Your code that set the original position variables: local originalPosition = {X=10, Y=20, Z=30} -- Store it in the player element (the local player here) setElementData(localPlayer, "originalPosition", originalPosition) -- This data is automatically synced with the server side in background server: function printMyOriginalPosition() local originalPosition = getElementData(thePlayer, "originalPosition") if originalPosition then local x, y, z = originalPosition.X, originalPosition.Y, originalPosition.Z outputChatBox("My original position is: "..x..", "..y..", "..z, thePlayer) else outputChatBox("Your originalPosition data has not been set yet !", thePlayer) end end addCommandHandler("originalpos", printMyOriginalPosition) Link to comment
heroes9898 Posted May 31, 2014 Author Share Posted May 31, 2014 thanks. the originalX was an example i asked only whether that works. 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