Facebook
From Mungo Motmot, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 189
  1. //Admin fly
  2.  
  3. //Zmienna przechowująca bool'a z włączonym lataniem. [FALSE - wyłączone, TRUE - włączone]
  4. static bool:FLY_Variable[MAX_PLAYERS];
  5.  
  6. //Definicje funkcji
  7. forward bool:FLY_Start(playerid);                            //Start latania, przed tym InitFly(%0)
  8. forward FLY_Keys(playerid);                                  //Obsługa klawiszy
  9. forward bool:FLY_Stop(playerid);                              //Wyłączenie latania
  10. forward static FLY_Look(playerid,Float:x,Float:y);    //Ustawianie pozycji kamery (credits: Y_Less, przerobiona delikatnie)
  11.  
  12. //---
  13.  
  14. //Macro na włączenie latania
  15. #define InitFly(%0)        
  16.     (FLY_Variable[(%0)] = false)
  17.  
  18. //Stricte włączenie latania
  19. bool:FLY_Start(playerid)
  20. {
  21.         //Warunek, że poprzednia funkcja została wykonana, ustawienie boola na 1.
  22.         if(FLY_Variable[playerid]) return false;
  23.         FLY_Variable[playerid] = true;
  24.        
  25.         //Stworzenie zmiennych z pozycją + przypisanie do nich pozycji
  26.         new
  27.             Float:x,
  28.             Float:y,
  29.             Float:z;
  30.  
  31.         GetPlayerPos(playerid,x,y,z);
  32.         SetPlayerPos(playerid,x,y,z+5.0);
  33.  
  34.         //Wywołanie funkcji public Fly;
  35.         FLY_Keys(playerid);
  36.  
  37.         return true;
  38. }
  39.  
  40. public FLY_Keys(playerid)
  41. {
  42.     if(playerid == INVALID_PLAYER_ID) return 1;
  43.  
  44.     new key[3];
  45.  
  46.     GetPlayerKeys(playerid,key[0],key[1],key[2]);
  47.  
  48.     new
  49.         Float:v_x,
  50.         Float:v_y,
  51.         Float:v_z,
  52.         Float:x,
  53.         Float:y,
  54.         Float:z;
  55.  
  56.     if(key[1] < 0)                                  //Góra powoli
  57.     {
  58.         GetPlayerCameraFrontVector(playerid,x,y,z);
  59.         v_x = x+0.1;
  60.         v_y = y+0.1;
  61.     }
  62.  
  63.     if(key[0] & 128) v_z = -0.2;
  64.     else if(key[0] & KEY_FIRE) v_z = 0.2;
  65.     if(key[0] & KEY_WALK)
  66.     {
  67.         v_x /=5.0;
  68.         v_y /=5.0;
  69.         v_z /=5.0;
  70.     }
  71.  
  72.     if(key[0] & KEY_SPRINT)
  73.     {
  74.         v_x *=4.0;
  75.         v_y *=4.0;
  76.         v_z *=4.0;
  77.     }
  78.  
  79.     if(v_z == 0.0) v_z = 0.025;
  80.     SetPlayerVelocity(playerid,v_x,v_y,v_z);
  81.     if(v_x != 0 && v_y != 0)
  82.     {      
  83.         GetPlayerCameraFrontVector(playerid,v_x,v_y,v_z);
  84.         GetPlayerCameraPos(playerid,x,y,z);
  85.         FLY_Look(playerid,v_x*500.0+x,v_y*500.0+y);
  86.     }
  87.     if(FLY_Variable[playerid]) SetTimerEx("Fly",100,false,"i",playerid);
  88.     return 1;
  89. }
  90.  
  91. bool:FLY_Stop(playerid)
  92. {
  93.     if(!FLY_Variable[playerid]) return false;
  94.     new
  95.         Float:x,
  96.         Float:y,
  97.         Float:z;
  98.  
  99.     GetPlayerPos(playerid,x,y,z);
  100.     SetPlayerPos(playerid,x,y,z);
  101.  
  102.     FLY_Variable[playerid] = false;
  103.     return true;
  104. }
  105.  
  106. static FLY_Look(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) Pa = floatsub(Pa, 360.0);
  116.     SetPlayerFacingAngle(playerid, Pa);
  117.     return;
  118. }