Jump to content

Questions about handlers


Pranter

Recommended Posts

all right xD 

21 minutes ago, Pranter said:

Can you give an example, because its like function name, and event name, and i am confused :D

https://wiki.multitheftauto.com/wiki/TriggerClientEvent

you can see wiki examples :v 

server-side

function greetingCommand ( playerSource, commandName )
    triggerClientEvent ( playerSource, "onGreeting", playerSource, "Hello World!" )
end
addCommandHandler ( "greet", greetingCommand )

client-side 

function greetingHandler ( message )
    outputChatBox ( "The server says: " .. message )
end
addEvent( "onGreeting", true )
addEventHandler( "onGreeting", localPlayer, greetingHandler )

 

Link to comment

So this is your client side function, since you didn't put the code in it, I will suppose it outputs the 'text' you pass as argument.

addEvent("test12334", true)
function trailerCreated(text)
  outputChatBox("Hello World!")
end
addEventHandler("test12334", getLocalPlayer(), trailerCreated)

Now to call call this from a server side script, you need to use triggerClientEvent like this:
 

triggerClientEvent(getRootElement(), "test12334", client, text)

This will trigger the event for all the players on the server, result: the "Hello World!" message will be outputed for all players.

If you want to specify an element to trigger the event for, simply change the first argument to the element you want.
For example, I want to trigger the event for ONE player only, this player is called "Angelo", this is what I will do:
 

local pElem = getPlayerFromName("Angelo") -- you can also do this inline inside the triggerClientEvent, but I prefer it like this
triggerClientEvent(me, "test12334", client, text)
-- me : target, trigger the event for this element, optional, default is getRootElement() which is all players
-- "test12334" : your client event name
-- client : it's the source of the event, where it came from
-- text : your argument from trailerCreated function

 

Link to comment
17 hours ago, Angelo. said:

So this is your client side function, since you didn't put the code in it, I will suppose it outputs the 'text' you pass as argument.


addEvent("test12334", true)
function trailerCreated(text)
  outputChatBox("Hello World!")
end
addEventHandler("test12334", getLocalPlayer(), trailerCreated)

Now to call call this from a server side script, you need to use triggerClientEvent like this:
 


triggerClientEvent(getRootElement(), "test12334", client, text)

This will trigger the event for all the players on the server, result: the "Hello World!" message will be outputed for all players.

If you want to specify an element to trigger the event for, simply change the first argument to the element you want.
For example, I want to trigger the event for ONE player only, this player is called "Angelo", this is what I will do:
 


local pElem = getPlayerFromName("Angelo") -- you can also do this inline inside the triggerClientEvent, but I prefer it like this
triggerClientEvent(me, "test12334", client, text)
-- me : target, trigger the event for this element, optional, default is getRootElement() which is all players
-- "test12334" : your client event name
-- client : it's the source of the event, where it came from
-- text : your argument from trailerCreated function

 

Thankyou ;)

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