onPlayerUpdate
From Liberty Unleashed Wiki
This event is called every time a player sync packet is received.
Syntax
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.
g_Positions <- array( GetMaxPlayers(), null ); // Storage for old positions function HasPlayerMoved( v1, v2 ) { return ( ( fabs( v1.x - v2.x ) > 0.1 ) || ( fabs( v1.y - v2.y ) > 0.1 ) || ( fabs( v1.z - v2.z ) > 0.1 ) ); } function onPlayerUpdate( player ) { local id = player.ID; // Grab the current and old positions and store values for future reference local oldpos = g_Positions[ id ]; local newpos = player.Pos; g_Positions[ id ] = newpos; // Do we have stored info about the previous position yet? if ( !oldpos ) return 1; if ( HasPlayerMoved( oldpos, newpos ) ) { // Player has moved, trigger the event onPlayerMove( player, oldpos, newpos ); } return 1; } function onPlayerMove( player, oldpos, newpos ) { MessagePlayer( "You moved!", player ); }
Notes
The function MessagePlayer was used in this example. More info about it can be found in the corresponding page.
Related Events
- onPlayerAction
- onPlayerArmourChange
- onPlayerCashChange
- onPlayerChat
- onPlayerCommand
- onPlayerConnect
- onPlayerDeath
- onPlayerFall
- onPlayerHealthChange
- onPlayerIslandChange
- onPlayerJoin
- onPlayerKill
- onPlayerPart
- onPlayerScoreChange
- onPlayerSkinChange
- onPlayerSpawn
- onPlayerUpdate
- onPlayerTeamChange
-
onPlayerUseDetonator
- onPlayerVirtualWorldChange
- onPlayerWeaponChange