srdjan

Hot air balloon

Nov 2nd, 2011
3,415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.16 KB | None | 0 0
  1. // Hot air balloon filterscript by Srdjan
  2. // Date is 01/11/2011
  3.  
  4. #include <a_samp>
  5. #include <mapandreas>
  6.  
  7. #define KEY_AIM 128
  8. #define MAX_BALLOONS 10
  9.  
  10. new BalloonID[MAX_BALLOONS];
  11. new PlayerInBalloon[MAX_PLAYERS];
  12. new Float: BalloonSpeed[MAX_BALLOONS];
  13. new Float: Radius[MAX_BALLOONS];
  14. new Float: Diametar[MAX_BALLOONS];
  15. new ResetTimer[MAX_BALLOONS];
  16. new ContinueTimer[MAX_BALLOONS];
  17.  
  18. new Text:commands;
  19.  
  20. forward ResetSpeed (objectid);
  21. forward Continue (objectid);
  22.  
  23. public OnFilterScriptInit ()
  24. {
  25.     CreateBalloons ();
  26.     commands = TextDrawCreate (30.0, 270.0,"~w~Commands:~n~Sprint key - speed up~n~Jump key - speed down~n~Key 'Y' - Tilt down~n~Key 'N' - Tilt up~n~LMB - Angle of heading - left~n~RMB - Angle of heading - right");
  27.     TextDrawFont (commands, 2);
  28.     TextDrawLetterSize (commands, 0.3, 0.8);
  29.     MapAndreas_Init (MAP_ANDREAS_MODE_FULL);
  30.     for (new i = 0; i < MAX_PLAYERS; i++) PlayerInBalloon[i] = -1;
  31.     printf ("\nHot Air Balloon by Srdjan loaded.\n");
  32.     return 1;
  33. }
  34.  
  35. CreateBalloons ()
  36. {
  37.     BalloonID[0] = CreateObject (19334, 198.9927, -1832.8091, 3.0, 0.0, 0.0, 0.0, 300.0);
  38.     BalloonID[1] = CreateObject (19335, 241.3257, -1834.1189, 3.0, 0.0, 0.0, 0.0, 300.0);
  39.     BalloonID[2] = CreateObject (19336, 284.8625, -1830.8752, 3.0, 0.0, 0.0, 0.0, 300.0);
  40.     for (new i = 0; i < 3; i++)
  41.     {
  42.         new id = CreateObject (18699, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 300.0);
  43.         AttachObjectToObject (id, BalloonID[i], 0.0, 0.0, 5.5, 0.0, 180.0, 0.0, 1);
  44.     }
  45. }
  46.  
  47. public OnPlayerCommandText (playerid, cmdtext[])
  48. {
  49.     if (!strcmp (cmdtext, "/operate"))
  50.     {
  51.         if (PlayerInBalloon[playerid] != -1)
  52.         {
  53.             ClearAnimations (playerid);
  54.             TextDrawHideForPlayer (playerid, commands);
  55.             PlayerInBalloon[playerid] = -1;
  56.         }
  57.         else
  58.         {
  59.             if (GetPlayerBalloonID (playerid, 0) > -1)
  60.             {
  61.                 ApplyAnimation (playerid, "GANGS", "leanIDLE", 4.1, 1, 1, 1, 1, 0, 1);
  62.                 TextDrawShowForPlayer (playerid, commands);
  63.                 PlayerInBalloon[playerid] = GetPlayerBalloonID (playerid, 0);
  64.             }
  65.             else if (GetPlayerBalloonID (playerid, 1) > -1)
  66.             {
  67.                 new objectid = BalloonID[GetPlayerBalloonID (playerid, 1)];
  68.                 if (IsObjectMoving (objectid))
  69.                 {
  70.                     ApplyAnimation (playerid, "GANGS", "leanIDLE", 4.1, 1, 1, 1, 1, 0, 1);
  71.                     TextDrawShowForPlayer (playerid, commands);
  72.                     PlayerInBalloon[playerid] = GetPlayerBalloonID (playerid, 1);
  73.                 }
  74.             }
  75.         }
  76.         return 1;
  77.     }
  78.     return 0;
  79. }
  80.  
  81. GetPlayerBalloonID (playerid, b)
  82. {
  83.     new Float: x, Float: y, Float: z;
  84.     for (new i = 0; i < sizeof (BalloonID); i++)
  85.     {
  86.         GetObjectPos (BalloonID[i], x, y, z);
  87.         if (!b)
  88.         {
  89.             if (!IsPlayerInRangeOfPoint (playerid, 1.5, x, y, z)) continue;
  90.             else return i;
  91.         }
  92.         else if (b)
  93.         {
  94.             if (!IsPlayerInRangeOfPoint (playerid, 5.0, x, y, z)) continue;
  95.             else return i;
  96.         }
  97.        
  98.     }
  99.     return -1;
  100. }
  101.  
  102. public OnPlayerKeyStateChange (playerid, newkeys, oldkeys)
  103. {
  104.     if (PlayerInBalloon[playerid] > -1)
  105.     {
  106.         new objectid = BalloonID[PlayerInBalloon[playerid]];
  107.         if ((newkeys & KEY_SPRINT) && !(oldkeys & KEY_SPRINT))
  108.         {
  109.             if (BalloonSpeed[objectid] < 15.0) BalloonSpeed[objectid] += 0.5;
  110.         }
  111.         if ((newkeys & KEY_JUMP) && !(oldkeys & KEY_JUMP))
  112.         {
  113.             if (BalloonSpeed[objectid] > -10.0) BalloonSpeed[objectid] -= 0.5;
  114.         }
  115.        
  116.         if ((newkeys & KEY_YES) && !(oldkeys & KEY_YES))
  117.         {
  118.             if (Radius[objectid] < 90.0) Radius[objectid] += 5.0;
  119.         }
  120.        
  121.         if ((newkeys & KEY_NO) && !(oldkeys & KEY_NO))
  122.         {
  123.             if (Radius[objectid] > 0.0) Radius[objectid] -= 5.0;
  124.         }
  125.        
  126.         if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
  127.         {
  128.             Diametar[objectid] -= 5.0;
  129.             if (Diametar[objectid] < 0.0) Diametar[objectid] = -5.0;
  130.         }
  131.  
  132.         if ((newkeys & KEY_AIM) && !(oldkeys & KEY_AIM))
  133.         {
  134.             Diametar[objectid] += 5.0;
  135.             if (Diametar[objectid] > 360.0) Diametar[objectid] = 5.0;
  136.         }
  137.         UpdateBalloonMove (objectid);
  138.     }
  139.     return 1;
  140. }
  141.  
  142. UpdateBalloonMove (objectid)
  143. {
  144.     StopObject (objectid);
  145.     if (BalloonSpeed[objectid] > 0.0)
  146.     {
  147.         Continue (objectid);
  148.     }
  149.     else if (BalloonSpeed[objectid] < 0.0)
  150.     {
  151.         KillTimer (ResetTimer[objectid]);
  152.         new Float: x, Float: y, Float: z;
  153.         GetObjectPos (objectid, x, y, z);
  154.         MapAndreas_FindZ_For2DCoord (x, y, z);
  155.         new time = MoveObject (objectid, x, y, z, floatabs(BalloonSpeed[objectid]));
  156.         ResetTimer[objectid] = SetTimerEx ("ResetSpeed", time, 0, "d", objectid);
  157.     }
  158. }
  159.  
  160. public ResetSpeed (objectid)
  161. {
  162.     if (BalloonSpeed[objectid] < 0.0) BalloonSpeed[objectid] = 0.0;
  163.     if (Radius[objectid] > 0.0) Radius[objectid] = 0.0;
  164. }
  165.  
  166. public Continue (objectid)
  167. {
  168.     new Float: x, Float: y, Float: z;
  169.     GetObjectPos (objectid, x, y, z);
  170.     KillTimer (ResetTimer[objectid]);
  171.     KillTimer (ContinueTimer[objectid]);
  172.     z = z + 300 * floatcos (-Radius[objectid], degrees);
  173.     x = x + 1000 * floatsin (-Radius[objectid], degrees) * floatcos (-Diametar[objectid], degrees);
  174.     y = y + 1000 * floatsin (-Radius[objectid], degrees) * floatsin (-Diametar[objectid], degrees);
  175.     new time = MoveObject (objectid, x, y, z, BalloonSpeed[objectid]);
  176.     ContinueTimer[objectid] = SetTimerEx ("Continue", time-2, 0, "d", objectid);
  177. }
  178.  
Advertisement
Add Comment
Please, Sign In to add comment