1
0

fire.inc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. ///****************************************************************************//
  2. /* Fire-Script
  3. by
  4. Sniperwolfes
  5. */
  6. //****************************************************************************//
  7. #include <a_samp>
  8. #include <streamer>
  9. //======================================
  10. #define Labels // 3D Labels above the Fires showing the Health?
  11. #define LoseHealth // Should Players and Vehicles lose Health if they stand in the fire?
  12. //======================================
  13. #define Holding(%0) \
  14. ((newkeys & (%0)) == (%0))
  15. #define MaxFire 80 // How many fires max.?
  16. forward OnFireKill(ID, killerid);
  17. forward f_OnPlayerUpdate(playerid);
  18. forward VehicleToPoint(Float:radi, vehicleid, Float:x, Float:y, Float:z);
  19. forward HealthDown();
  20. forward f_init();
  21. public f_init()
  22. {
  23. #if defined LoseHealth
  24. SetTimer("HealthDown", 600, 1);
  25. #endif
  26. }
  27. new
  28. FireObj[MaxFire],
  29. Float:FirePos[MaxFire][3],
  30. TotalFires = 0,
  31. FireHealth[MaxFire],
  32. FireHealthMax[MaxFire];
  33. #if defined Labels
  34. new Text3D:FireText[MaxFire];
  35. #endif
  36. stock AddFire(Float:x, Float:y, Float:z, Health)
  37. {
  38. TotalFires++;
  39. new ID = TotalFires;
  40. FireObj[ID] = CreateDynamicObject(18691, x, y, z-2.61, 0, 0, 0.0);
  41. FirePos[ID][0] = x, FirePos[ID][1] = y, FirePos[ID][2] = z;
  42. FireHealth[ID] = Health;
  43. FireHealthMax[ID] = Health;
  44. #if defined Labels
  45. new string[128];
  46. format(string, sizeof(string), "%d/%d", FireHealth[ID], FireHealthMax[ID]);
  47. FireText[ID] = Create3DTextLabel(string, 0xFFFFFFFFF, x, y, z, 20, 0);
  48. #endif
  49. }
  50. stock DeleteFire(ID)
  51. {
  52. DestroyDynamicObject(FireObj[ID]);
  53. TotalFires--;
  54. FirePos[ID][0] = 0, FirePos[ID][1] = 0, FirePos[ID][2] = 0;
  55. #if defined Labels
  56. Delete3DTextLabel(FireText[ID]);
  57. #endif
  58. }
  59. stock DeleteAllFire()
  60. {
  61. new ID;
  62. for(ID = 0; ID<MaxFire; ID++)
  63. {
  64. DestroyDynamicObject(FireObj[ID]);
  65. TotalFires= 0;
  66. FirePos[ID][0] = 0, FirePos[ID][1] = 0, FirePos[ID][2] = 0;
  67. #if defined Labels
  68. Delete3DTextLabel(FireText[ID]);
  69. #endif
  70. }
  71. }
  72. stock IsValidFire(ID)
  73. {
  74. if( (FirePos[ID][0] != 0) && (FirePos[ID][1] != 0) && (FirePos[ID][2] != 0) ) return true;
  75. else return false;
  76. }
  77. stock GetClosestFire(playerid)
  78. {
  79. new i;
  80. for(i = 0; i<MaxFire; i++)
  81. {
  82. if(IsValidFire(i) && IsPlayerInRangeOfPoint(playerid, 1, FirePos[i][0], FirePos[i][1], FirePos[i][2]))
  83. {
  84. return i;
  85. }
  86. }
  87. return 0;
  88. }
  89. public f_OnPlayerUpdate(playerid)
  90. {
  91. new newkeys,l,u;
  92. GetPlayerKeys(playerid, newkeys, l, u);
  93. new i;
  94. if(Holding(KEY_FIRE))
  95. {
  96. if(GetPlayerWeapon(playerid) == 42)
  97. {
  98. for(i = 0; i<MaxFire; i++)
  99. {
  100. if(IsValidFire(i))
  101. {
  102. if(PlayerFaces(playerid, FirePos[i][0], FirePos[i][1], FirePos[i][2], 1) && IsPlayerInRangeOfPoint(playerid, 4, FirePos[i][0], FirePos[i][1], FirePos[i][2]))
  103. {
  104. FireHealth[i]-=2;
  105. #if defined Labels
  106. new string[128];
  107. format(string, sizeof(string), "%d/%d", FireHealth[i], FireHealthMax[i]);
  108. Update3DTextLabelText(FireText[i], 0xFFFFFFFF, string);
  109. //Delete3DTextLabel(FireText[i]);
  110. //FireText[i] = Create3DTextLabel(string, 0xFFFFFFFF, FirePos[i][0], FirePos[i][1], FirePos[i][2], 20, 0);
  111. #endif
  112. if(FireHealth[i] <= 0)
  113. {
  114. DeleteFire(i);
  115. CallRemoteFunction("OnFireDeath", "dd", i, playerid);
  116. }
  117. }
  118. }
  119. }
  120. }
  121. }
  122. return 1;
  123. }
  124. Float:DistanceCameraTargetToLocation(Float:CamX, Float:CamY, Float:CamZ, Float:ObjX, Float:ObjY, Float:ObjZ, Float:FrX, Float:FrY, Float:FrZ) {
  125. new Float:TGTDistance;
  126. TGTDistance = floatsqroot((CamX - ObjX) * (CamX - ObjX) + (CamY - ObjY) * (CamY - ObjY) + (CamZ - ObjZ) * (CamZ - ObjZ));
  127. new Float:tmpX, Float:tmpY, Float:tmpZ;
  128. tmpX = FrX * TGTDistance + CamX;
  129. tmpY = FrY * TGTDistance + CamY;
  130. tmpZ = FrZ * TGTDistance + CamZ;
  131. return floatsqroot((tmpX - ObjX) * (tmpX - ObjX) + (tmpY - ObjY) * (tmpY - ObjY) + (tmpZ - ObjZ) * (tmpZ - ObjZ));
  132. }
  133. stock PlayerFaces(playerid, Float:x, Float:y, Float:z, Float:radius)
  134. {
  135. new Float:cx,Float:cy,Float:cz,Float:fx,Float:fy,Float:fz;
  136. GetPlayerCameraPos(playerid, cx, cy, cz);
  137. GetPlayerCameraFrontVector(playerid, fx, fy, fz);
  138. return (radius >= DistanceCameraTargetToLocation(cx, cy, cz, x, y, z, fx, fy, fz));
  139. }
  140. public VehicleToPoint(Float:radi, vehicleid, Float:x, Float:y, Float:z)
  141. {
  142. new Float:oldposx, Float:oldposy, Float:oldposz;
  143. new Float:tempposx, Float:tempposy, Float:tempposz;
  144. GetVehiclePos(vehicleid, oldposx, oldposy, oldposz);
  145. tempposx = (oldposx -x);
  146. tempposy = (oldposy -y);
  147. tempposz = (oldposz -z);
  148. //printf("DEBUG: X:%f Y:%f Z:%f",posx,posy,posz);
  149. if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
  150. {
  151. return 1;
  152. }
  153. return 0;
  154. }
  155. public HealthDown()
  156. {
  157. new i,v,p;
  158. for(i = 0; i<MaxFire; i++)
  159. {
  160. if(IsValidFire(i))
  161. {
  162. for(p = 0; p<MAX_PLAYERS; p++)
  163. {
  164. if(IsPlayerInRangeOfPoint(p, 1, FirePos[i][0], FirePos[i][1], FirePos[i][2]) && !IsPlayerInAnyVehicle(p))
  165. {
  166. new Float:HP;
  167. GetPlayerHealth(p, HP);
  168. SetPlayerHealth(p, HP-4);
  169. }
  170. }
  171. for(v = 0; v<MAX_VEHICLES; v++)
  172. {
  173. if(VehicleToPoint(2, v, FirePos[i][0], FirePos[i][1], FirePos[i][2]))
  174. {
  175. new Float:HP;
  176. GetVehicleHealth(v, HP);
  177. SetVehicleHealth(v, HP-30);
  178. }
  179. }
  180. }
  181. }
  182. }