Hero192 Posted January 21, 2016 Share Posted January 21, 2016 Hey, I am interested to learn about this function "triggerEvent" , can anyone explain to me more clear with an example please because I didn't get well what on wiki about this function, Thanks ! Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 You can use this function to trigger your own events, such as: -- server side: addEvent ( "onHelloCommandUsed", true ) -- Register the 'onHelloCommandUsed' event addEventHandler ( "onHelloCommandUsed", root, function ( ) outputChatBox ( getPlayerName ( source ) .." used the /hello command." ) -- Output the name of the player that used the /hello command to the chat end ) addCommandHandler ( "hello", function ( thePlayer ) triggerEvent ( "onHelloCommandUsed", thePlayer ) -- Trigger the 'onHelloCommandUsed' event end ) Link to comment
Hero192 Posted January 21, 2016 Author Share Posted January 21, 2016 So this event can be used only with the Register event of the trigger function? or it can be used on this situation too triggerEvent ( "onPlayerShoot", player, enemy) triggerClientEvent ( player, "onPlayerShoot", player, enemy) What I understood from you, This function get all the information from register event and sends it to somewhere by using triggerEvent, Correct me if I am wrong please Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 triggerEvent, triggerClientEvent and triggerServerEvent are different functions, but they work pretty much the same way. Link to comment
Hero192 Posted January 21, 2016 Author Share Posted January 21, 2016 What I understood from you, This function get all the information from register event and sends it to somewhere by using triggerEvent, Correct me if I am wrong please I know how to use the trigger(client/server)event , but I have a problem with this can you correct my first question please Link to comment
Castillo Posted January 21, 2016 Share Posted January 21, 2016 If you register an event with addEvent function, then you can trigger it later with triggerEvent. Link to comment
Hero192 Posted January 21, 2016 Author Share Posted January 21, 2016 If you register an event with addEvent function, then you can trigger it later with triggerEvent. Okay thanks I understood, So, The usage of this function is totally wrong , Because the event register doesn't exist here to use this event, RIGHT? triggerEvent ( "onPlayerShoot", player, enemy) triggerClientEvent ( player, "onPlayerShoot", player, enemy) Link to comment
Dealman Posted January 21, 2016 Share Posted January 21, 2016 It's rather simple, really. It works pretty much identically to that of triggerClientEvent and triggerServerEvent with one exception; it's one-sided. triggerClientEvent - Executed in a server-side script, it triggers a client-side event. Server -> Client triggerServerEvent - Executed in a client-sided script, it triggers a server-side event. Client -> Server triggerEvent - Can be executed in either client- or server-sided scripts, triggers an event that is in the same environment as it was executed. Client -> Client OR Server -> Server For example; -- Server Side function ExampleEvent() outputChatBox("This is my example event!") end addEvent("myExampleEvent") function TriggerCMD() triggerEvent("myExampleEvent", root) -- This will trigger the above event end addCommandHandler("Trigger", TriggerCMD, false) -- Client Side function TriggerClientCMD() triggerEvent("myExampleEvent", root) -- This will return an error, the event "myExampleEvent" does not exist end addCommandHandler("Trigger", TriggerClientCMD, false) Link to comment
Army@1 Posted January 21, 2016 Share Posted January 21, 2016 It's rather simple, really. It works pretty much identically to that of triggerClientEvent and triggerServerEvent with one exception; it's one-sided.triggerClientEvent - Executed in a server-side script, it triggers a client-side event. Server -> Client triggerServerEvent - Executed in a client-sided script, it triggers a server-side event. Client -> Server triggerEvent - Can be executed in either client- or server-sided scripts, triggers an event that is in the same environment as it was executed. Client -> Client OR Server -> Server For example; -- Server Side function ExampleEvent() outputChatBox("This is my example event!") end addEvent("myExampleEvent") function TriggerCMD() triggerEvent("myExampleEvent", root) -- This will trigger the above event end addCommandHandler("Trigger", TriggerCMD, false) -- Client Side function TriggerClientCMD() triggerEvent("myExampleEvent", root) -- This will return an error, the event "myExampleEvent" does not exist end addCommandHandler("Trigger", TriggerClientCMD, false) Little mistake there, you forgot to attach the function to the event. 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