Advertisement
Mionelal

fireballs.pwn

Apr 17th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.09 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3.  
  4. #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  5.  
  6. stock IsPlayerAiming(playerid, aimid)
  7. {
  8.         new Float:X1, Float:Y1, Float:Z1, Float:X2, Float:Y2, Float:Z2;
  9.         GetPlayerPos(playerid, X1, Y1, Z1);
  10.         GetPlayerPos(aimid, X2, Y2, Z2);
  11.         new Float:Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
  12.         if(Distance < 100)
  13.         {
  14.                 new Float:A;
  15.                 GetPlayerFacingAngle(playerid, A);
  16.                 X1 += (Distance * floatsin(-A, degrees));
  17.                 Y1 += (Distance * floatcos(-A, degrees));
  18.                 Distance = floatsqroot(floatpower(floatabs(X1-X2), 2) + floatpower(floatabs(Y1-Y2), 2));
  19.                 if(Distance < 0.5)
  20.                 {
  21.                     return true;
  22.                 }
  23.         }
  24.         return false;
  25. }
  26.  
  27. stock IsPlayerLookingAtPlayer(player1, player2) { // Simon edited by Carlton
  28.         if (!IsPlayerConnected(player1) || !IsPlayerConnected(player2)) return 0;
  29.         if(player1 == player2) return 0;
  30.         new
  31.                 Float: distance,
  32.                 Float: vectorX,
  33.                 Float: vectorY,
  34.                 Float: vectorZ,
  35.                 Float: plyrPos[2][3],
  36.                 Float: projPos[3];
  37.         GetPlayerCameraFrontVector(player1, vectorX, vectorY, vectorZ);
  38.         GetPlayerCameraPos(player1, plyrPos[0][0], plyrPos[0][1], plyrPos[0][2]);
  39.         GetPlayerPos(player2, plyrPos[1][0], plyrPos[1][1], plyrPos[1][2]);
  40.         #define SQUARE(%1)  ((%1)*(%1))
  41.         distance = floatsqroot(
  42.         SQUARE(plyrPos[1][0]-plyrPos[0][0]) + SQUARE(plyrPos[1][1]-plyrPos[0][1]) + SQUARE(plyrPos[1][2]-plyrPos[0][2]));
  43.         projPos[0] = plyrPos[0][0] + vectorX * distance;
  44.         projPos[1] = plyrPos[0][1] + vectorY * distance;
  45.         projPos[2] = plyrPos[0][2] + vectorZ * distance;
  46.         return ((SQUARE(plyrPos[1][0]-projPos[0]) + SQUARE(plyrPos[1][1]-projPos[1]) + SQUARE(plyrPos[1][2]-projPos[2])) <= SQUARE(distance / 6));
  47.         #undef SQUARE
  48. }
  49.  
  50. CMD:fireballs(playerid, params[])
  51. {
  52.     if( !GetPVarInt(playerid, "FIREBALLS") ) SetPVarInt(playerid, "FIREBALLS", 1), SendClientMessage(playerid, -1, "Fireballs turned on.");
  53.     else SetPVarInt(playerid, "FIREBALLS", 0), SendClientMessage(playerid, -1, "Fireballs turned off.");
  54.     return 1;
  55.  
  56. }
  57.  
  58. public OnObjectMoved(objectid)
  59. {
  60.  
  61.     for( new i = 0; i < MAX_PLAYERS; i++)
  62.     {
  63.         if( objectid == GetPVarInt(i, "FIREOBJID") )
  64.         {
  65.  
  66.             DestroyObject( GetPVarInt(i, "FIREOBJID") );
  67.             DeletePVar(i, "FIREOBJID");
  68.             CreateExplosion( GetPVarFloat(i, "FIREBALLX"), GetPVarFloat(i, "FIREBALLY"), GetPVarFloat(i, "FIREBALLZ"), 11, 7.5);
  69.  
  70.         }
  71.     }
  72.  
  73. }
  74.  
  75. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  76. {
  77.     if (GetPVarInt(playerid, "FIREBALLS") && PRESSED(KEY_FIRE))
  78.     {
  79.         new Float:posX, Float:posY, Float:posZ;
  80.         for(new i = 0; i < MAX_PLAYERS; i++)
  81.         {
  82.             GetPlayerPos(i,posX,posY,posZ);
  83.             if (i == playerid) continue;
  84.             if(IsPlayerLookingAtPlayer(playerid, i) && IsPlayerAiming(playerid, i) && !IsPlayerInAnyVehicle(playerid) && !IsPlayerInAnyVehicle(i))
  85.             {
  86.                 if( GetPVarInt(playerid, "FIREOBJID") != 0 ) return SendClientMessage(playerid, -1, "1 at a time!");
  87.  
  88.                 new str[100];
  89.                 new nom[32];
  90.                 GetPlayerName(i, nom, 32);
  91.                 format(str, 100, "You fireballed %s.", nom);
  92.                 SendClientMessage(playerid, -1, str);
  93.                 new Float:px, Float:py, Float:pz;
  94.                 GetPlayerPos(playerid, px, py, pz);
  95.                 SetPVarInt(playerid, "FIREOBJID", CreateObject(18688, px, py, pz-1.35, 0, 0, 0, 500.0));
  96.                 GetPlayerPos(i, px, py, pz);
  97.                 SetPVarFloat(playerid, "FIREBALLX", px);
  98.                 SetPVarFloat(playerid, "FIREBALLY", py);
  99.                 SetPVarFloat(playerid, "FIREBALLZ", pz);
  100.                 MoveObject(GetPVarInt(playerid, "FIREOBJID"), px, py, pz-1.5, 15);
  101.             }
  102.         }
  103.     }
  104.     return 1;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement