Advertisement
Guest User

Untitled

a guest
Mar 31st, 2012
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.26 KB | None | 0 0
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //                      Script name: Tires Damage                             //
  3. //                      Author: Snoowker                                      //
  4. //                      Date of creation: 31-03-2012 01:54                    //
  5. //                      Skype: snoowker                                       //
  6. ////////////////////////////////////////////////////////////////////////////////
  7.  
  8. #include <a_samp>
  9.  
  10. #define PRESSED(%0) \
  11.     (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  12.    
  13. //------------------------------------------------------------------------------
  14. // Congiguration (RECOMMENDED!)
  15. #define MIN_SLOW_TIME       20
  16. #define MAX_SLOW_TIME       40
  17. #define MAX_SLOW_SPEED      7
  18. #define SLOW_KEY_ID         40
  19. #define TIMER_DURATION      1
  20. //------------------------------------------------------------------------------
  21.  
  22. new
  23.     td_BustTime[MAX_PLAYERS],
  24.     td_TimerID;
  25.  
  26. public OnFilterScriptInit() {
  27.     for(new td_i = 0, td_m = GetMaxPlayers(); td_i < td_m; td_i ++) {
  28.         td_BustTime[td_i] = 0;
  29.         DeletePVar(td_i, "td_vehicleid");
  30.     }
  31.     td_TimerID = SetTimer("td_CheckTires", TIMER_DURATION * 1000, 1);
  32.     print("Tires Damage script by Snoowker successfully loaded!");
  33.     return 1;
  34. }
  35.  
  36. public OnFilterScriptExit() {
  37.     for(new td_i = 0, td_m = GetMaxPlayers(); td_i < td_m; td_i ++) {
  38.         td_BustTime[td_i] = 0;
  39.         DeletePVar(td_i, "td_vehicleid");
  40.     }
  41.     KillTimer(td_TimerID);
  42.     print("Tires Damage script by Snoowker successfully unloaded!");
  43.     return 1;
  44. }
  45.  
  46. forward td_CheckTires();
  47. public td_CheckTires() {
  48.     new
  49.         td_Keys,
  50.         td_ud,
  51.         td_lr,
  52.         td_vehicleid,
  53.         td_NeedTimeToDamage,
  54.         td_state[2];
  55.     for(new td_i = 0, td_m = GetMaxPlayers(); td_i < td_m; td_i ++) {
  56.         if(!IsPlayerConnected(td_i) || GetPlayerState(td_i) != PLAYER_STATE_DRIVER || td_BustTime[td_i] == 0) continue;
  57.         td_vehicleid = GetPlayerVehicleID(td_i);
  58.         if(td_vehicleid != GetPVarInt(td_i, "td_vehicleid")) {
  59.             td_BustTime[td_i] = 0;
  60.             DeletePVar(td_i, "td_vehicleid");
  61.             continue;
  62.         }
  63.         GetPlayerKeys(td_i, td_Keys, td_ud, td_lr);
  64.         if(!(td_Keys & SLOW_KEY_ID || td_Keys == SLOW_KEY_ID)) {
  65.             td_BustTime[td_i] = 0;
  66.             DeletePVar(td_i, "td_vehicleid");
  67.             continue;
  68.         }
  69.         td_state[0] = GetVehicleTireState(td_vehicleid, 2);
  70.         td_state[1] = GetVehicleTireState(td_vehicleid, 4);
  71.         if(td_state[0] && td_state[1]) continue;
  72.         if(td_GetVehicleSpeed(td_vehicleid) >= MAX_SLOW_SPEED) continue;
  73.         td_BustTime[td_i] += TIMER_DURATION;
  74.         td_NeedTimeToDamage = MIN_SLOW_TIME + random(MAX_SLOW_TIME - MIN_SLOW_TIME + 1);
  75.         if(td_BustTime[td_i] >= td_NeedTimeToDamage) {
  76.             if(!random(2) && !td_state[0]) {
  77.                 SetVehicleTireState(td_vehicleid, 2, 1);
  78.             }
  79.             else {
  80.                 SetVehicleTireState(td_vehicleid, 4, 1);
  81.             }
  82.         }
  83.     }
  84.     return 1;
  85. }
  86.  
  87. public OnVehicleDamageStatusUpdate(vehicleid, playerid) {
  88.     new
  89.         td_Keys,
  90.         td_ud,
  91.         td_lr;
  92.     GetPlayerKeys(playerid, td_Keys, td_ud, td_lr);
  93.     if((!GetVehicleTireState(vehicleid, 2) || !GetVehicleTireState(vehicleid, 4)) && vehicleid == GetPVarInt(playerid, "td_vehicleid") && (td_Keys & SLOW_KEY_ID || td_Keys == SLOW_KEY_ID)) {
  94.         td_BustTime[playerid] = (MIN_SLOW_TIME + MAX_SLOW_TIME) / 5;
  95.         SetPVarInt(playerid, "td_vehicleid", vehicleid);
  96.     }
  97.     else if(GetVehicleTireState(vehicleid, 2) && GetVehicleTireState(vehicleid, 4)) {
  98.         td_BustTime[playerid] = 0;
  99.         DeletePVar(playerid, "td_vehicleid");
  100.     }
  101.     return 1;
  102. }
  103.  
  104. public OnPlayerConnect(playerid) {
  105.     td_BustTime[playerid] = 0;
  106.     return 1;
  107. }
  108.  
  109. public OnPlayerDisconnect(playerid, reason) {
  110.     td_BustTime[playerid] = 0;
  111.     return 1;
  112. }
  113.  
  114. public OnPlayerStateChange(playerid, newstate, oldstate) {
  115.     if(oldstate == PLAYER_STATE_DRIVER) {
  116.         td_BustTime[playerid] = 0;
  117.         DeletePVar(playerid, "td_vehicleid");
  118.     }
  119.     return 1;
  120. }
  121.  
  122. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  123.     if(PRESSED(SLOW_KEY_ID) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && !td_BustTime[playerid] && td_IsVehicleRD(GetPlayerVehicleID(playerid))) {
  124.         new
  125.             td_vehicleid = GetPlayerVehicleID(playerid);
  126.         if(!GetVehicleTireState(td_vehicleid, 2) || !GetVehicleTireState(td_vehicleid, 4)) {
  127.             td_BustTime[playerid] = 1;
  128.             SetPVarInt(playerid, "td_vehicleid", td_vehicleid);
  129.         }
  130.     }
  131.     return 1;
  132. }
  133.  
  134. td_GetVehicleSpeed(td_carid) {
  135.     new
  136.         Float: td_Velocity[3];
  137.     GetVehicleVelocity(td_carid, td_Velocity[0], td_Velocity[1], td_Velocity[2]);
  138.     return floatround(floatsqroot(td_Velocity[0] * td_Velocity[0] + td_Velocity[1] * td_Velocity[1] + td_Velocity[2] * td_Velocity[2]) * 100);
  139. }
  140.  
  141. td_IsVehicleRD(td_vehicleid) {
  142.     new
  143.         td_model = GetVehicleModel(td_vehicleid);
  144.     switch(td_model) {
  145.         case
  146.             400, 402, 403, 405, 406, 407, 408, 409, 411, 412, 413, 414, 415, 416,
  147.             418, 419, 421, 422, 423, 424, 426, 427, 428, 429, 431, 433, 434, 437,
  148.             438, 439, 442, 443, 444, 448, 451, 455, 456, 457, 458, 459, 461, 462,
  149.             463, 466, 467, 468, 470, 471, 475, 477, 478, 480, 482, 483, 485, 486,
  150.             489, 490, 491, 492, 494, 495, 498, 499, 500, 502, 503, 504, 505, 506,
  151.             507, 508, 514, 515, 517, 518, 521..529, 531, 533..536, 541..547, 549,
  152.             551, 552, 554..558, 560..562, 566..568, 571..576, 578..583, 585..588,
  153.             596..605, 609: return 1;
  154.         default:
  155.             return 0;
  156.     }
  157.     return 0;
  158. }
  159.  
  160. GetVehicleTireState(vehicleid, tireid) {
  161.     new panels, doors, lights, tires;
  162.     GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  163.     switch(tireid) {
  164.         case 1: { // FRONT LEFT
  165.             switch(tires) {
  166.                 case 0..7: return 0;
  167.                 default: return 1;
  168.             }
  169.         }
  170.         case 2: { // BACK LEFT
  171.             switch(tires) {
  172.                 case 0..3, 8..11: return 0;
  173.                 default: return 1;
  174.             }
  175.         }
  176.         case 3: { // FRONT RIGHT
  177.             switch(tires) {
  178.                 case 0, 1, 4, 5, 8, 9, 12, 13: return 0;
  179.                 default: return 1;
  180.             }
  181.         }
  182.         case 4: { // BACK RIGHT
  183.             switch(tires) {
  184.                 case 0, 2, 4, 6, 8, 10, 12, 14: return 0;
  185.                 default: return 1;
  186.             }
  187.         }
  188.         default: return -1;
  189.     }
  190.     return -1;
  191. }
  192.  
  193. SetVehicleTireState(vehicleid, tireid, tirestate) {
  194.     new panels, doors, lights, tires, tire[4], str[5];
  195.     GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
  196.     if((tirestate != 0 && tirestate != 1) || tireid < 1 || tireid > 4) return -1;
  197.     for(new i = 0; i < 4; i ++) tire[i] = GetVehicleTireState(vehicleid, i + 1);
  198.     tire[tireid - 1] = tirestate;
  199.     format(str, 5, "%i%i%i%i", tire[0], tire[1], tire[2], tire[3]);
  200.     new TireState[16][5] = {
  201.         {"0000"},
  202.         {"0001"},
  203.         {"0010"},
  204.         {"0011"},
  205.         {"0100"},
  206.         {"0101"},
  207.         {"0110"},
  208.         {"0111"},
  209.         {"1000"},
  210.         {"1001"},
  211.         {"1010"},
  212.         {"1011"},
  213.         {"1100"},
  214.         {"1101"},
  215.         {"1110"},
  216.         {"1111"}
  217.     };
  218.     new i = 0;
  219.     for(new m = sizeof(TireState) + 1; i < m; i ++) {
  220.         if(!strcmp(TireState[i], str, true, 4)) break;
  221.         if(i == sizeof(TireState)) return -1;
  222.     }
  223.     UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, i);
  224.     return 1;
  225. }
  226.  
  227. ////////////////////////////////////////////////////////////////////////////////
  228. //                      Script name: Tires Damage                             //
  229. //                      Author: Snoowker                                      //
  230. //                      Date of creation: 31-03-2012                          //
  231. //                      Skype: snoowker                                       //
  232. ////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement