Jump to content

Stream Element Sync


InDev

Recommended Posts

I want know some things about the stream of the elements:

-Does, when an element is stream for a player, the server as the true position of the element if he move ? ( i suppose yes )

-Does, If it's true, this script working? :

For the moment i only take care of the vehicles elements ( it's the most important )

Clientside:

addEventHandler( "onClientElementStreamIn", getRootElement( ),
function ( )
if getElementType( source ) == "vehicle" then
triggerServerEvent( "streamIn", source, source, getLocalPlayer() )
end
end
)
addEventHandler( "onClientElementStreamOut", getRootElement( ),
function ( )
if getElementType( source ) == "vehicle" then
triggerServerEvent( "streamOut", source, source, getLocalPlayer() )
end
end
)
addEvent( "setElementPosForPl", true )
function setElementPosForPl( element, x, y, z, r, lights )
setElementPosition( element, x, y, z )
setVehicleRotation( element, (360-r) )
setVehicleLightState( element, lights )
end
addEventHandler( "setElementPosForPl", getRootElement(), setElementPosForPl )

Serverside:

function streamIn( element, forpl )
element = element or source
if ( not getVehicleOccupant(element, 0) and not getVehicleOccupant( element, 1 ) and not getVehicleOccupant( element, 2 ) and not getVehicleOccupant( element, 3 ) and not getVehicleOccupant( element, 4 ) ) then
local x = getElementData( element, "Xs" )
local y = getElementData( element, "Ys" )
local z = getElementData( element, "Zs" )
local r = getElementData( element, "Rots" )
setElementPosition( element, x, y, z )
setVehicleRotation( element, 0, 0, (r-360) )
setVehicleOverrideLights( element, getElementData( element, "lights" ) )
else
local x, y, z = getElementPosition( element )
local rx, ry, r = getVehicleRotation( element )
local lights = getElementData( element, "lights" )
triggerClientEvent( forpl, "setElementPosForPl", forpl, element, x, y , z, r, lights ) 
end
end
addEvent( "streamIn", true )
addEventHandler( "streamIn", getRootElement(), streamIn )
 
function streamOut( element, forpl )
element = element or source
if ( not getVehicleOccupant(element, 0) and not getVehicleOccupant( element, 1 ) and not getVehicleOccupant( element, 2 ) and not getVehicleOccupant( element, 3 ) and not getVehicleOccupant( element, 4 ) ) then
local x, y, z = getElementPosition( element )
local rx,ry,r = getVehicleRotation( element )
setElementData( element, "Xs", x )
setElementData( element, "Ys", y )
setElementData( element, "Zs", z )
setElementData( element, "Rots", r )
local li = getVehicleOverrideLights( element )
setElementData( element, "lights", li )
end
end
addEvent( "streamOut", true )
addEventHandler( "streamOut", getRootElement(), streamOut )

Thanx for (futures) answers

Link to comment
-Does, when an element is stream for a player, the server as the true position of the element if he move ? ( i suppose yes )

I don't understand your question, to be honest.

Also, why are you making that code? It should be synced by MTA itself. Seems like a lot of trouble for nothing to be honest.

Link to comment

I also don't really understand why you feel the need to do so.

Is this related to your previous trailer topic?

Because if it is so, indeed, if you try, on the client side, to move vehicles for which the local player is not the driver, then MTA doesn't consider the local player as the syncer for those objects. Therefore the positions of the objects you moved will be reset as soon as an other player approaches the vicinity of the local player or the object's last legit position known by the server.

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...