Advertisement
ploxarik

OnPlayerWeaponShot

Mar 10th, 2021
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 1.69 KB | None | 0 0
  1. /*
  2.     BULLET_HIT_TYPE_NONE //called if the player does not shoot.
  3.     BULLET_HIT_TYPE_PLAYER //called if the player shoots the player.
  4.     BULLET_HIT_TYPE_VEHICLE //called if the player shoots a car.
  5.     BULLET_HIT_TYPE_OBJECT //called if the player shoots an object.
  6.     BULLET_HIT_TYPE_PLAYER_OBJECT //called if the player shoots the created object.
  7. */
  8.  
  9.  
  10. new ObjectHP[MAX_OBJECTS];
  11.  
  12. public OnGameModeInit()
  13. {
  14.     //We reset the hp.
  15.     for(new i; i< MAX_OBJECTS; i++) ObjectHP[i] = 0;
  16.     CreateObject(18848, 1450.59, -2446.57, 12.50,   0.00, 0.00, 0.00);
  17.     CreateObject(18848, 1442.11, -2444.87, 12.55,   0.00, 0.00, 0.00);
  18.     CreateObject(18848, 1461.18, -2446.89, 12.54,   0.00, 0.00, 0.00);
  19.     CreateObject(18848, 1457.31, -2430.67, 12.54,   0.00, 0.00, 0.00);
  20.     CreateObject(18848, 1449.48, -2430.51, 12.54,   0.00, 0.00, 0.00);
  21.     //HP setting.
  22.     for(new i; i< MAX_OBJECTS; i++)
  23.     {
  24.          if(!IsValidObject(i)) continue; //If the object is not working
  25.          ObjectHP[i] = 100; //100 hp for faster destruction.
  26.     }
  27.     return 1;
  28.  
  29. }
  30.  
  31. public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
  32. {
  33.     if(hittype == BULLET_HIT_TYPE_OBJECT) //In case the player hits the object
  34.     {
  35.         if(IsValidObject(hitid))
  36.         {
  37.             ObjectHP[hitid] -= random(10) + 1;
  38.             if(ObjectHP[hitid] >= 0)
  39.             {
  40.                 new str[128];
  41.                 format(str, sizeof(str), "~G~OBJECT DAMAGED!~N~~Y~OBJECT ID ~W~: ~R~ %d~N~~Y~HP LEFT ~W~: ~R~        
  42.                %d",hitid,ObjectHP[hitid]);
  43.             }
  44.             if(ObjectHP[hitid] <= 0)
  45.             {
  46.                 DestroyObject(hitid);
  47.             }
  48.         }
  49.     }
  50.     return 1;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement