Jump to content

Return value from "triggerClientEvent()"


Recommended Posts

  • Moderators

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

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...