Jump to content

Question Related to Trailers


Ben_Sherman

Recommended Posts

You could use element data to store the fact there's a trailer attached and use that data to reattach the trailer when streaming in to either the towtruck or the trailer, and perhaps every 5 seconds (of course as long as either one of them is streamed in) (checking if it has disconnected through desync) maybe?

Link to comment

Although catching the streaming events is a good start, it's also just the half answer. The complete answer is to also include client side positioning, meaning that during stream in you would have to set the towed vehicle's position to the exact right position behind the tow truck. Let's have a look at the code which would bee something like this (without positioning):

addEventHandler("onClientElementStreamIn", getRootElement( ), 
    function ( ) 
        if not getElementData(source, "GTWvehicles.isTrailerTowingVehile") then return end 
        local trailer = getElementData(source, "GTWvehicles.attachedTrailer") 
        attachTrailerToVehicle(source, trailer) 
    end 
); 
addEventHandler( "onClientElementStreamOut", getRootElement( ), 
    function ( ) 
            if getElementData(source, "GTWvehicles.isTrailerTowingVehile") then 
                    local trailer = getElementData(source, "GTWvehicles.attachedTrailer") 
                    if isElementStreamedIn(source) and isElementStreamedIn(trailer) then 
                            detachTrailerFromVehicle(source, trailer) 
                    end 
            elseif getElementData(source, "GTWvehicles.isTrailer") then 
                    local tower = getElementData(source, "GTWvehicles.towingVehicle") 
                    if isElementStreamedIn(tower) and isElementStreamedIn(source) then 
                            detachTrailerFromVehicle(tower, source) 
                    end 
            end 
    end 
); 

Source: https://github.com/404rq/GTW-RPG/blob/master/%5Bresources%5D/GTWvehicles/vehicle_client.lua

Assuming the towed vehicle knows the towing vehicle stored as element data and vice versa, this was originally written for trucks but the principle should be the same for tow trucks too. Now the problem with this is that even if it does work and attach and detach upon stream in/out the trailer doesn't know where the truck is and vice versa so the trailer could be in another lane of the road or even further away but still somehow attached to the truck.

Even trains are affected by this streaming issue where the cars attach/detach in an apparently random way, but here's the interesting part. Since trains always corrects their position by following the tracks this idea works brilliantly so applying the same for trucks and remaining towing vehicles would require client side positioning during stream in. Now I haven't tried that yet but I'm 99% sure that's the solution, if you just manage to position the trailer/towed vehicle in the exact right position according to the towing vehicle.

I don't have any screenshot of the problem but here's a server running this (without positioning) so that you can see the problem, bring some friends and follow a towing vehicle while it streams in and out to see what happens to the trailer: mtasa://lon.404rq.com:22005. I would appreciate if anyone can confirm the solution if they manage to make it work before me.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...