httpRick Posted July 12, 2016 Share Posted July 12, 2016 Hello, I have a problem with synchronization trailer because the trailer MTA walks away from Player A certain distance lose their proper sync, I wanted to remedy after the execution of the New Stremaera trailers but there are still problems at the bottom of sending the code: Server-Side: function Unhook(player) if getPedOccupiedVehicle( player ) then local theTruck = getPedOccupiedVehicle( player ) if detachTrailerFromVehicle(theTruck) then local theTrailer = getElementData(theTruck,"Trailer") local x,y,z = getElementPosition( theTruck ) local _,_,rot = getElementRotation( theTruck ) local rot = 360-rot local rot = math.rad(rot) local x = x - 15 * math.sin(rot) local y = y - 15 * math.cos(rot) setElementPosition( theTrailer, x,y,z ) end end end addCommandHandler( "unhook", Unhook ) function onTrailerAttach(theTruck) setElementData(theTruck,"Trailer",source) triggerClientEvent( "addTrailer", getRootElement( ),theTruck, source ) end addEventHandler("onTrailerAttach", getRootElement(), onTrailerAttach) function onTrailerDetach(theTruck) triggerClientEvent( "removeTrailer", getRootElement( ), theTruck, source ) end addEventHandler("onTrailerDetach", getRootElement(), onTrailerDetach) Client-Side: Amount = 0 Sync = false Trailers = {} Timer = getTickCount( ) local screenW, screenH = guiGetScreenSize() function getTrailer(theTruck,theTrailer) for i,v in ipairs(Trailers) do if v.truck == theTruck and v.trailer == theTrailer then return theTruck, theTrailer, i end end return nil, nil, false end function addTrailer(theTruck, theTrailer) local _, _, index = getTrailer(theTruck,theTrailer) if not(index) then table.insert(Trailers, {truck=theTruck, trailer=theTrailer} ) end end function deleteTrailer(theTruck, theTrailer) local _, _, index = getTrailer(theTruck,theTrailer) if index then table.remove(Trailers, index) setElementData(theTruck,"Trailer",false) end collectgarbage() end function UpdateSyncedTrailer() if getTickCount()-Timer > 5000 then Timer = getTickCount( ) Amount = 0 Sync = false for i,v in ipairs(Trailers) do if isElementStreamedIn( v.truck ) and isElementStreamedIn( v.trailer ) then if not( getPedOccupiedVehicle( getLocalPlayer( ) ) == v.truck) then detachTrailerFromVehicle( v.truck, v.trailer ) attachTrailerToVehicle( v.truck, v.trailer ) Sync = true end Amount = Amount+1 end end collectgarbage() end dxDrawText("Streaming Trailers: "..Amount.." | Size Array: "..#Trailers.." | Memory use: "..collectgarbage("count")*1024 .." | Update Time next Sync: ".. math.abs( getTickCount()-Timer - 5000 ) , screenW * 0.0063, screenH * 0.9333, screenW * 0.2906, screenH * 0.9700, tocolor(255, 255, 255, 255), 2.00, "default", "left", "top", false, false, false, false, false) end addEventHandler("onClientRender",root,UpdateSyncedTrailer) function onClientTrailerAttach(TheTruck, TheTrailer) if not( getElementType(source) == "vehicle" ) then source = TheTrailer end --setElementStreamable ( source, true ) addTrailer(TheTruck, source) end addEventHandler("onClientTrailerAttach", getRootElement(), onClientTrailerAttach) addEvent ( "addTrailer", true ) addEventHandler ( "addTrailer", getRootElement(), onClientTrailerAttach ) function onClientTrailerDetach(TheTruck, TheTrailer) if not( getElementType(source) == "vehicle" ) then source = TheTrailer end --setElementStreamable ( source, false ) if not(Sync) then deleteTrailer(TheTruck, source) end end addEventHandler("onClientTrailerDetach", getRootElement(), onClientTrailerDetach) addEvent ( "removeTrailer", true ) addEventHandler ( "removeTrailer", getRootElement(), onClientTrailerDetach ) function onClientElementStreamIn() if getElementType(source) == "vehicle" then if getElementData(source,"Trailer") then addTrailer(source, getElementData(source,"Trailer") ) end end end addEventHandler( "onClientElementStreamIn", getRootElement( ), onClientElementStreamIn) function onClientElementStreamOut() if getElementType(source) == "vehicle" then if getElementData(source,"Trailer") then --removeTrailer(source, getElementData(source,"Trailer") ) end end end addEventHandler( "onClientElementStreamOut", getRootElement( ), onClientElementStreamOut) I will be grateful for any kind of help, I'm sorry to be so that my english. 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