Jump to content

Problem with triggerClientEvent and outputChatBox


Dudalus

Recommended Posts

Hi

I wrote gamemodes for SA-MP and am new to the MTA scene - so maybe my understanding about the element tree is wrong. I want to call a client function from serverside and output a simple message - but I don't see a message (the trigger should be ok, there is no error in the server console). Both scripts are added to the meta.xml

Serverside:

function callFoo() 
    triggerClientEvent("foo", getRootElement()) 
end 
addEventHandler("onPlayerJoin", getRootElement(), callFoo) 
  

Clientside:

function foo() 
    outputChatBox("Hello", source) 
end 
addEvent("foo", true) 
addEventHandler("foo", getRootElement(), foo) 

Is this code right ? source is always the object which triggered an event ? There is a variable called "client", is this the clientside version ?

Thanks

Link to comment
  • Other Languages Moderators

Client side outputChatBox doesn't have argument visibleTo.

Arguments is

bool outputChatBox ( string text [, int r=231, int g=217, int b=176, bool colorCoded=false ] ) 

So your second argument is element but should be number( integer ).

Also if you use event ( onPlayerJoin server side event ) it doesn't triggered to all because some body can download something and etc. In this case you should use this:

Server

addEvent( 'SendTextToClient', true ) 
  
local sJoinMessage = 'Welcome'  
  
addEventHandler( 'SendTextToClient', root, 
    function() 
        triggerClientEvent( source, 'SendMessage', source, sJoinMessage ) -- Send text to client 
    end 
) 
  

Client

  
addEvent( 'SendMessage', true ) 
  
addEventHandler( 'SendMessage', localPlayer, 
    function( sMsg ) 
        outputChatBox( sMsg ) 
    end 
) 
  
addEventHandler( 'onClientResourceStart', resourceRoot, 
    function() 
        triggerServerEvent( 'SendTextToClient', localPlayer ) -- Trigger when client is ready. 
    end 
) 
  
  

Link to comment

Hi

My problem was to detect if the player has an account or not (serverside function). So my solution is onClientResourceStart - I trigger a serverside function, check for an existing account and trigger a clientside login or register function and create a dialoge. Then I trigger a serverside function and create an account or spawn the player. Now the system works fine

Thanks

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