Advertisement
Guest User

thefiresystem Include

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