damage.inc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <YSI_Coding\y_hooks>
  2. forward OnVehicleWrecked(vehicleid);
  3. static bool:Wrecked[MAX_VEHICLES];
  4. task OnVehicleUpdate[1500]()
  5. {
  6. foreach(new i : Vehicle)
  7. {
  8. new Float:health;
  9. GetVehicleHealth(i, health);
  10. if(health < 300 && Wrecked[i] == false)
  11. {
  12. OnVehicleWrecked(i);
  13. }
  14. }
  15. }
  16. public OnVehicleWrecked(vehicleid)
  17. {
  18. Wrecked[vehicleid] = true;
  19. SetVehicleHealth(vehicleid, 300);
  20. if(IsEngineVehicle(vehicleid))
  21. {
  22. new engine, lights, alarm, doors, bonnet, boot, objective;
  23. GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
  24. SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
  25. }
  26. foreach(new i : Player)
  27. {
  28. if(IsPlayerInVehicle(i, vehicleid) && GetPlayerVehicleSeat(i) == 0)
  29. {
  30. va_SendClientMessage(i, 0xFF6666FF, "> This vehicle (%s) is now badly damaged, the engine has stopped working.", GetVehicleName(vehicleid));
  31. break;
  32. }
  33. }
  34. return 1;
  35. }
  36. hook OnVehicleCreated(vehicleid)
  37. {
  38. Wrecked[vehicleid] = false;
  39. }
  40. hook OnVehicleSpawn(vehicleid)
  41. {
  42. Wrecked[vehicleid] = false;
  43. }
  44. hook OnPlayerShotVehicle(playerid, vehicleid, weaponid)
  45. {
  46. if(Wrecked[vehicleid] == false && IsEngineVehicle(vehicleid))
  47. {
  48. new Float:health;
  49. GetVehicleHealth(vehicleid, health);
  50. switch(weaponid)
  51. {
  52. case 0:
  53. {
  54. if(health > 310) SetVehicleHealth(vehicleid, health-10);
  55. else OnVehicleWrecked(vehicleid);
  56. }
  57. case 24, 25, 33, 34:
  58. {
  59. if(health > 420) SetVehicleHealth(vehicleid, health-120);
  60. else OnVehicleWrecked(vehicleid);
  61. }
  62. case 22, 23, 30, 31, 28, 29, 32:
  63. {
  64. if(health > 330) SetVehicleHealth(vehicleid, health-30);
  65. else OnVehicleWrecked(vehicleid);
  66. }
  67. }
  68. }
  69. }
  70. stock SetVehicleWrecked(vehicleid, bool:status)
  71. {
  72. Wrecked[vehicleid] = status;
  73. }
  74. stock IsVehicleWrecked(vehicleid)
  75. {
  76. if(Wrecked[vehicleid])
  77. {
  78. return true;
  79. }
  80. return false;
  81. }