'LinKin Posted October 8, 2014 Share Posted October 8, 2014 Hello, Quick question: When you have an event handler on more than one script, how are they triggered? Are they triggered all at the same time? Or they are triggered in a script, then another, then another, etc... Thanks Link to comment
Anubhav Posted October 8, 2014 Share Posted October 8, 2014 They are triggered while resource starts. Link to comment
.:HyPeX:. Posted October 9, 2014 Share Posted October 9, 2014 They are triggered while resource starts. You misunderstood. @OP: They are all triggered at once. triggers are global for all running resources, but events are only callable from outside current resource/script if the variable that checks this is set. [ addEventHandler("random", true) ] keep in mind that server>client and viceversa have some delay. (They are still globally triggered, just from one to the other side.) Link to comment
myonlake Posted October 9, 2014 Share Posted October 9, 2014 You are however able to manipulate the order by using the priority parameter of the addEventHandler function. https://wiki.multitheftauto.com/wiki/AddEventHandler Link to comment
'LinKin Posted October 9, 2014 Author Share Posted October 9, 2014 I have a kills script for DD, It works using setElementData, so, in the stats script, I have: the event onPlayerFinishDD, Then I read the killer by getting the elementData of the source, and then at the end I set it to nil (to clear the kill). And on another script I have the same onPlayerFinishDD event, and I'm trying to get the killer of the source by getting it's elementData, but it's always returning nil. hm. I had to merge both scripts for it to work. Link to comment
Mr_Moose Posted October 9, 2014 Share Posted October 9, 2014 A more elegant solution would be to define custom events. triggerEvent With that you will always know which order they'll execute in, and it's easier to pass data to other resources functions instead of using set and getElementData, that saves bandwidth. Link to comment
.:HyPeX:. Posted October 10, 2014 Share Posted October 10, 2014 I have a kills script for DD, It works using setElementData, so, in the stats script, I have: the event onPlayerFinishDD,Then I read the killer by getting the elementData of the source, and then at the end I set it to nil (to clear the kill). And on another script I have the same onPlayerFinishDD event, and I'm trying to get the killer of the source by getting it's elementData, but it's always returning nil. hm. I had to merge both scripts for it to work. Pretty sure you're destroying the value itself, remind that althought they are triggered all at once they are the same event and are asynchronious. If the nil part was to be before the second part then it was likely to return so. Link to comment
Moderators IIYAMA Posted October 10, 2014 Moderators Share Posted October 10, 2014 I would suggest. (how I created it) When you hit somebody, you trigger a server event. You put a delay between them, like 200 ms per update. -- to save a lot of data transfer. If you use elementdata, you will be using more depending on the player count in the server and you will be constantly using the network. The next step, which you are asking for in this post. - Start exporting your data from resource to resource. (which I do recommend, because of the clean way of doing) - You can also use triggerEvent, like MrBrutus said. But that one uses a lot of memory even it isn't a bad idea. - Also you use setElementData without synchronisation, which will not use and bandwidth. (but it also creates trash, you have to delete it when you stop the resource) That are your options. 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