Advertisement
Guest User

SA:MP Vehicle Damage Control (c) by Kaliber

a guest
Aug 26th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. /* SA-MP Include Vehicle Damage Control
  2.  *
  3.  * (c) by Kaliber, 2014
  4.  *
  5.  */
  6. #if !defined _samp_included
  7.     #include <a_samp>
  8. #endif
  9. #if defined _vehicle_control
  10.     #endinput
  11. #endif
  12. #define _vehicle_control
  13. #define INVALID -1
  14. stock DestroyWheel(vehicleid, wheel) {
  15.     static tmp[4];
  16.     GetVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], tmp[3]);
  17.     if(inc_IsABike(vehicleid)) {
  18.         if(wheel <= 0 || wheel > 2) return INVALID;
  19.         tmp[3] = (tmp[3] == 1) ? 0b0010 : 0b0001;
  20.     } else {
  21.         if(wheel <= 0 || wheel > 4) return INVALID;
  22.         switch(wheel) {
  23.             case 1: tmp[3] = 0b1000;
  24.             case 2: tmp[3] = 0b0010;
  25.             case 3: tmp[3] = 0b0100;
  26.             case 4: tmp[3] = 0b0001;
  27.         }
  28.     }
  29.     return UpdateVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], tmp[3]);
  30. }
  31. stock RepairWheels(vehicleid) {
  32.     static tmp[4];
  33.     return GetVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], tmp[3]),UpdateVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], 0);
  34. }
  35. stock DestroyAllWheels(vehicleid) {
  36.     static tmp[4];
  37.     return GetVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], tmp[3]),UpdateVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], (inc_IsABike(vehicleid)) ? 3 : 15);
  38. }
  39. stock DestroyPanel(vehicleid, idx) {
  40.     if(inc_IsABike(vehicleid) || idx <= 0 || idx > 4) return INVALID;
  41.     static tmp[4],buffer[33],whise[4][9];
  42.     GetVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], tmp[3]);
  43.     format(buffer,sizeof buffer,"%032b",tmp[0]),idx--;
  44.     strmid(whise[0],buffer,0,8,9),strmid(whise[1],buffer,8,16,9);
  45.     strmid(whise[2],buffer,16,24,9),strmid(whise[3],buffer,24,32,9);
  46.     strdel(whise[idx],strlen(whise[idx])-1,strlen(whise[idx]));
  47.     strins(whise[idx],"1",strlen(whise[idx]),8);
  48.     format(buffer,sizeof buffer,"%s%s%s%s",whise[0],whise[1],whise[2],whise[3]);
  49.     return UpdateVehicleDamageStatus(vehicleid, BinaryToDecimal(buffer), tmp[1], tmp[2], tmp[3]);
  50. }
  51. stock DestroyStuff(vehicleid, idx) {
  52.     if(inc_IsABike(vehicleid) || idx <= 0 || idx > 4) return INVALID;
  53.     static tmp[4],buffer[33],whise[4][9];
  54.     GetVehicleDamageStatus(vehicleid, tmp[0], tmp[1], tmp[2], tmp[3]);
  55.     format(buffer,sizeof buffer,"%032b",tmp[1]),idx--;
  56.     strmid(whise[0],buffer,0,8,9),strmid(whise[1],buffer,8,16,9);
  57.     strmid(whise[2],buffer,16,24,9),strmid(whise[3],buffer,24,32,9);
  58.     strdel(whise[idx],strlen(whise[idx])-1,strlen(whise[idx]));
  59.     strins(whise[idx],"1",strlen(whise[idx]),8);
  60.     format(buffer,sizeof buffer,"%s%s%s%s",whise[0],whise[1],whise[2],whise[3]);
  61.     return UpdateVehicleDamageStatus(vehicleid, tmp[0], BinaryToDecimal(buffer), tmp[2], tmp[3]);
  62. }
  63. stock inc_IsABike(vID) {
  64.     new m = GetVehicleModel(vID);
  65.     return (m==509||m==510||m==581||m==522||m==521||m==523||m==586||m==481||m==462||m==448||m==461||m==463||m==468||m==471) ? 1 : 0;
  66. }
  67. stock BinaryToDecimal(const binary[]) {
  68.     new num=0;
  69.     for(new i,cPos[2],l=strlen(binary); i<l; i++) {
  70.         strmid(cPos, binary, (l-(i+1)),(l-i),2);
  71.         num += (strval(cPos)*floatround(floatpower(float(2),float(i)),floatround_floor));
  72.     }
  73.     return num;
  74. }
  75. #undef INVALID
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement