08.02.2018, 22:42
Create an integer variable for each vehicle (in this case an array) - let's called it trailerId, and set it to the trailer's ID (vehicle id because trailers are vehicles) whenever someone attaches a trailer to their vehicles, then to INVALID_VEHICLE_ID when they detach it.
Create a reoccurring timer, that loops through vehicles and checks if their trailerId equals INVALID_VEHICLE_ID, if not, attach the trailer with that id if it's not attached already.
Create a reoccurring timer, that loops through vehicles and checks if their trailerId equals INVALID_VEHICLE_ID, if not, attach the trailer with that id if it's not attached already.