Advertisement
AwDod

fly.inc

Oct 24th, 2023
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.88 KB | None | 0 0
  1. An example:
  2. #include <a_samp>
  3. #include <fly>
  4.  
  5. public OnFilterScriptInit()
  6. {
  7.     print("=========================================\n");
  8.     print("Fly include demo FS by Norck");
  9.     print(" ");
  10.     print("=========================================\n");
  11.     return 1;
  12. }
  13. public OnPlayerConnect(playerid)
  14. {
  15.     InitFly(playerid);
  16.     return 1;
  17. }
  18. public OnPlayerCommandText(playerid, cmdtext[])
  19. {
  20.     if(!strcmp(cmdtext,"/fly",true))
  21.     {
  22.         StartFly(playerid);
  23.         return 1;
  24.     }
  25.     if(!strcmp(cmdtext,"/stopfly",true))
  26.     {
  27.         StopFly(playerid);
  28.         return 1;
  29.     }
  30.     return 0;
  31. }
  32.  
  33. And I include everything:
  34. // =======================================================================================
  35. // fly.inc
  36. //
  37. // Author: Norck
  38. //
  39. // msn:     paul_norck@hotmail.com
  40. // icq:     44-055-21
  41. // skype:   paul_norck
  42. //
  43. // Credits: Creator of SetPlayerLookAt function. Sorry, I can't remember their name
  44. //
  45. // you are allowed to edit this script
  46. // you are not allowed to sell this script
  47. //
  48. // Please, don't remove the credits
  49. // =======================================================================================
  50.  
  51. // variables
  52.  
  53. static bool:OnFly[MAX_PLAYERS];     // true = player is flying, false = player on foot
  54.  
  55. // prototypes
  56.  
  57. forward InitFly(playerid);                          // call this function in OnPlayerConnect
  58. forward bool:StartFly(playerid);                    // start flying
  59. forward Fly(playerid);                              // timer
  60. forward bool:StopFly(playerid);                     // stop flying
  61. forward static SetPlayerLookAt(playerid,Float:x,Float:y);   // set player face position
  62.  
  63. // functions
  64.  
  65. InitFly(playerid)
  66. {
  67.     OnFly[playerid] = false;
  68.     return;
  69. }
  70.  
  71. bool:StartFly(playerid)
  72. {
  73.     if(OnFly[playerid])
  74.         return false;
  75.     OnFly[playerid] = true;
  76.     new Float:x,Float:y,Float:z;
  77.     GetPlayerPos(playerid,x,y,z);
  78.     SetPlayerPos(playerid,x,y,z+5.0);
  79.     ApplyAnimation(playerid,"PARACHUTE","PARA_steerR",6.1,1,1,1,1,0,1);
  80.     Fly(playerid);
  81.     GameTextForPlayer(playerid,"~y~Fly mode~n~~r~~k~~PED_FIREWEAPON~ ~w~- increase height~n~~r~RMB ~w~- reduce height~n~\
  82.     ~r~~k~~PED_SPRINT~ ~w~- increase speed~n~\
  83.     ~r~~k~~SNEAK_ABOUT~ ~w~- reduce speed",10000,3);
  84.     return true;
  85. }
  86.  
  87. public Fly(playerid)
  88. {
  89.     if(!IsPlayerConnected(playerid))
  90.         return 1;
  91.     new k, ud,lr;
  92.     GetPlayerKeys(playerid,k,ud,lr);
  93.     new Float:v_x,Float:v_y,Float:v_z,
  94.         Float:x,Float:y,Float:z;
  95.     if(ud < 0)  // forward
  96.     {
  97.         GetPlayerCameraFrontVector(playerid,x,y,z);
  98.         v_x = x+0.1;
  99.         v_y = y+0.1;
  100.     }
  101.     if(k & 128) // down
  102.         v_z = -0.2;
  103.     else if(k & KEY_FIRE)   // up
  104.         v_z = 0.2;
  105.     if(k & KEY_WALK)    // slow
  106.     {
  107.         v_x /=5.0;
  108.         v_y /=5.0;
  109.         v_z /=5.0;
  110.     }
  111.     if(k & KEY_SPRINT)  // fast
  112.     {
  113.         v_x *=4.0;
  114.         v_y *=4.0;
  115.         v_z *=4.0;
  116.     }
  117.     if(v_z == 0.0)
  118.         v_z = 0.025;
  119.     SetPlayerVelocity(playerid,v_x,v_y,v_z);
  120.     if(v_x == 0 && v_y == 0)
  121.     {  
  122.         if(GetPlayerAnimationIndex(playerid) == 959)   
  123.             ApplyAnimation(playerid,"PARACHUTE","PARA_steerR",6.1,1,1,1,1,0,1);
  124.     }
  125.     else
  126.     {
  127.         GetPlayerCameraFrontVector(playerid,v_x,v_y,v_z);
  128.         GetPlayerCameraPos(playerid,x,y,z);
  129.         SetPlayerLookAt(playerid,v_x*500.0+x,v_y*500.0+y);
  130.         if(GetPlayerAnimationIndex(playerid) != 959)
  131.             ApplyAnimation(playerid,"PARACHUTE","FALL_SkyDive_Accel",6.1,1,1,1,1,0,1);
  132.     }
  133.     if(OnFly[playerid])
  134.         SetTimerEx("Fly",100,false,"i",playerid);
  135.     return 1;
  136. }
  137.  
  138. bool:StopFly(playerid)
  139. {
  140.     if(!OnFly[playerid])
  141.         return false;
  142.     new Float:x,Float:y,Float:z;
  143.     GetPlayerPos(playerid,x,y,z);
  144.     SetPlayerPos(playerid,x,y,z);
  145.     OnFly[playerid] = false;
  146.     return true;
  147. }
  148.  
  149. static SetPlayerLookAt(playerid,Float:x,Float:y)
  150. {
  151.     new Float:Px, Float:Py, Float: Pa;
  152.     GetPlayerPos(playerid, Px, Py, Pa);
  153.     Pa = floatabs(atan((y-Py)/(x-Px)));
  154.     if (x <= Px && y >= Py)         Pa = floatsub(180.0, Pa);
  155.     else if (x < Px && y < Py)      Pa = floatadd(Pa, 180.0);
  156.     else if (x >= Px && y <= Py)    Pa = floatsub(360.0, Pa);
  157.     Pa = floatsub(Pa, 90.0);
  158.     if (Pa >= 360.0)
  159.         Pa = floatsub(Pa, 360.0);
  160.     SetPlayerFacingAngle(playerid, Pa);
  161.     return;
  162. }
Tags: fly include
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement