Overkillz Posted March 1, 2019 Share Posted March 1, 2019 Hello dear community, I have a little question about triggers First of all, I won't use the function getEventHandlers() or the event onDebugMessage to cancell the event. Is there someway to avoid the typical message thats says: Server/Client triggered clientside/serverside EventName but event is not added if the script is not running. Im under an experimental script and I want to avoid such messages without having the resource running. Best regards. Link to comment
Moderators IIYAMA Posted March 1, 2019 Moderators Share Posted March 1, 2019 (edited) 1. Solving the main issue. In case of sending from server to client. • Do not send triggerClientEvent's over the root variable.(it is also root, when you do not fill in the receiver) Instead use a table which contains all players that have loaded their resources. When the event onClientResourceStart has been triggered, this player is ready to go. When I release a tool that I have been announced two days ago, there will be a 2e. There is also a function in Lua called pcall. This will skip all error messages, but I don't think that will work as it is an async created error. (Not directly shown up when the trigger*Event function is called, but after it has first send to the other side) function test1 (arg) print(arg) end pcall(test1, 13342144) pcall(test2, 354356) -- there is no test2 function, but we can try to call it without any error message. Edited March 1, 2019 by IIYAMA 2 Link to comment
Moderators IIYAMA Posted March 3, 2019 Moderators Share Posted March 3, 2019 @Overkillz I made an announcement about your option 2 on my status updates. (Topic comes later, when I have more time) 1 Link to comment
Scripting Moderators ds1-e Posted May 4, 2019 Scripting Moderators Share Posted May 4, 2019 On 01/03/2019 at 08:53, IIYAMA said: 1. Solving the main issue. In case of sending from server to client. • Do not send triggerClientEvent's over the root variable.(it is also root, when you do not fill in the receiver) Instead use a table which contains all players that have loaded their resources. When the event onClientResourceStart has been triggered, this player is ready to go. When I release a tool that I have been announced two days ago, there will be a 2e. There is also a function in Lua called pcall. This will skip all error messages, but I don't think that will work as it is an async created error. (Not directly shown up when the trigger*Event function is called, but after it has first send to the other side) function test1 (arg) print(arg) end pcall(test1, 13342144) pcall(test2, 354356) -- there is no test2 function, but we can try to call it without any error message. Should work? -- default --> add player to table, after his login on https://wiki.multitheftauto.com/wiki/OnPlayerLogin -- in case of resource restart --> loop: getElementsByType, check if they are logged in (isGuestAccount function), insert logged in players to table. And so, if isn't root then this will be a little bit better for performance? Link to comment
Moderators IIYAMA Posted May 4, 2019 Moderators Share Posted May 4, 2019 3 minutes ago, majqq said: Should work? -- default --> add player to table, after his login on https://wiki.multitheftauto.com/wiki/OnPlayerLogin -- in case of resource restart --> loop: getElementsByType, check if they are logged in (isGuestAccount function), insert logged in players to table. yes, this is how it should be done. 4 minutes ago, majqq said: And so, if isn't root then this will be a little bit better for performance? for which function? triggerServer/ClientEvent, addEventHandler or getElementsByType? 1 Link to comment
Scripting Moderators ds1-e Posted May 4, 2019 Scripting Moderators Share Posted May 4, 2019 (edited) 21 minutes ago, IIYAMA said: yes, this is how it should be done. for which function? triggerServer/ClientEvent, addEventHandler or getElementsByType? triggerServerEvent Edited May 4, 2019 by majqq Link to comment
Moderators IIYAMA Posted May 5, 2019 Moderators Share Posted May 5, 2019 41 minutes ago, majqq said: triggerServerEvent I am not 100% sure why sending the root to the other side will create more CPU usage. It is not logic when you look at the element tree Element_tree. Most addEventHandlers have by default propagation enabled. Which means that all element (children) in the server will be able to trigger those addEventHandlers, if the eventname is the same and the handler element is root. The situation with using a child should be able to trigger more events than when the root element is used. What is the difference between sending root and resourceRoot from a performance perspective? Can't answer that. Not even sure if it has any relations with the addEventHandler. 1 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