utils.inc 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. stock ClearChat(playerid)
  2. {
  3. for(new i; i < 20; i++) SendClientMessage(playerid, -1, " ");
  4. }
  5. stock bool:IsPlayerFacingPoint(playerid, Float:x, Float:y, Float:range = 10.0)
  6. {
  7. new Float:posX, Float:posY, Float:posZ;
  8. GetPlayerPos(playerid, posX, posY, posZ);
  9. new Float:facing;
  10. GetPlayerFacingAngle(playerid, facing);
  11. new Float:angle;
  12. if(posY > y ) angle = (-acos((posX - x) / floatsqroot((posX - x)*(posX - x) + (posY - y)*(posY - y))) - 90.0);
  13. else if( posY < y && posX < x ) angle = (acos((posX - x) / floatsqroot((posX - x)*(posX - x) + (posY - y)*(posY - y))) - 450.0);
  14. else if( posY < y ) angle = (acos((posX - x) / floatsqroot((posX - x)*(posX - x) + (posY - y)*(posY - y))) - 90.0);
  15. return (IsAngleInRangeOfAngle(-angle, facing, range));
  16. }
  17. stock bool:IsPlayerDoingAnimation(playerid)
  18. {
  19. if(GetPlayerSpecialAction(playerid) != 0) return true;
  20. switch(GetPlayerAnimationIndex(playerid))
  21. {
  22. case 454..471, 899..915, 1181..1183, 1185..1189, 1192, 1222..1235, 1249, 1256..1258, 1260..1272, 1275..1287, 1382..1386: return false;
  23. }
  24. return true;
  25. }
  26. stock bool:IsPlayerNearPlayer(playerid, targetid, Float:radius)
  27. {
  28. new Float:x, Float:y, Float:z;
  29. GetPlayerPos(playerid, x, y, z);
  30. new matchingVW = GetPlayerVirtualWorld(playerid) == GetPlayerVirtualWorld(targetid);
  31. new matchingInt = GetPlayerInterior(playerid) == GetPlayerInterior(targetid);
  32. new inRange = IsPlayerInRangeOfPoint(targetid, radius, x, y, z);
  33. return matchingVW && matchingInt && inRange;
  34. }
  35. stock bool:IsPlayerNearActor(playerid, actorid, Float:radius)
  36. {
  37. if(!Iter_Contains(StreamedActor[playerid], actorid)) return false;
  38. new Float:actorX, Float:actorY, Float:actorZ;
  39. GetActorPos(actorid, actorX, actorY, actorZ);
  40. if(!IsPlayerInRangeOfPoint(playerid, radius, actorX, actorY, actorZ)) return false;
  41. return true;
  42. }
  43. stock GetClosestActor(playerid, Float:range = FLOAT_INFINITY)
  44. {
  45. new Float:thisDist;
  46. new Float:actorX, Float:actorY, Float:actorZ;
  47. new Float:closestDist = FLOAT_INFINITY;
  48. new closestActor = INVALID_ACTOR_ID;
  49. foreach(new i : StreamedActor[playerid])
  50. {
  51. GetActorPos(i, actorX, actorY, actorZ);
  52. thisDist = GetPlayerDistanceFromPoint(playerid, actorX, actorY, actorZ);
  53. if(thisDist < closestDist && thisDist < range)
  54. {
  55. closestActor = i;
  56. closestDist = thisDist;
  57. }
  58. }
  59. return closestActor;
  60. }
  61. stock GetClosestPlayer(playerid, Float:range = FLOAT_INFINITY)
  62. {
  63. new Float:thisDist;
  64. new Float:x, Float:y, Float:z;
  65. new Float:closestDist = FLOAT_INFINITY;
  66. new closestPlayer = INVALID_PLAYER_ID;
  67. GetPlayerPos(playerid, x, y, z);
  68. foreach(new i : StreamedPlayer[playerid])
  69. {
  70. thisDist = GetPlayerDistanceFromPoint(i, x, y, z);
  71. if(thisDist < closestDist && thisDist < range)
  72. {
  73. closestPlayer = i;
  74. closestDist = thisDist;
  75. }
  76. }
  77. return closestPlayer;
  78. }
  79. stock GetClosestVehicle(playerid, Float:range = FLOAT_INFINITY)
  80. {
  81. new Float:thisDist;
  82. new Float:x, Float:y, Float:z;
  83. new Float:closestDist = FLOAT_INFINITY;
  84. new closestVehicle = INVALID_VEHICLE_ID;
  85. GetPlayerPos(playerid, x, y, z);
  86. foreach(new i : StreamedVehicle[playerid])
  87. {
  88. thisDist = GetVehicleDistanceFromPoint(i, x, y, z);
  89. if(thisDist < closestDist && thisDist < range)
  90. {
  91. closestVehicle = i;
  92. closestDist = thisDist;
  93. }
  94. }
  95. return closestVehicle;
  96. }
  97. stock SetPlayerToFacePlayer(playerid, targetid, Float:offset = 0.0)
  98. {
  99. new Float:x1, Float:y1, Float:z1;
  100. new Float:x2, Float:y2, Float:z2;
  101. GetPlayerPos(playerid, x1, y1, z1);
  102. GetPlayerPos(targetid, x2, y2, z2);
  103. SetPlayerFacingAngle(playerid, GetAngleToPoint(x1, y1, x2, y2) + offset);
  104. }
  105. stock SetPlayerToFacePoint(playerid, Float:x, Float:y)
  106. {
  107. new Float:pX, Float:pY, Float:pZ, Float:ang;
  108. GetPlayerPos(playerid, pX, pY, pZ);
  109. if(y > pY) ang = (-acos((x - pX) / floatsqroot((x - pX)*(x - pX) + (y - pY)*(y - pY))) - 90.0);
  110. else if(y < pY && x < pX) ang = (acos((x - pX) / floatsqroot((x - pX)*(x - pX) + (y - pY)*(y - pY))) - 450.0);
  111. else if(y < pY) ang = (acos((x - pX) / floatsqroot((x - pX)*(x - pX) + (y - pY)*(y - pY))) - 90.0);
  112. if(x > pX) ang = (floatabs(floatabs(ang) + 180.0));
  113. else ang = (floatabs(ang) - 180.0);
  114. SetPlayerFacingAngle(playerid, ang);
  115. return false;
  116. }
  117. stock SetPlayerToFaceDynamicActor(playerid, targetid)
  118. {
  119. new Float:x1, Float:y1, Float:z1;
  120. new Float:x2, Float:y2, Float:z2;
  121. GetPlayerPos(playerid, x1, y1, z1);
  122. GetDynamicActorPos(targetid, x2, y2, z2);
  123. SetPlayerFacingAngle(playerid, GetAngleToPoint(x1, y1, x2, y2));
  124. }
  125. stock bool:IsAngleInRangeOfAngle(Float:a1, Float:a2, Float:range = 10.0)
  126. {
  127. a1 -= a2;
  128. if((a1 < range) && (a1 > -range)) return true;
  129. return false;
  130. }
  131. // Truncates a value to the range 0.0 - 360.0
  132. stock Float:GetAbsoluteAngle(Float:angle)
  133. {
  134. while(angle < 0.0)
  135. {
  136. angle += 360.0;
  137. }
  138. while(angle > 360.0)
  139. {
  140. angle -= 360.0;
  141. }
  142. return angle;
  143. }
  144. // Returns the offset heading from north between a point and a destination
  145. stock Float:GetAngleToPoint(Float:fPointX, Float:fPointY, Float:fDestX, Float:fDestY)
  146. {
  147. return GetAbsoluteAngle(-(90.0 - (atan2((fDestY - fPointY), (fDestX - fPointX)))));
  148. }
  149. #include <YSI_Coding\y_hooks>
  150. static const AnimData[][] =
  151. {
  152. "AIRPORT", "ATTRACTORS", "BAR", "BASEBALL", "BD_FIRE",
  153. "BEACH", "BENCHPRESS", "BF_INJECTION", "BIKE_DBZ", "BIKED",
  154. "BIKEH", "BIKELEAP", "BIKES", "BIKEV", "BLOWJOBZ",
  155. "BMX", "BOMBER", "BOX", "BSKTBALL", "BUDDY",
  156. "BUS", "CAMERA", "CAR", "CAR_CHAT", "CARRY",
  157. "CASINO", "CHAINSAW", "CHOPPA", "CLOTHES", "COACH",
  158. "COLT45", "COP_AMBIENT", "COP_DVBYZ", "CRACK", "CRIB",
  159. "DAM_JUMP", "DANCING", "DEALER", "DILDO", "DODGE",
  160. "DOZER", "DRIVEBYS", "FAT", "FIGHT_B", "FIGHT_C",
  161. "FIGHT_D", "FIGHT_E", "FINALE", "FINALE2", "FLAME",
  162. "FLOWERS", "FOOD", "FREEWEIGHTS", "GANGS", "GFUNK",
  163. "GHANDS", "GHETTO_DB", "GOGGLES", "GRAFFITI", "GRAVEYARD",
  164. "GRENADE", "GYMNASIUM", "HAIRCUTS", "HEIST9", "INT_HOUSE",
  165. "INT_OFFICE", "INT_SHOP", "JST_BUISNESS", "KART", "KISSING",
  166. "KNIFE", "LAPDAN1", "LAPDAN2", "LAPDAN3", "LOWRIDER",
  167. "MD_CHASE", "MD_END", "MEDIC", "MISC", "MTB",
  168. "MUSCULAR", "NEVADA", "ON_LOOKERS", "OTB", "PARACHUTE",
  169. "PARK", "PAULNMAC", "PED", "PLAYER_DVBYS", "PLAYIDLES",
  170. "POLICE", "POOL", "POOR", "PYTHON", "QUAD",
  171. "QUAD_DBZ", "RAPPING", "RIFLE", "RIOT", "ROB_BANK",
  172. "ROCKET", "RUNNINGMAN", "RUSTLER", "RYDER", "SCRATCHING",
  173. "SEX", "SHAMAL", "SHOP", "SHOTGUN", "SILENCED",
  174. "SKATE", "SMOKING", "SNIPER", "SNM", "SPRAYCAN",
  175. "STRIP", "SUNBATHE", "SWAT", "SWEET", "SWIM",
  176. "SWORD", "TANK", "TATTOOS", "TEC", "TRAIN",
  177. "TRUCK", "UZI", "VAN", "VENDING", "VORTEX",
  178. "WAYFARER", "WEAPONS", "WOP", "WUZI"
  179. };
  180. hook OnPlayerConnect(playerid)
  181. {
  182. for(new i = 0; i < sizeof(AnimData); i++) ApplyAnimation(playerid, AnimData[i], "null", 4.0, 0, 0, 0, 0, 0, 1);
  183. }