Captain Cody Posted December 6, 2015 Share Posted December 6, 2015 I have created a train script, but for other people on the server, the carts appear on different tracks. For the driver they appear on a single track. How would I fix this "If even possible" function startScript () Train = createVehicle ( 538, 2765.2949, 508.41016, 9.864749 ) Cart = createVehicle ( 570, 2765.2949, 538.41016, 9.864749 ) Cart2 = createVehicle ( 570, 2765.2949, 590.41016, 9.864749 ) Cart3 = createVehicle ( 590, 2765.2949, 620.41016, 9.864749 ) setTrainDirection(Train, true) setTrainDerailable(Train, false) setTrainDerailable(Cart, false) setTrainDerailable(Cart2, false) setTrainDerailable(Cart3, false) setTimer ( checkdistance, 100, 0) setTimer ( checkdistance2, 100, 0) setTimer ( checkdistance3, 100, 0) end function checkdistance () vehicle1x, vehicle1y, vehicle1z = getElementPosition ( Train ) vehicle2x, vehicle2y, vehicle2z = getElementPosition ( Cart ) local distance = getDistanceBetweenPoints2D ( vehicle1x, vehicle1y, vehicle2x, vehicle2y ) local speedT2 = getTrainSpeed ( Train ) if distance > 19 then setTrainSpeed(Cart, speedT2+0.01) else if distance < 19 then setTrainSpeed(Cart, speedT2-0.0105) else if distance < 18 then setTrainSpeed(Cart, speedT2-0.015) end end end end function checkdistance2 () vehiclegx, vehiclegy, vehiclegz = getElementPosition ( Cart2 ) local distancea = getDistanceBetweenPoints2D ( vehicle1x, vehicle1y, vehiclegx, vehiclegy ) local speedT2 = getTrainSpeed ( Train ) if distancea > 40 then setTrainSpeed(Cart2, speedT2+0.01) else if distancea < 40 then setTrainSpeed(Cart2, speedT2-0.0105) if distancea < 39 then setTrainSpeed(Cart2, speedT2-0.015) end end end end function checkdistance3 () vehiclefx, vehiclefy, vehiclefz = getElementPosition ( Cart3 ) local distancea = getDistanceBetweenPoints2D ( vehicle1x, vehicle1y, vehiclefx, vehiclefy ) local speedT2 = getTrainSpeed ( Train ) if distancea > 61 then setTrainSpeed(Cart3, speedT2+0.01) else if distancea < 61 then setTrainSpeed(Cart3, speedT2-0.0105) if distancea < 60 then setTrainSpeed(Cart3, speedT2-0.015) end end end end function traincruise (playersource) theSpeed = getTrainSpeed(Train) trainTrack = getTrainTrack(Train) local thespeeda = getTrainSpeed(Train) outputChatBox ( "Train set to cruise at :" ..thespeeda.." MS", playersource ) TrainTimer = setTimer ( setSpeed, 300, 0) end function setSpeed () setTrainSpeed (Train, theSpeed) end function cancelcruise () killTimer (TrainTimer) outputChatBox ( "Train cruise disabled.", playersource ) end addCommandHandler ( "traincstop", cancelcruise ) addCommandHandler ( "trainc", traincruise ) addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), startScript) Link to comment
Captain Cody Posted December 6, 2015 Author Share Posted December 6, 2015 Any one have any ideas on how to fix this? Link to comment
Moderators IIYAMA Posted December 6, 2015 Moderators Share Posted December 6, 2015 wait for 1.6... or use 1.6 beta. 1.6 will enable functions to control that. I have the same problem with: https://forum.multitheftauto.com/viewtopic.php?f ... ain+script Link to comment
Captain Cody Posted December 6, 2015 Author Share Posted December 6, 2015 Ah ok thanks. Link to comment
Mr_Moose Posted December 7, 2015 Share Posted December 7, 2015 1.6 will only provide these two functions currently: bool setTrainTrack(vehicle train, int track) bool getTrainTrack(vehicle train, int track) Although you can control which track to spawn in you can't control where on the track your train will spawn currently. Take the two main tracks as an example if you are in San Fierro and switch the tracks from there you'll end up at a random location on the other track. These two resources provide sample code to illustrate the issue as well as temporary solutions to them: GTWtrain and GTWvehicles. What you can do is to position all cars you want to attach to your engine after your engine before attaching them by using math.sin and math.cos and the distance 20. This seems to work for up to 15 cars, more than that could still cause them to end up in different tracks. You can also prevent the cars from streaming out, which you would need to do anyway for trains longer than 8 cars as streamed out train elements tends to end up in a different track. Link to comment
Captain Cody Posted December 7, 2015 Author Share Posted December 7, 2015 Well if you stay near the train there is no issue, the only issue is when someone leaves the train it steams out client side "I'm assuming", when they go back to the train for them some carts are on different tracks but for the person who is at the train all the carts are on the same tracks. 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