Pranter Posted February 7, 2017 Share Posted February 7, 2017 Hello i have question. I got function.. function trailerCreated(text) and down here i got addEvent("test12334", true) addEventHandler("test12334", getLocalPlayer(), trailerCreated) but how i can call it from server side? any ideas? Link to comment
Oussema Posted February 7, 2017 Share Posted February 7, 2017 https://wiki.multitheftauto.com/wiki/TriggerServerEvent Link to comment
koragg Posted February 7, 2017 Share Posted February 7, 2017 https://wiki.multitheftauto.com/wiki/TriggerClientEvent As he said "from server side". Link to comment
Pranter Posted February 7, 2017 Author Share Posted February 7, 2017 1 minute ago, koragg said: https://wiki.multitheftauto.com/wiki/TriggerClientEvent As he said "from server side". Can you give an example, because its like function name, and event name, and i am confused Link to comment
Oussema Posted February 7, 2017 Share Posted February 7, 2017 all right 21 minutes ago, Pranter said: Can you give an example, because its like function name, and event name, and i am confused 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
Angelo. Posted February 8, 2017 Share Posted February 8, 2017 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
Pranter Posted February 8, 2017 Author Share Posted February 8, 2017 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now