Advertisement
Johurt

[Fix] Trailer Death

Sep 24th, 2014
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.48 KB | None | 0 0
  1. #define MAX_TRAILERS 10
  2.  
  3. new TrailerID[MAX_TRAILERS] = {INVALID_VEHICLE_ID, ...},
  4.     TrailerNum[MAX_VEHICLES] = {-1, ...};
  5.  
  6. stock j_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
  7. {
  8.     new vehicleid = CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
  9.     switch(modelid)
  10.     {
  11.         case 435, 450, 584, 591, 606, 607, 608, 610, 611:
  12.             {
  13.                 new bool:f;
  14.                 for(new c; c < MAX_TRAILERS; c++)
  15.                 {
  16.                         if(TrailerID[c] == INVALID_VEHICLE_ID)
  17.                         {
  18.                             TrailerID[c] = vehicleid;
  19.                             TrailerNum[vehicleid] = c;
  20.                             f = true;
  21.                             break;
  22.                 }
  23.                 }
  24.                 if(!f) print("Increase MAX_TRAILERS value!");
  25.             }
  26.     }
  27.     return vehicleid;
  28. }
  29. #define CreateVehicle j_CreateVehicle
  30.  
  31. stock j_DestroyVehicle(vehicleid)
  32. {
  33.     switch(GetVehicleModel(vehicleid))
  34.     {
  35.         case 435, 450, 584, 591, 606, 607, 608, 610, 611:
  36.             {
  37.                 TrailerID[TrailerNum[vehicleid]] = INVALID_VEHICLE_ID;
  38.             TrailerNum[vehicleid] = -1;
  39.             }
  40.     }
  41.     return 1;
  42. }
  43. #define DestroyVehicle j_DestroyVehicle
  44.  
  45. public OnGameModeInit()
  46. {
  47.     SetTimer("CheckTrailers", 200, true);
  48.     CreateVehicle(435,1626.2261,-1305.7869,17.5208,279.3670,19,50, -1); // tr1
  49.     CreateVehicle(435,1644.1757,-1300.4391,16.1890,230.2410,102,6, -1); // tr2
  50.     CreateVehicle(435,1607.9326,-1300.4973,17.9331,173.2703,91,47, -1); // tr3
  51.     return 1;
  52. }
  53.  
  54. forward CheckTrailers();
  55. public CheckTrailers()
  56. {
  57.     new Float:tHP, trailerid;
  58.         for(new c; c < MAX_TRAILERS; c++)
  59.     {
  60.         trailerid = TrailerID[c];
  61.             if(trailerid == INVALID_VEHICLE_ID) continue;
  62.             GetVehicleHealth(trailerid, tHP);
  63.             if(tHP < 250)
  64.             {
  65.                 CallLocalFunction("OnVehicleDeath", "dd", trailerid, INVALID_PLAYER_ID);
  66.             }
  67.     }
  68.     return 1;
  69. }
  70.  
  71. public OnVehicleDeath(vehicleid, killerid)
  72. {
  73.         switch(GetVehicleModel(vehicleid))
  74.     {
  75.         case 435, 450, 584, 591, 606, 607, 608, 610, 611:
  76.             {
  77.                 new str[32];
  78.             format(str, 32, "OnVehicleDeath: TrailerID: %d", vehicleid);
  79.             SendClientMessageToAll(-1, str);
  80.             SetVehicleToRespawn(vehicleid);
  81.         }
  82.     }
  83.     return 1;
  84. }
  85.  
  86. public OnPlayerCommandText(playerid, cmdtext[])
  87. {
  88.     if(!strcmp("/f", cmdtext, true, 2))
  89.     {
  90.         new trailerid;
  91.         for(new c; c < MAX_TRAILERS; c++)
  92.         {
  93.             trailerid = TrailerID[c];
  94.             if(trailerid == INVALID_VEHICLE_ID) continue;
  95.             SetVehicleHealth(trailerid, 249);
  96.         }
  97.         return 1;
  98.     }
  99.     return 1;
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement