Server update: 0.3a R8
#24

Quote:
Originally Posted by Kye
Dealing with individual vehicle damage elements can be a little bit tricky because they're compressed in to bits to save space.

JernejL (RedShirt) has provided an example of dealing with individual damage elements and also provided some reusable functions:

pawn Code:
const object_undamaged = 0;
const door_swinging = 1;
const door_damaged = 2;
const door_damaged_swinging = 3;
const door_fell_off = 4;
   
const windshield_crackedA = 1;
const windshield_crackedB = 2;
const windshielddestroyed = 3;

encode_lights(light1, light2, light3, light4) {
   
    return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
   
}

encode_tires(tire1, tire2, tire3, tire4) {
   
    return tire1 | (tire2 << 1) | (tire3 << 2) | (tire4 << 3);
   
}

encode_tires_bike(rear, front) {
   
    return rear | (front << 1);
   
}

#pragma unused encode_tires_bike

encode_doors(bonnet, boot, driver_door, passenger_door, behind_driver_door, behind_passenger_door) {
    #pragma unused behind_driver_door
    #pragma unused behind_passenger_door
       
    // will be modified once again, when rear doors are synced.
    return bonnet | (boot << 8) | (driver_door << 16) | (passenger_door << 24);
   
}

encode_panels(flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper) {
   
    return flp | (frp << 4) | (rlp << 8) | (rrp << 12) | (windshield << 16) | (front_bumper << 20) | (rear_bumper << 24);
   
}

breakcar(PlayerID) {
   
    if (IsPlayerInAnyVehicle(PlayerID)) {
       
        new panels, doors, lights, tires;
       
        GetVehicleDamageStatus(GetPlayerVehicleID(PlayerID), panels, doors, lights, tires);
        panels = encode_panels(1, 1, 1, 1, 3, 3, 3); // damage windshield & make bumpers swing
        doors = encode_doors(4, 4, 4, 4, 0, 0); // make them all fall off
        lights = encode_lights(1, 1, 1, 1); // damage all lights
        tires = encode_tires(1, 1, 1, 1); // damage all tires
       
        UpdateVehicleDamageStatus(GetPlayerVehicleID(PlayerID), panels, doors, lights, tires);
       
    }
   
    return true;
}

OnVehicleDamageStatusUpdate(vehicleid, playerid) {
    #pragma unused playerid
   
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
   
    new driver_door, passenger_door/ *, behind_driver_door, behind_passenger_door* / = 0;
   
    / *
    door & boot & bonnet status:
    0: undamaged
    1: swinging
    2: damaged
    3: damaged & swinging
    4: fell off
    * /
   
    driver_door = doors >> 16 & 0x7;
    passenger_door = doors >> 24 & 0x7;
   
    // other 2 doors are not yet synced.
   
    new bonnet, boot = 0;
   
    bonnet = doors & 0x7;
    boot = doors >> 8 & 0x7; // boot will not swing unless on specific car (like a bobcat)
   
    new flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper;
   
    / *
    panels are unused on cars, they are used on planes tho.
    * /
   
    flp = panels >> 0 & 0xF;
    frp = panels >> 4 & 0xF;
    rlp = panels >> 8 & 0xF;
    rrp = panels >> 12 & 0xF;
   
    / *
    windshield:
    0 undagamed
    1,2 cracked
    3: destroyed
    * /
   
    windshield = panels >> 16 & 0xF;
   
    / *
    bonnet & boot:
    0 undamaged
    1 open swinging (hood only)
    2 damaged
    3 damaged swinging
    4 fallen off
    * /
   
    front_bumper = panels >> 20 & 0xF;
    rear_bumper = panels >> 24 & 0xF;
   
    // for tires & lights: 1 damaged, 0 = ordinary
    new tyre1, tyre2, tyre3, tyre4;
   
    tyre1 = tires >> 0 & 0x1; // rear right (bike rear)
    tyre2 = tires >> 1 & 0x1; // front right (bike front)
    tyre3 = tires >> 2 & 0x1; // rear left
    tyre4 = tires >> 3 & 0x1; // front left
   
    new light1, light2, light3, light4;
   
    light1 = lights >> 0 & 0x1; // front left
    light2 = lights >> 1 & 0x1; // cant get to break rear light
    light3 = lights >> 2 & 0x1; // front right
    light4 = lights >> 3 & 0x1; // cant get to break rear light
   
    // bike lights never break!
   
    new string[128];
    format(string,sizeof(string),"Doors: Driver: %d, Passenger: %d", driver_door, passenger_door);
    SendClientMessageToAll(COLOR_RED, string);
   
    format(string,sizeof(string),"Swinging: bonnet: %d, boot: %d", bonnet, boot);
    SendClientMessageToAll(COLOR_RED, string);
   
    format(string,sizeof(string),"panels: flp: %d, frp: %d, rlp: %d, rrp: %d, windshield: %d, front bumper: %d, rear bumper: %d", flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper);
    SendClientMessageToAll(COLOR_RED, string);
   
    format(string,sizeof(string),"tires: %d %d %d %d", tyre1, tyre2, tyre3, tyre4);
    SendClientMessageToAll(COLOR_RED, string);
   
    format(string,sizeof(string),"lights: %d %d %d %d", light1, light2, light3, light4);
    SendClientMessageToAll(COLOR_RED, string);
   
    return 1;
}
Dude.., that's just an awesome update and feature! love you guys!
Reply


Messages In This Thread
Server update: 0.3a R8 - by Kalcor - 24.03.2010, 01:11
Re: Server update: 0.3a R5 - by Kalcor - 24.03.2010, 01:25
Re: Server update: 0.3a R5 - by Woet - 24.03.2010, 01:27
Re: Server update: 0.3a R5 - by Carlton - 24.03.2010, 01:31
Re: Server update: 0.3a R5 - by niCe - 24.03.2010, 01:35
Re: Server update: 0.3a R5 - by Bob_Mars - 24.03.2010, 01:45
Re: Server update: 0.3a R5 - by Hijolion - 24.03.2010, 01:50
Re: Server update: 0.3a R5 - by DaRkDeViiL - 24.03.2010, 01:54
Re: Server update: 0.3a R5 - by CJ101 - 24.03.2010, 01:57
Re: Server update: 0.3a R5 - by gotenks918 - 24.03.2010, 02:05
Re: Server update: 0.3a R5 - by Tannz0rz - 24.03.2010, 02:07
Re: Server update: 0.3a R5 - by Kalcor - 24.03.2010, 02:08
Re: Server update: 0.3a R5 - by Mr187 - 24.03.2010, 02:14
Re: Server update: 0.3a R5 - by Woet - 24.03.2010, 02:30
Re: Server update: 0.3a R5 - by Matite - 24.03.2010, 02:31
Re: Server update: 0.3a R5 - by [Saint] - 24.03.2010, 02:36
Re: Server update: 0.3a R5 - by Aygem - 24.03.2010, 02:38
Re: Server update: 0.3a R5 - by shady91 - 24.03.2010, 02:42
Re: Server update: 0.3a R5 - by Mr187 - 24.03.2010, 02:47
Re: Server update: 0.3a R5 - by cyber_punk - 24.03.2010, 02:47
Re: Server update: 0.3a R5 - by CracK - 24.03.2010, 03:34
Re: Server update: 0.3a R5 - by deather - 24.03.2010, 03:37
Re: Server update: 0.3a R5 - by Norn - 24.03.2010, 03:51
Re: Server update: 0.3a R5 - by FujiNNN - 24.03.2010, 04:28
Re: Server update: 0.3a R5 - by Tenshi - 24.03.2010, 04:52
Re: Server update: 0.3a R5 - by Calgon - 24.03.2010, 05:02
Re: Server update: 0.3a R5 - by CracK - 24.03.2010, 05:35
Re: Server update: 0.3a R5 - by Calgon - 24.03.2010, 05:40
Re: Server update: 0.3a R5 - by Finn - 24.03.2010, 05:42
Re: Server update: 0.3a R5 - by CracK - 24.03.2010, 06:03
Re: Server update: 0.3a R5 - by DarkPower - 24.03.2010, 22:34
Re: Server update: 0.3a R5 - by Chaprnks - 24.03.2010, 23:01
Re: Server update: 0.3a R5 - by ruarai - 24.03.2010, 23:08
Re: Server update: 0.3a R5 - by MX_Master - 25.03.2010, 03:50
Re: Server update: 0.3a R5 - by Simon - 25.03.2010, 08:04
Re: Server update: 0.3a R5 - by Whitetiger - 25.03.2010, 09:25
Re: Server update: 0.3a R5 - by Brian_Furios - 25.03.2010, 13:05
Re: Server update: 0.3a R5 - by Correlli - 25.03.2010, 13:18
Re: Server update: 0.3a R5 - by Brian_Furios - 25.03.2010, 13:35
Re: Server update: 0.3a R5 - by Vandooz - 25.03.2010, 14:09
Re: Server update: 0.3a R5 - by Maccer - 26.03.2010, 21:35
Re: Server update: 0.3a R5 - by Maccer - 26.03.2010, 21:48
Re: Server update: 0.3a R5 - by Sergei - 26.03.2010, 22:27
Re: Server update: 0.3a R5 - by Kalcor - 26.03.2010, 22:28
Re: Server update: 0.3a R5 - by Correlli - 26.03.2010, 22:30
Re: Server update: 0.3a R5 - by Extremo - 27.03.2010, 01:30
Re: Server update: 0.3a R6 - by whooper - 27.03.2010, 02:35
Re: Server update: 0.3a R6 - by Simon - 27.03.2010, 02:45
Re: Server update: 0.3a R6 - by Whitetiger - 27.03.2010, 02:59
Re: Server update: 0.3a R6 - by CC. - 27.03.2010, 04:14
Re: Server update: 0.3a R7 - by Maccer - 28.03.2010, 13:05
Re: Server update: 0.3a R7 - by Correlli - 28.03.2010, 13:06
Re: Server update: 0.3a R7 - by IDownload - 28.03.2010, 13:06
Re: Server update: 0.3a R7 - by Geso - 28.03.2010, 13:08
Re: Server update: 0.3a R7 - by Correlli - 28.03.2010, 13:12
Re: Server update: 0.3a R7 - by Kalcor - 28.03.2010, 13:16
Re: Server update: 0.3a R7 - by Geso - 28.03.2010, 13:19
Re: Server update: 0.3a R7 - by xcasio - 28.03.2010, 14:24
Re: Server update: 0.3a R7 - by Sergei - 28.03.2010, 14:53
Re: Server update: 0.3a R7 - by Dark_Kostas - 28.03.2010, 16:06
Re: Server update: 0.3a R7 - by Spik3 - 28.03.2010, 23:18
Re: Server update: 0.3a R7 - by Sim00n - 29.03.2010, 03:12
Re: Server update: 0.3a R7 - by MPKaboose - 29.03.2010, 12:59
Re: Server update: 0.3a R7 - by BeckzyBoi - 29.03.2010, 13:38
Re: Server update: 0.3a R7 - by Mikep. - 29.03.2010, 13:43
Re: Server update: 0.3a R7 - by xenowort - 29.03.2010, 16:57
Re: Server update: 0.3a R7 - by Sim00n - 29.03.2010, 21:33
Re: Server update: 0.3a R7 - by damianxb - 29.03.2010, 21:52
Re: Server update: 0.3a R7 - by Mikep. - 30.03.2010, 00:18
Re: Server update: 0.3a R7 - by yezizhu - 30.03.2010, 01:23
Re: Server update: 0.3a R7 - by ev0lution - 30.03.2010, 01:48
Re: Server update: 0.3a R7 - by Google63 - 30.03.2010, 08:30
Re: Server update: 0.3a R7 - by Panoulis - 30.03.2010, 10:35
Re: Server update: 0.3a R7 - by bajskorv123 - 31.03.2010, 17:28
Re: Server update: 0.3a R7 - by Correlli - 31.03.2010, 17:47
Re: Server update: 0.3a R7 - by wafffllesss - 31.03.2010, 17:49
Re: Server update: 0.3a R7 - by Krozz - 02.04.2010, 15:43
Re: Server update: 0.3a R7 - by Mikep. - 02.04.2010, 15:51
Re: Server update: 0.3a R7 - by Zlayer - 02.04.2010, 20:33
Re: Server update: 0.3a R7 - by Krozz - 02.04.2010, 23:53
Re: Server update: 0.3a R7 - by [03]Garsino - 02.04.2010, 23:55
Re: Server update: 0.3a R7 - by XGh0stz - 03.04.2010, 02:06
Re: Server update: 0.3a R7 - by Toribio - 03.04.2010, 06:21
Re: Server update: 0.3a R7 - by XGh0stz - 03.04.2010, 08:25
Re: Server update: 0.3a R7 - by oggylt - 06.04.2010, 13:06
Re: Server update: 0.3a R7 - by pspleo - 06.04.2010, 13:37
Re: Server update: 0.3a R7 - by XGh0stz - 06.04.2010, 17:29
Re: Server update: 0.3a R7 - by Tannz0rz - 06.04.2010, 17:33
Re: Server update: 0.3a R7 - by oggylt - 07.04.2010, 14:43
Re: Server update: 0.3a R7 - by XGh0stz - 07.04.2010, 15:43
Re: Server update: 0.3a R7 - by oggylt - 07.04.2010, 16:20
Re: Server update: 0.3a R7 - by XGh0stz - 11.04.2010, 06:10
Re: Server update: 0.3a R7 - by biltong - 11.04.2010, 10:47
Re: Server update: 0.3a R7 - by Dark_Kostas - 11.04.2010, 15:37
Re: Server update: 0.3a R7 - by Joe Staff - 11.04.2010, 16:32
Re: Server update: 0.3a R7 - by XGh0stz - 11.04.2010, 19:00
Re: Server update: 0.3a R7 - by [03]Garsino - 11.04.2010, 19:05
Re: Server update: 0.3a R7 - by biltong - 12.04.2010, 16:34
Re: Server update: 0.3a R7 - by shady91 - 12.04.2010, 16:39
Re: Server update: 0.3a R7 - by [JIeXa] - 13.04.2010, 14:15
Re: Server update: 0.3a R8 - by [03]Garsino - 22.06.2010, 14:40
Re: Server update: 0.3a R8 - by matthewdriftking - 22.06.2010, 14:51
Re: Server update: 0.3a R8 - by [03]Garsino - 22.06.2010, 14:55
Re: Server update: 0.3a R8 - by Panorama_ - 22.06.2010, 15:11
Re: Server update: 0.3a R8 - by Correlli - 22.06.2010, 15:35
Re: Server update: 0.3a R8 - by Littl3j0hNy - 22.06.2010, 15:40
Re: Server update: 0.3a R8 - by Pawno_Scripter - 22.06.2010, 17:18
Re: Server update: 0.3a R8 - by OKStyle - 22.06.2010, 18:13
Re: Server update: 0.3a R8 - by Trooper[Y] - 22.06.2010, 19:07
Re: Server update: 0.3a R8 - by Kar - 22.06.2010, 22:00
Re: Server update: 0.3a R8 - by Scenario - 23.06.2010, 01:40
Re: Server update: 0.3a R8 - by W00Z - 23.06.2010, 12:18
Re: Server update: 0.3a R8 - by Calgon - 24.06.2010, 03:32
Re: Server update: 0.3a R8 - by Killa[DGZ] - 24.06.2010, 11:36
Re: Server update: 0.3a R8 - by HydraX - 05.07.2010, 20:47
Re: Server update: 0.3a R8 - by Calgon - 05.07.2010, 20:53
Re: Server update: 0.3a R8 - by HydraX - 05.07.2010, 21:28
Re: Server update: 0.3a R8 - by TheGuardianAngel - 22.07.2010, 14:11
Re: Server update: 0.3a R8 - by Maggi - 25.07.2010, 16:31
Re: Server update: 0.3a R8 - by ikey07 - 30.07.2010, 09:18
Re: Server update: 0.3a R8 - by GaGlets(R) - 30.07.2010, 19:53
Re: Server update: 0.3a R8 - by jiggy89 - 09.08.2010, 19:04
Re: Server update: 0.3a R8 - by [NoV]LaZ - 09.08.2010, 19:56
Re: Server update: 0.3a R8 - by gamer931215 - 11.08.2010, 08:55
Re: Server update: 0.3a R8 - by Kwarde - 31.10.2010, 15:12
Re: Server update: 0.3a R8 - by bigcomfycouch - 31.10.2010, 15:36

Forum Jump:


Users browsing this thread: 1 Guest(s)