OnPlayerUpdate
Jump to navigation
Jump to search
Description:
This function is called when the packet containing a players data arrives from the server.
Parameters:
( playerid, updateType)
playerId : The ID of the player
updateType : The updateType
Return Values:
This function does not return any specific values.
Example
//The following is taken from an npcscript. NPC cries "Oh no", when attacked with a 'Melee weapon' function OnPlayerUpdate( playerid, updateType ) { if(updateType == PLAYERUPDATE_NORMAL || updateType == PLAYERUPDATE_AIMING) { if( (GetPlayerKeys(playerid) & 576)== 576 ) //Fire key is pressed. { local mypos = GetMyPos(); local plrangle = GetPlayerFacingAngle( playerid ); local plrpos = GetPlayerPos( playerid ); local _angle = atan2( -(mypos.x - plrpos.x ), mypos.y - plrpos.y ); if( _angle < 0 && plrangle > 0 )_angle+=2*PI; else if( plrangle <0 && _angle > 0 )_angle-=2*PI; if( abs( _angle - plrangle ) < PI/2 ) //take PI/2. 0 means straight to npc { //player is facing npc local weapon = GetPlayerArmedWeapon( playerid ); if( weapon >=0 && weapon <= 11 ) { local range = 5 ; if( GetDistanceFromMeToPoint( plrpos ) <= range ) { SendChat( "Oh! no. Stop" ); } } } } } }