fire2.inc 5.5 KB

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