onPlayerUpdate

From Liberty Unleashed Wiki
Jump to: navigation, search
Home   |   Squirrel Scripting   |   Server Functions   |   Server Events   |   Client Functions   |   Client Events
LU Warning: This event is called multiple times per second for each player. It is not recommended to run any heavy code under this.

This event is called every time a player sync packet is received.

Syntax

  1. function onPlayerUpdate( Player player )

Arguments

  • player - The player who is sending a sync packet

Returns

  • 1 - This sync packet will be transmitted to other clients normally
  • 0 - Do not broadcast this sync packet to other clients (Does not affect passenger packets)

Example

This example will trigger a function every time a player moves.

  1.  
  2. g_Positions <- array( GetMaxPlayers(), null ); // Storage for old positions
  3.  
  4. function HasPlayerMoved( v1, v2 )
  5. {
  6. return ( ( fabs( v1.x - v2.x ) > 0.1 ) || ( fabs( v1.y - v2.y ) > 0.1 ) || ( fabs( v1.z - v2.z ) > 0.1 ) );
  7. }
  8.  
  9. function onPlayerUpdate( player )
  10. {
  11. local id = player.ID;
  12. // Grab the current and old positions and store values for future reference
  13. local oldpos = g_Positions[ id ];
  14. local newpos = player.Pos;
  15. g_Positions[ id ] = newpos;
  16. // Do we have stored info about the previous position yet?
  17. if ( !oldpos ) return 1;
  18. if ( HasPlayerMoved( oldpos, newpos ) )
  19. {
  20. // Player has moved, trigger the event
  21. onPlayerMove( player, oldpos, newpos );
  22. }
  23.  
  24. return 1;
  25. }
  26.  
  27. function onPlayerMove( player, oldpos, newpos )
  28. {
  29. MessagePlayer( "You moved!", player );
  30. }
  31.  

Notes

The function MessagePlayer was used in this example. More info about it can be found in the corresponding page.

Related Events

Personal tools
Namespaces

Variants
Actions
Navigation
scripting
Toolbox