Guest User

Pit Maneuver ALPHA

a guest
Jul 23rd, 2011
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.65 KB | None | 0 0
  1. // Copyright wups
  2. #define FILTERSCRIPT
  3.  
  4. #include <a_samp>
  5. #include <foreach>
  6.  
  7. new Float:PVAngle[MAX_PLAYERS],
  8.     LastHandBreak[MAX_PLAYERS],
  9.     bool:HandBreak[MAX_PLAYERS];
  10. //Y_Less:
  11. #if !defined abs
  12.     #define abs(%1) \
  13.         (((%1) < 0) ? (-(%1)) : ((%1)))
  14. #endif
  15.  
  16. #if !defined PRESSED
  17.     #define PRESSED(%0) \
  18.         (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  19. #endif
  20. #if !defined RELEASED
  21.     #define RELEASED(%0) \
  22.         (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  23. #endif
  24.  
  25.  
  26. public OnPlayerConnect(playerid)
  27. {
  28.     HandBreak[playerid]=false;
  29.     LastHandBreak[playerid]=0;
  30.     return 1;
  31. }
  32.  
  33.  
  34. public OnPlayerUpdate(playerid)
  35. {
  36.  
  37.     return 1;
  38. }
  39.  
  40. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  41. {
  42.     if(IsPlayerInAnyVehicle(playerid))
  43.     {
  44.         if(PRESSED(KEY_HANDBRAKE))
  45.         {
  46.             HandBreak[playerid]=true;
  47.         }
  48.         else if(RELEASED(KEY_HANDBRAKE))
  49.         {
  50.             HandBreak[playerid]=false;
  51.             LastHandBreak[playerid]=GetTickCount();
  52.         }
  53.     }
  54.     return 1;
  55. }
  56.  
  57. public OnPlayerStateChange(playerid, newstate, oldstate)
  58. {
  59.     if(newstate==PLAYER_STATE_DRIVER)
  60.         GetVehicleZAngle(GetPlayerVehicleID(playerid),PVAngle[playerid]);
  61.     return 1;
  62. }
  63.  
  64. forward CheckForPIT();
  65. public CheckForPIT()
  66. {
  67.     new vehicleid,
  68.         victim=-1,
  69.         Float:angle,
  70.         Float:diff,
  71.         CPlayer;
  72.        
  73.     foreach(Player, playerid)
  74.     {
  75.         vehicleid = GetPlayerVehicleID(playerid);
  76.         if(vehicleid && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
  77.         {
  78.             CPlayer = GetClosestPlayer(playerid,4.0);
  79.             if(CPlayer == INVALID_PLAYER_ID) continue;
  80.            
  81.             GetVehicleZAngle(vehicleid,angle);
  82.             if (angle > 360.0)
  83.                 angle -= 360.0;
  84.             else if (angle < 0.0)
  85.                 angle += 360.0;
  86.             diff = abs(angle-PVAngle[playerid]);
  87.             if(diff > 45.0 && (HandBreak[playerid] || ((GetTickCount()-500) < LastHandBreak[playerid])))
  88.             {
  89.                 victim=playerid;
  90.                 break;
  91.             }
  92.             PVAngle[playerid]=angle;
  93.         }
  94.     }
  95.     if(victim != -1) OnPitManeuver(victim,CPlayer);
  96.     return 1;
  97. }
  98. stock OnPitManeuver(victim,suspect)
  99. {
  100.     SendClientMessage(victim,0xFF0000FF," * You have been hit with a PIT Maneuver!");
  101.     SendClientMessage(suspect,0xFF0000FF,", * You've done a PIT Maneuver!");
  102.     return 1;
  103. }
  104. stock GetClosestPlayer(playerid,Float:radius = 999.999)
  105. {
  106.     new Float:dis[2];
  107.     new returnid;
  108.     returnid = INVALID_PLAYER_ID;
  109.     dis[0] = radius;
  110.    
  111.     new Float:coo[6];
  112.     GetPlayerPos(playerid,coo[0],coo[1],coo[2]);
  113.     foreach(Player, i) if(i != playerid)
  114.     {
  115.         GetPlayerPos(i,coo[3],coo[4],coo[5]);
  116.         dis[1] = floatround(floatsqroot((coo[0]-coo[3])*(coo[0]-coo[3])+(coo[1]-coo[4])*(coo[1]-coo[4])+(coo[2]-coo[5])*(coo[2]-coo[5])));
  117.         if(dis[1]< dis[0])
  118.         {
  119.             dis[0] = dis[1];
  120.             returnid = i;
  121.         }
  122.     }
  123.     return returnid;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment