Advertisement
DraKiNs

[FS] Anti Bug Cars

Jul 15th, 2011
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.33 KB | None | 0 0
  1. #include <a_samp>
  2. #define HOLDING(%0) \
  3. ((newkeys & (%0)) == (%0))
  4. #define RELEASED(%0) \
  5. (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
  6. #define PRESSED(%0) \
  7. (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  8.  
  9. #include <a_npc>
  10.  
  11. public OnGameModeInit()
  12. {
  13.     return ConnectNPC("BotCars","BugCars");
  14. }
  15.  
  16.  
  17. public OnPlayerSpawn(playerid)
  18. {
  19.     return SetBotInPos("BotCars",0.0,0.0,0.0);
  20. }
  21.  
  22.  
  23. stock SetBotInPos(botname[],Float:x,Float:y,Float:z)
  24. {
  25.     for(new id = 0; id < 500 ; id ++) {
  26.         if(IsPlayerNPC(id)) {
  27.             new playername[24];
  28.             GetPlayerName(id,playername,24);
  29.             if(!strcmp(playername,botname,true))
  30.                 SetPlayerPos(id,x,y,z);
  31.         }
  32.     }
  33. }
  34.  
  35.  
  36. stock PutBotInVehicle(botname[],vehicleid)
  37. {
  38.     for(new id = 0; id < 500 ; id ++) {
  39.         if(IsPlayerNPC(id)) {
  40.             new playername[24];
  41.             GetPlayerName(id,playername,24);
  42.             if(!strcmp(playername,botname,true))
  43.                 PutPlayerInVehicle(id, vehicleid, 0);
  44.         }
  45.     }
  46. }
  47.  
  48.  
  49. stock GetCarAimingPlayer(playerid)
  50. {
  51.     new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2,Float:A;
  52.     GetPlayerPos(playerid, X1, Y1, Z1);
  53.     GetPlayerFacingAngle(playerid, A);
  54.     for(new v = 0; v < 8000; v++) {
  55.         GetVehiclePos(v, X2, Y2, Z2);
  56.         new Float:Raius = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
  57.         if(Raius < 100) {
  58.             X1 += (Raius * floatsin(-A, degrees));
  59.             Y1 += (Raius * floatcos(-A, degrees));
  60.             Raius = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
  61.             if(Raius < 0.5) return v;
  62.         }
  63.     }
  64.     return -1;
  65. }
  66.  
  67.  
  68. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  69. {
  70.     new Float:HealthCar,bool:PlayerAtirou;
  71.     if(newkeys & KEY_FIRE || oldkeys & KEY_FIRE && PlayerAtirou == false) {
  72.         new mirando = GetCarAimingPlayer(playerid);
  73.         if(mirando != -1) {
  74.             PutBotInVehicle("BotCars",mirando);
  75.             GetVehicleHealth(mirando,HealthCar);
  76.             SetVehicleHealth(mirando,HealthCar-13);
  77.             PlayerAtirou = true;
  78.         }
  79.         if(PlayerAtirou == true) {
  80.             SetBotInPos("BotCars",0.0,0.0,0.0);
  81.             PlayerAtirou = false;
  82.         }
  83.     }
  84.     return 1;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement