Advertisement
Guest User

fly.inc

a guest
Jan 7th, 2012
7,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 3.29 KB | None | 0 0
  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.  
  18. // variables
  19.  
  20. static bool:OnFly[MAX_PLAYERS];     // true = player is flying, false = player on foot
  21.  
  22. // prototypes
  23.  
  24. forward InitFly(playerid);                          // call this function in OnPlayerConnect
  25. forward bool:StartFly(playerid);                    // start flying
  26. forward Fly(playerid);                              // timer
  27. forward bool:StopFly(playerid);                     // stop flying
  28. forward static SetPlayerLookAt(playerid,Float:x,Float:y);   // set player face position
  29.  
  30. // functions
  31.  
  32. InitFly(playerid)
  33. {
  34.     OnFly[playerid] = false;
  35.     return;
  36. }
  37.  
  38. bool:StartFly(playerid)
  39. {
  40.     if(OnFly[playerid])
  41.         return false;
  42.     OnFly[playerid] = true;
  43.     new Float:x,Float:y,Float:z;
  44.     GetPlayerPos(playerid,x,y,z);
  45.     SetPlayerPos(playerid,x,y,z+5.0);
  46.     ApplyAnimation(playerid,"PARACHUTE","PARA_steerR",6.1,1,1,1,1,0,1);
  47.     Fly(playerid);
  48.     GameTextForPlayer(playerid,"~y~Fly mode~n~~r~~k~~PED_FIREWEAPON~ ~w~- increase height~n~~r~RMB ~w~- reduce height~n~\
  49.     ~r~~k~~PED_SPRINT~ ~w~- increase speed~n~\
  50.     ~r~~k~~SNEAK_ABOUT~ ~w~- reduce speed",10000,3);
  51.     return true;
  52. }
  53.  
  54. public Fly(playerid)
  55. {
  56.     if(!IsPlayerConnected(playerid))
  57.         return 1;
  58.     new k, ud,lr;
  59.     GetPlayerKeys(playerid,k,ud,lr);
  60.     new Float:v_x,Float:v_y,Float:v_z,
  61.         Float:x,Float:y,Float:z;
  62.     if(ud < 0)  // forward
  63.     {
  64.         GetPlayerCameraFrontVector(playerid,x,y,z);
  65.         v_x = x+0.1;
  66.         v_y = y+0.1;
  67.     }
  68.     if(k & 128) // down
  69.         v_z = -0.2;
  70.     else if(k & KEY_FIRE)   // up
  71.         v_z = 0.2;
  72.     if(k & KEY_WALK)    // slow
  73.     {
  74.         v_x /=5.0;
  75.         v_y /=5.0;
  76.         v_z /=5.0;
  77.     }
  78.     if(k & KEY_SPRINT)  // fast
  79.     {
  80.         v_x *=4.0;
  81.         v_y *=4.0;
  82.         v_z *=4.0;
  83.     }
  84.     if(v_z == 0.0)
  85.         v_z = 0.025;
  86.     SetPlayerVelocity(playerid,v_x,v_y,v_z);
  87.     if(v_x == 0 && v_y == 0)
  88.     {  
  89.         if(GetPlayerAnimationIndex(playerid) == 959)   
  90.             ApplyAnimation(playerid,"PARACHUTE","PARA_steerR",6.1,1,1,1,1,0,1);
  91.     }
  92.     else
  93.     {
  94.         GetPlayerCameraFrontVector(playerid,v_x,v_y,v_z);
  95.         GetPlayerCameraPos(playerid,x,y,z);
  96.         SetPlayerLookAt(playerid,v_x*500.0+x,v_y*500.0+y);
  97.         if(GetPlayerAnimationIndex(playerid) != 959)
  98.             ApplyAnimation(playerid,"PARACHUTE","FALL_SkyDive_Accel",6.1,1,1,1,1,0,1);
  99.     }
  100.     if(OnFly[playerid])
  101.         SetTimerEx("Fly",100,false,"i",playerid);
  102.     return 1;
  103. }
  104.  
  105. bool:StopFly(playerid)
  106. {
  107.     if(!OnFly[playerid])
  108.         return false;
  109.     new Float:x,Float:y,Float:z;
  110.     GetPlayerPos(playerid,x,y,z);
  111.     SetPlayerPos(playerid,x,y,z);
  112.     OnFly[playerid] = false;
  113.     return true;
  114. }
  115.  
  116. static SetPlayerLookAt(playerid,Float:x,Float:y)
  117. {
  118.     new Float:Px, Float:Py, Float: Pa;
  119.     GetPlayerPos(playerid, Px, Py, Pa);
  120.     Pa = floatabs(atan((y-Py)/(x-Px)));
  121.     if (x <= Px && y >= Py)         Pa = floatsub(180.0, Pa);
  122.     else if (x < Px && y < Py)      Pa = floatadd(Pa, 180.0);
  123.     else if (x >= Px && y <= Py)    Pa = floatsub(360.0, Pa);
  124.     Pa = floatsub(Pa, 90.0);
  125.     if (Pa >= 360.0)
  126.         Pa = floatsub(Pa, 360.0);
  127.     SetPlayerFacingAngle(playerid, Pa);
  128.     return;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement