Guest User

Sniperwolfes Fire-Script

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