fly.inc 3.3 KB

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