Jump to content

Return value from "triggerClientEvent()"


Recommended Posts

Posted

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

Don´t let your fears stand in the way of your dreams!

Posted

You can't do that.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted

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) 

The rEvolution is coming ...

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