Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////////////////////////////////////////////////////
- // Script name: Tires Damage //
- // Author: Snoowker //
- // Date of creation: 31-03-2012 01:54 //
- // Skype: snoowker //
- ////////////////////////////////////////////////////////////////////////////////
- #include <a_samp>
- #define PRESSED(%0) \
- (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- //------------------------------------------------------------------------------
- // Congiguration (RECOMMENDED!)
- #define MIN_SLOW_TIME 20
- #define MAX_SLOW_TIME 40
- #define MAX_SLOW_SPEED 7
- #define SLOW_KEY_ID 40
- #define TIMER_DURATION 1
- //------------------------------------------------------------------------------
- new
- td_BustTime[MAX_PLAYERS],
- td_TimerID;
- public OnFilterScriptInit() {
- for(new td_i = 0, td_m = GetMaxPlayers(); td_i < td_m; td_i ++) {
- td_BustTime[td_i] = 0;
- DeletePVar(td_i, "td_vehicleid");
- }
- td_TimerID = SetTimer("td_CheckTires", TIMER_DURATION * 1000, 1);
- print("Tires Damage script by Snoowker successfully loaded!");
- return 1;
- }
- public OnFilterScriptExit() {
- for(new td_i = 0, td_m = GetMaxPlayers(); td_i < td_m; td_i ++) {
- td_BustTime[td_i] = 0;
- DeletePVar(td_i, "td_vehicleid");
- }
- KillTimer(td_TimerID);
- print("Tires Damage script by Snoowker successfully unloaded!");
- return 1;
- }
- forward td_CheckTires();
- public td_CheckTires() {
- new
- td_Keys,
- td_ud,
- td_lr,
- td_vehicleid,
- td_NeedTimeToDamage,
- td_state[2];
- for(new td_i = 0, td_m = GetMaxPlayers(); td_i < td_m; td_i ++) {
- if(!IsPlayerConnected(td_i) || GetPlayerState(td_i) != PLAYER_STATE_DRIVER || td_BustTime[td_i] == 0) continue;
- td_vehicleid = GetPlayerVehicleID(td_i);
- if(td_vehicleid != GetPVarInt(td_i, "td_vehicleid")) {
- td_BustTime[td_i] = 0;
- DeletePVar(td_i, "td_vehicleid");
- continue;
- }
- GetPlayerKeys(td_i, td_Keys, td_ud, td_lr);
- if(!(td_Keys & SLOW_KEY_ID || td_Keys == SLOW_KEY_ID)) {
- td_BustTime[td_i] = 0;
- DeletePVar(td_i, "td_vehicleid");
- continue;
- }
- td_state[0] = GetVehicleTireState(td_vehicleid, 2);
- td_state[1] = GetVehicleTireState(td_vehicleid, 4);
- if(td_state[0] && td_state[1]) continue;
- if(td_GetVehicleSpeed(td_vehicleid) >= MAX_SLOW_SPEED) continue;
- td_BustTime[td_i] += TIMER_DURATION;
- td_NeedTimeToDamage = MIN_SLOW_TIME + random(MAX_SLOW_TIME - MIN_SLOW_TIME + 1);
- if(td_BustTime[td_i] >= td_NeedTimeToDamage) {
- if(!random(2) && !td_state[0]) {
- SetVehicleTireState(td_vehicleid, 2, 1);
- }
- else {
- SetVehicleTireState(td_vehicleid, 4, 1);
- }
- }
- }
- return 1;
- }
- public OnVehicleDamageStatusUpdate(vehicleid, playerid) {
- new
- td_Keys,
- td_ud,
- td_lr;
- GetPlayerKeys(playerid, td_Keys, td_ud, td_lr);
- if((!GetVehicleTireState(vehicleid, 2) || !GetVehicleTireState(vehicleid, 4)) && vehicleid == GetPVarInt(playerid, "td_vehicleid") && (td_Keys & SLOW_KEY_ID || td_Keys == SLOW_KEY_ID)) {
- td_BustTime[playerid] = (MIN_SLOW_TIME + MAX_SLOW_TIME) / 5;
- SetPVarInt(playerid, "td_vehicleid", vehicleid);
- }
- else if(GetVehicleTireState(vehicleid, 2) && GetVehicleTireState(vehicleid, 4)) {
- td_BustTime[playerid] = 0;
- DeletePVar(playerid, "td_vehicleid");
- }
- return 1;
- }
- public OnPlayerConnect(playerid) {
- td_BustTime[playerid] = 0;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason) {
- td_BustTime[playerid] = 0;
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate) {
- if(oldstate == PLAYER_STATE_DRIVER) {
- td_BustTime[playerid] = 0;
- DeletePVar(playerid, "td_vehicleid");
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
- if(PRESSED(SLOW_KEY_ID) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER && !td_BustTime[playerid] && td_IsVehicleRD(GetPlayerVehicleID(playerid))) {
- new
- td_vehicleid = GetPlayerVehicleID(playerid);
- if(!GetVehicleTireState(td_vehicleid, 2) || !GetVehicleTireState(td_vehicleid, 4)) {
- td_BustTime[playerid] = 1;
- SetPVarInt(playerid, "td_vehicleid", td_vehicleid);
- }
- }
- return 1;
- }
- td_GetVehicleSpeed(td_carid) {
- new
- Float: td_Velocity[3];
- GetVehicleVelocity(td_carid, td_Velocity[0], td_Velocity[1], td_Velocity[2]);
- return floatround(floatsqroot(td_Velocity[0] * td_Velocity[0] + td_Velocity[1] * td_Velocity[1] + td_Velocity[2] * td_Velocity[2]) * 100);
- }
- td_IsVehicleRD(td_vehicleid) {
- new
- td_model = GetVehicleModel(td_vehicleid);
- switch(td_model) {
- case
- 400, 402, 403, 405, 406, 407, 408, 409, 411, 412, 413, 414, 415, 416,
- 418, 419, 421, 422, 423, 424, 426, 427, 428, 429, 431, 433, 434, 437,
- 438, 439, 442, 443, 444, 448, 451, 455, 456, 457, 458, 459, 461, 462,
- 463, 466, 467, 468, 470, 471, 475, 477, 478, 480, 482, 483, 485, 486,
- 489, 490, 491, 492, 494, 495, 498, 499, 500, 502, 503, 504, 505, 506,
- 507, 508, 514, 515, 517, 518, 521..529, 531, 533..536, 541..547, 549,
- 551, 552, 554..558, 560..562, 566..568, 571..576, 578..583, 585..588,
- 596..605, 609: return 1;
- default:
- return 0;
- }
- return 0;
- }
- GetVehicleTireState(vehicleid, tireid) {
- new panels, doors, lights, tires;
- GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
- switch(tireid) {
- case 1: { // FRONT LEFT
- switch(tires) {
- case 0..7: return 0;
- default: return 1;
- }
- }
- case 2: { // BACK LEFT
- switch(tires) {
- case 0..3, 8..11: return 0;
- default: return 1;
- }
- }
- case 3: { // FRONT RIGHT
- switch(tires) {
- case 0, 1, 4, 5, 8, 9, 12, 13: return 0;
- default: return 1;
- }
- }
- case 4: { // BACK RIGHT
- switch(tires) {
- case 0, 2, 4, 6, 8, 10, 12, 14: return 0;
- default: return 1;
- }
- }
- default: return -1;
- }
- return -1;
- }
- SetVehicleTireState(vehicleid, tireid, tirestate) {
- new panels, doors, lights, tires, tire[4], str[5];
- GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
- if((tirestate != 0 && tirestate != 1) || tireid < 1 || tireid > 4) return -1;
- for(new i = 0; i < 4; i ++) tire[i] = GetVehicleTireState(vehicleid, i + 1);
- tire[tireid - 1] = tirestate;
- format(str, 5, "%i%i%i%i", tire[0], tire[1], tire[2], tire[3]);
- new TireState[16][5] = {
- {"0000"},
- {"0001"},
- {"0010"},
- {"0011"},
- {"0100"},
- {"0101"},
- {"0110"},
- {"0111"},
- {"1000"},
- {"1001"},
- {"1010"},
- {"1011"},
- {"1100"},
- {"1101"},
- {"1110"},
- {"1111"}
- };
- new i = 0;
- for(new m = sizeof(TireState) + 1; i < m; i ++) {
- if(!strcmp(TireState[i], str, true, 4)) break;
- if(i == sizeof(TireState)) return -1;
- }
- UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, i);
- return 1;
- }
- ////////////////////////////////////////////////////////////////////////////////
- // Script name: Tires Damage //
- // Author: Snoowker //
- // Date of creation: 31-03-2012 //
- // Skype: snoowker //
- ////////////////////////////////////////////////////////////////////////////////
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement