ShayF2 Posted April 14, 2018 Share Posted April 14, 2018 (edited) I didn't want to put this into resources because it's not a resource, its more of a useful function. I made this today and I thought that it would help a lot of scripters. This is a onVehicleSpawn event that I made, it is server side only. Here is how you use it. addEvent('onVehicleSpawn') local last = 0 setTimer(function() local vehs = getElementsByType('vehicle') if #vehs > last then last = #vehs triggerEvent('onVehicleSpawn',root,vehs[#vehs]) end end,50,0) -- then use it like so addEventHandler('onVehicleSpawn',root,function(vehicle) setElementPosition(vehicle,0,0,0) -- or whatever u want here.. end) Edited April 14, 2018 by ShayF 1 Link to comment
Moderators Patrick Posted April 14, 2018 Moderators Share Posted April 14, 2018 It's a good idea, but think this function use a lot of server processor. (If 500 vehs spawned on the server, this function count all vehicles in every 50ms) Link to comment
JeViCo Posted April 17, 2018 Share Posted April 17, 2018 (edited) very useful. It was so hard to trigger client many times to get a vehicle with isElementStreamedIn. But still this function may have problems. For example when 2 cars were spawned at the same time. Also it might reduce server perfomance when it has more than 200 players Edited April 17, 2018 by Juuve Link to comment
Moderators IIYAMA Posted April 17, 2018 Moderators Share Posted April 17, 2018 Hmm interesting. It isn't bug free yet. For example if you destroy a vehicle and create a vehicle at the same time, the event wouldn't be triggered. A more accurate way would be using an invert loop, which checks if the vehicle's at the end of the table are new. If not, then you can break the loop. New vehicle's should be afaik always at the end. 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