Captain Cody Posted December 10, 2015 Share Posted December 10, 2015 (edited) Not the best video, but demonstrating basic capabilities of trains in MTA, One issue I am having is keeping the trains still at stations, due to the code constantly correcting the positions they are slowly moving back and forth as they are stopped. Using freeze element does nothing. Any ideas on how to do this? Edited December 11, 2015 by Guest Link to comment
Mr_Moose Posted December 10, 2015 Share Posted December 10, 2015 Well it might not be the best solution but what I do to keep my trains still is to check their distance to defined coordinates stored in a table, and as long the train is within the station area they are not allowed to move at all. The speed is set to 0 strictly, controls like ability to move back and forth are disabled and that's all it takes to keep them still. Of course this only occurs for a limited time thanks to an indicator which is set to true while the train is still, then when switched to false another value is set to true forcing the train to override it's acceleration so that it can continue it's ride. At the end of the track you do want it to stop. You may also find some inspiration here even if some features could have been implemented better, at least for the sync. Link to comment
Captain Cody Posted December 10, 2015 Author Share Posted December 10, 2015 Ok, I'll try something like that. and I accually managed to improve sync alot, by attaching objects "In this case colshapes" to the carts and having it get distance between the train colshape and cart colshape, for some reason if someone is in the cart you are getting distance of it messes it up, the object attached fixes that. Link to comment
Dealman Posted December 11, 2015 Share Posted December 11, 2015 The YouTube BB codes do work, enter only the video ID. Link to comment
Mr_Moose Posted December 11, 2015 Share Posted December 11, 2015 Having everything synced for one player only is fairly easy, the problem is when multiple players are nearby a moving train, all with different latency and FPS. Each element has a "sync element" a player who is responsible to keep the element synced and this might work for vehicles and single cars but as soon trailers are involved, no matter if it's a train or a truck with a trailer attached there may be different element syncers for the engine and the attached trailers and that's the main reason for the bad synchronization. There's also an issue with trailers that detach once the engine is streamed out, obviously not for the driver but for players seeing the vehicle stream out and then in again it's noticeable. Two things to consider on that area I could recommend is to detach any attached vehicles when they stream out (client side only) and then attach them again when they stream in. Secondly, make sure that the element synchronizer is the same for all trailers in the chain, preferably the player with lowest latency or the driver. Although I haven't noticed this on trains very often it's a common issue with the trucks: Linerunner, Tanker and Roadtrain. It's encouraging to see more people trying to make use of trains in MTA, best luck Link to comment
Captain Cody Posted December 11, 2015 Author Share Posted December 11, 2015 How would I find the player with the lowest ping? Link to comment
Mr_Moose Posted December 11, 2015 Share Posted December 11, 2015 Loop through all players quickly and compare their ping to each other, once this piece of code is finished you will have the player element with the lowest latency and the value of the lowest latency in the two variables on line 1. local plr_lowest,lowest_ping = nil,9999 for k,v in pairs(getElementsByType("player")) do if getPlayerPing(v) < lowest_ping then lowest_ping = getPlayerPing(v) plr_lowest = v end end Last but not least you will have to call: setElementSyncer(train, plr_lowest) Assuming "train" is your train element, if you have trailers attached run a loop there as well to make sure all pieces has the same sync element. Although I'm not quiet sure about the occurrence of this if It's fair enough to set it just once, if it overrides MTA's default choice or if MTA overrides this at a later time and if so for how long time. I guess it's something to experiment with until you'll find a suitable sync. I'm currently using a basic timer for this syncing with the train engineer so the code above is just a quick non-tested example but in theory it should work and hopefully provide a fair enough (but not perfect) sync. Link to comment
Captain Cody Posted December 11, 2015 Author Share Posted December 11, 2015 Well I just set it up so it sets all the carts to who ever is syncing the train engine -- Checks every few secounds, works pretty good so far. And solved the park thing, added park command that disables the timers to check distances and sets all the speeds to 0 every few seconds to make sure the train stays stationary. - To sum it up, much more complicated then that. Link to comment
Captain Cody Posted December 12, 2015 Author Share Posted December 12, 2015 Had another player join for testing, there is a bit of lag due to ping but sync is awesome now. 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