Advertisement
Guest User

Fly.inc

a guest
Jan 6th, 2021
1,832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.28 KB | None | 0 0
  1. // =======================================================================================
  2. // fly.inc
  3. //
  4. // Author: Norck
  5. //
  6. // icq: 44-055-21
  7. // skype: paul_norck
  8. //
  9. // Credits: Creator of SetPlayerLookAt function. Sorry, I can't remember their name
  10. //
  11. // you are allowed to edit this script
  12. // you are not allowed to sell this script
  13. //
  14. // Please, don't remove the credits
  15. // =======================================================================================
  16.  
  17. // variables
  18.  
  19. static bool:OnFly[MAX_PLAYERS]; // true = player is flying, false = player on foot
  20.  
  21. // prototypes
  22.  
  23. forward InitFly(playerid); // call this function in OnPlayerConnect
  24. forward bool:StartFly(playerid); // start flying
  25. forward Fly(playerid); // timer
  26. forward bool:StopFly(playerid); // stop flying
  27. forward static SetPlayerLookAt(playerid,Float:x,Float:y); // set player face position
  28.  
  29. // functions
  30.  
  31. InitFly(playerid)
  32. {
  33. OnFly[playerid] = false;
  34. return;
  35. }
  36.  
  37. bool:StartFly(playerid)
  38. {
  39. if(OnFly[playerid])
  40. return false;
  41. OnFly[playerid] = true;
  42. new Float:x,Float:y,Float:z;
  43. GetPlayerPos(playerid,x,y,z);
  44. SetPlayerPos(playerid,x,y,z+5.0);
  45. ApplyAnimation(playerid,"PARACHUTE","PARA_steerR",6.1,1,1,1,1,0,1);
  46. Fly(playerid);
  47. GameTextForPlayer(playerid,"~y~MODO VOAR~n~~r~~k~~PED_FIREWEAPON~ ~w~- AUMENTA ALTURA~n~~r~RMB ~w~- REDUZ ALTURA~n~\
  48. ~r~~k~~PED_SPRINT~ ~w~- AUMENTAR SPEED~n~\
  49. ~r~~k~~SNEAK_ABOUT~ ~w~- REDUZ SPEED",10000,3);
  50. return true;
  51. }
  52.  
  53. public Fly(playerid)
  54. {
  55. if(!IsPlayerConnected(playerid))
  56. return 1;
  57. new k, ud,lr;
  58. GetPlayerKeys(playerid,k,ud,lr);
  59. new Float:v_x,Float:v_y,Float:v_z,
  60. Float:x,Float:y,Float:z;
  61. if(ud < 0) // forward
  62. {
  63. GetPlayerCameraFrontVector(playerid,x,y,z);
  64. v_x = x+0.1;
  65. v_y = y+0.1;
  66. }
  67. if(k & 128) // down
  68. v_z = -0.2;
  69. else if(k & KEY_FIRE) // up
  70. v_z = 0.2;
  71. if(k & KEY_WALK) // slow
  72. {
  73. v_x /=5.0;
  74. v_y /=5.0;
  75. v_z /=5.0;
  76. }
  77. if(k & KEY_SPRINT) // fast
  78. {
  79. v_x *=4.0;
  80. v_y *=4.0;
  81. v_z *=4.0;
  82. }
  83. if(v_z == 0.0)
  84. v_z = 0.025;
  85. SetPlayerVelocity(playerid,v_x,v_y,v_z);
  86. if(v_x == 0 && v_y == 0)
  87. {
  88. if(GetPlayerAnimationIndex(playerid) == 959)
  89. ApplyAnimation(playerid,"PARACHUTE","PARA_steerR",6.1,1,1,1,1,0,1);
  90. }
  91. else
  92. {
  93. GetPlayerCameraFrontVector(playerid,v_x,v_y,v_z);
  94. GetPlayerCameraPos(playerid,x,y,z);
  95. SetPlayerLookAt(playerid,v_x*500.0+x,v_y*500.0+y);
  96. if(GetPlayerAnimationIndex(playerid) != 959)
  97. ApplyAnimation(playerid,"PARACHUTE","FALL_SkyDive_Accel",6.1,1,1,1,1,0,1);
  98. }
  99. if(OnFly[playerid])
  100. SetTimerEx("Fly",100,false,"i",playerid);
  101. return 1;
  102. }
  103.  
  104. bool:StopFly(playerid)
  105. {
  106. if(!OnFly[playerid])
  107. return false;
  108. new Float:x,Float:y,Float:z;
  109. GetPlayerPos(playerid,x,y,z);
  110. SetPlayerPos(playerid,x,y,z);
  111. OnFly[playerid] = false;
  112. return true;
  113. }
  114.  
  115. static SetPlayerLookAt(playerid,Float:x,Float:y)
  116. {
  117. new Float:Px, Float:Py, Float: Pa;
  118. GetPlayerPos(playerid, Px, Py, Pa);
  119. Pa = floatabs(atan((y-Py)/(x-Px)));
  120. if (x <= Px && y >= Py) Pa = floatsub(180.0, Pa);
  121. else if (x < Px && y < Py) Pa = floatadd(Pa, 180.0);
  122. else if (x >= Px && y <= Py) Pa = floatsub(360.0, Pa);
  123. Pa = floatsub(Pa, 90.0);
  124. if (Pa >= 360.0)
  125. Pa = floatsub(Pa, 360.0);
  126. SetPlayerFacingAngle(playerid, Pa);
  127. return;
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement