Jump to content

Serversided setPedControlState


NeXTreme

Recommended Posts

I've seen this "issue" being addressed in the Scripting section a lot, and I could certainly use it myself, too. The problem with setPedControlState is that it's only client-sided, which isn't that big of a deal in most cases. However, my recent project requires precise synchronization and having a client-sided function to toggle controls isn't really the best. Just last time I was testing a script with some people, and after a while the vehicle that the ped was controlling started to have major desync. It was driving for a bit, then quickly jumped to another location, etc. Now the difference with the server-sided function would be that it's fully controlled by the server, and therefore isn't affected by FPS for example. I've been able to achieve a very "hacky" workaround with elementData, and it does a decent job of keeping everything synced. I would, however, still like to see this function available server-side if possible.

Regards,

NeXTreme

Link to comment

You should trigger an event for everyone... well that wouldn't make sync if I'm not wrong, but you should try if you never tried.

ped = createPed ( 248, 0, 0, 5 ) 
triggerClientEvent ( root, "onControlState", ped ) 

addEvent ( "onControlState", true ) 
addEventHandler ( "onControlState", root, function () 
setPedControlState ( source, "fire", true ) 
end ) 
  

Link to comment

I have of course triggered an event for everyone, but sometimes desync still occurs. Now obviously if you can't have "server-side physics", there should still be some way of making sync better, like, if some player had an average of 20 fps, his vehicle could move slower, and therefore cause desync. Same could occur with having a high ping or something, as the player would recieve the response from the server later than other players. The idea of server-sided function is that the server would ensure that every client would get it at the exact same time, and also ensure the vehicle (or ped) has moved correctly.

Link to comment

With server-sided function clients would still get the new control state at different time because it takes different time for clients with different ping to get the data from the server. And ped/vehicle will still be in position where the syncer sees them. The only workaround I see is a client-side script which detects how much the player is lagging and and according to that, get velocity of all vehicles streamed in and put them further in the direction where they're moving. Still, that needs some work with collision detection to prevent vehicles from moving through walls.

Link to comment

Making the setPedControlState function server side would not solve the problem, when you use the function on the client that is a syncer of an element, the element (ped, vehicle)will be synced (have the same position, animation and velocity)for all clients regardless to ping or fps.

The problem lays in SYNCING RANGE and that is 140m for vehicles ans 100m for pedestrians.

Elements outside that range are not synced, velocity position and animations are not updated for other clients... When the element find itself in the range again, it will “jump” to the last synced position...

I doubt that the range will be increased someday, the current may seam shout, but I think its good enough compromise between the quality and performance...

one more thing: functions like setElementPosition and moveObject are forcing the elements position to update even outside the syncing range ;)

Link to comment

Accuracy is less important when no one is near the ped/vehicle. That is the point, you can use setElementPosition to update the position if element has no syncer. I had done such updating to make the ped follow the path and it worked fine.

Link to comment
  • Recently Browsing   0 members

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