Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stock AngleInRangeOfAngle(Float:a1, Float:a2, Float:range)
- {
- a1 -= a2;
- if((a1 < range) && (a1 > -range)) return true;
- return false;
- }
- stock Float:DistanceCameraTargetToLocation( Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ ) {
- new Float:TGTDistance;
- TGTDistance = floatsqroot(( CamX - ObjX ) * ( CamX - ObjX ) + ( CamY - ObjY ) * ( CamY - ObjY ) + ( CamZ - ObjZ ) * ( CamZ - ObjZ ));
- new Float:tmpX, Float:tmpY, Float:tmpZ;
- tmpX = FrX * TGTDistance + CamX;
- tmpY = FrY * TGTDistance + CamY;
- tmpZ = FrZ * TGTDistance + CamZ;
- return floatsqroot(( tmpX - ObjX ) * ( tmpX - ObjX ) + ( tmpY - ObjY ) * ( tmpY - ObjY ) + ( tmpZ - ObjZ ) * ( tmpZ - ObjZ ));
- }
- stock Float:GetPointAngleToPoint( Float:x2, Float:y2, Float:_X, Float:_Y )
- {
- new Float:DX, Float:DY;
- new Float:angle;
- DX = floatabs( floatsub( x2,_X ));
- DY = floatabs( floatsub( y2,_Y ));
- if( DY == 0.0 || DX == 0.0)
- {
- if( DY == 0 && DX > 0) angle = 0.0;
- else if( DY == 0 && DX < 0) angle = 180.0;
- else if( DY > 0 && DX == 0) angle = 90.0;
- else if( DY < 0 && DX == 0) angle = 270.0;
- else if( DY == 0 && DX == 0) angle = 0.0;
- }
- else
- {
- angle = atan( DX/DY );
- if( _X > x2 && _Y <= y2 ) angle += 90.0;
- else if( _X <= x2 && _Y < y2 ) angle = floatsub( 90.0, angle );
- else if( _X < x2 && _Y >= y2 ) angle -= 90.0;
- else if( _X >= x2 && _Y > y2 ) angle = floatsub( 270.0, angle );
- }
- return floatadd( angle, 90.0);
- }
- stock IsPlayerAimingAt( playerid, Float:x, Float:y, Float:z, Float:radius )
- {
- new Float:camera_x,Float:camera_y,Float:camera_z,Float:vector_x,Float:vector_y,Float:vector_z;
- GetPlayerCameraPos( playerid, camera_x, camera_y, camera_z );
- GetPlayerCameraFrontVector( playerid, vector_x, vector_y, vector_z );
- new Float:vertical, Float:horizontal;
- switch ( GetPlayerWeapon( playerid ))
- {
- case 34,35,36:
- {
- if( DistanceCameraTargetToLocation( camera_x, camera_y, camera_z, x, y, z, vector_x, vector_y, vector_z ) < radius ) return true;
- return false;
- }
- case 30,31: { vertical = 4.0; horizontal = -1.6;}
- case 33: { vertical = 2.7; horizontal = -1.0;}
- default: { vertical = 6.0; horizontal = -2.2;}
- }
- new Float:angle = GetPointAngleToPoint( 0, 0, floatsqroot( vector_x*vector_x+vector_y*vector_y ), vector_z ) - 270.0;
- new Float:resize_x, Float:resize_y, Float:resize_z = floatsin( angle+vertical, degrees );
- GetXYInFrontOfPoint( resize_x, resize_y, GetPointAngleToPoint( 0, 0, vector_x, vector_y )+horizontal, floatcos( angle+vertical, degrees ));
- if( DistanceCameraTargetToLocation( camera_x, camera_y, camera_z, x, y, z, resize_x, resize_y, resize_z ) < radius ) return true;
- return false;
- }
- stock IsPlayerFacingPlayer(playerid, targetid, Float:dOffset)
- {
- new
- Float:pX,
- Float:pY,
- Float:pZ,
- Float:pA,
- Float:X,
- Float:Y,
- Float:Z,
- Float:ang;
- if(!IsPlayerConnected(playerid) || !IsPlayerConnected(targetid)) return 0;
- GetPlayerPos(targetid, pX, pY, pZ);
- GetPlayerPos(playerid, X, Y, Z);
- GetPlayerFacingAngle(playerid, pA);
- if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
- else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
- else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
- return AngleInRangeOfAngle(-ang, pA, dOffset);
- }
- public OnPlayerUpdate( playerid )
- {
- new Keys,ud,lr;
- GetPlayerKeys(playerid,Keys,ud,lr);
- if( Keys & KEY_FIRE )
- {
- if( GetPlayerTargetPlayer( playerid ) == npc )
- {
- if( GetPlayerWeaponState( playerid ) != WEAPONSTATE_NO_BULLETS && GetPlayerWeaponState( playerid ) != WEAPONSTATE_RELOADING )
- {
- if( GetPlayerCameraMode( playerid ) == 53 )
- {
- if( IsPlayerFacingPlayer( playerid, npc, 5.0 ) )
- {
- if( IsPlayerAimingAt( playerid, x, y, z, 4.2 ) )
- {
- new Float:dmg;
- // Default GTA:SA weapon damages.
- switch( GetPlayerWeapon( playerid ) )
- {
- case 22: dmg = 17.0;
- case 23: dmg = 40.0;
- case 24: dmg = 70.0;
- case 32: dmg = 20.0;
- case 28: dmg = 20.0;
- case 29: dmg = 25.0;
- case 25: dmg = 50.0;
- case 26: dmg = 40.0;
- case 27: dmg = 20.0;
- case 31: dmg = 35.0;
- case 30: dmg = 30.0;
- case 33: dmg = 70.0;
- case 34: dmg = 125.0;
- default: dmg = 30.0;
- }
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement