Jump to content

Triggering an exported client-side function


patriot

Recommended Posts

Hi there,

I've got a client-side function that I export to other resources. Everything is fine, until I need this function to be triggered by serverside event.

When I want to export this clientside function to clientside resource, I simply use this:

exports["text"]:showText("My text", "4000", 20 ) 

But what should I do if I want to "showText" to "thePlayer", by serverside?

function getPosition(thePlayer, commandName) 
        local x, y, z = getElementPosition(thePlayer) 
        local rotation = getPedRotation(thePlayer) 
        local dimension = getElementDimension(thePlayer) 
        local interior = getElementInterior(thePlayer) 
         
        outputChatBox("Position: " .. x .. ", " .. y .. ", " .. z, thePlayer, 255, 194, 14) 
        outputChatBox("Rotation: " .. rotation, thePlayer, 255, 194, 14) 
        outputChatBox("Dimension: " .. dimension, thePlayer, 255, 194, 14) 
        outputChatBox("Interior: " .. interior, thePlayer, 255, 194, 14) 
end 
addCommandHandler("getpos", getPosition, false, false) 
  

I want to use my exported clientside function inside the function above. In what way exactly can I do this?

Link to comment

What? Simply create an event with ability for remote triggering in client-side which will call that exported function just the way you wrote above in the first post and call the event in server-side.

Example - Client-side:

addEvent( "onGetPosition", true ); 
  
addEventHandler( "onGetPosition", root,  
    function( szText, var1, var2 ) 
        exports.text:showText( tostring( szText ), tostring( var1 ), tonumber( var2 ) ); 
    end 
) 

Server-side:

triggerClientEvent( ele, "onGetPosition", ele, "My text", "4000", 20 ); 

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