Advertisement
Guest User

Rzzr's Flymode

a guest
Nov 4th, 2011
2,134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.96 KB | None | 0 0
  1. // Simple but efficient Flymode
  2. // by Rzzr.
  3. // You are free to use, reproduce, edit, burn or whipe your ass with this script.
  4.  
  5. #include <a_samp>
  6.  
  7. #define FLYMODESPEED GetPVarFloat(playerid, "FlymodeSpeed")
  8. new PlayerToetsen, OmhoogLaag, LinksRechts;
  9. new Float:x,Float:y,Float:z;
  10. new Float:x2, Float:y2, Float:z2;
  11.  
  12. public OnFilterScriptInit()
  13. {
  14.     print(">> Simple Flymode, by Rzzr <c>");
  15.     return 1;
  16. }
  17.  
  18. public OnFilterScriptExit()
  19. {
  20.     return 1;
  21. }
  22.  
  23. public OnPlayerRequestSpawn(playerid)
  24. {
  25.     SetPVarFloat(playerid, "FlymodeSpeed", 1);
  26.     return 1;
  27. }
  28.  
  29. forward Float:SetPlayerToFacePos(playerid, Float:X, Float:Y);
  30. public Float:SetPlayerToFacePos(playerid, Float:X, Float:Y)
  31. {
  32.     new
  33.         Float:pX,
  34.         Float:pY,
  35.         Float:pZ,
  36.         Float:ang;
  37.  
  38.     if(!IsPlayerConnected(playerid)) return 0.0;
  39.  
  40.     GetPlayerPos(playerid, pX, pY, pZ);
  41.  
  42.     if( Y > pY ) ang = (-acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  43.     else if( Y < pY && X < pX ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 450.0);
  44.     else if( Y < pY ) ang = (acos((X - pX) / floatsqroot((X - pX)*(X - pX) + (Y - pY)*(Y - pY))) - 90.0);
  45.  
  46.     if(X > pX) ang = (floatabs(floatabs(ang) + 180.0));
  47.     else ang = (floatabs(ang) - 180.0);
  48.  
  49.     //ang += 180.0;
  50.  
  51.     SetPlayerFacingAngle(playerid, ang);
  52.  
  53.     return ang;
  54. }
  55.  
  56. public OnPlayerCommandText(playerid, cmdtext[])
  57. {
  58.  
  59.     if(IsPlayerAdmin(playerid))
  60.     {
  61.    
  62.    
  63.         if (strcmp("/flymode", cmdtext, true, 10) == 0)
  64.         {
  65.             if(GetPVarInt(playerid, "Flymode") == 0)
  66.             {
  67.                 SetPVarInt(playerid, "Flymode", 1);
  68.                 //ApplyAnimation(playerid,"PARACHUTE","FALL_SkyDive_Accel",4.1,1,1,1,1,0);
  69.                 SetPlayerHealth(playerid, 50000);
  70.                 SendClientMessage(playerid, 0xFF0000AA, "Flymode activated. Press shift to enter flying mode, and space to fly!");
  71.                 return 1;
  72.             }
  73.             if(GetPVarInt(playerid, "Flymode") == 1)
  74.             {
  75.                 SetPVarInt(playerid, "Flymode", 0);
  76.                 ClearAnimations(playerid);
  77.                 SetPlayerHealth(playerid, 100);
  78.                 SendClientMessage(playerid, 0xFF0000AA, "Flymode disabled");
  79.                 return 1;
  80.             }
  81.             return 1;
  82.         }
  83.         if (strcmp("/flyspeed", cmdtext, true, 10) == 0)
  84.         {
  85.             ShowPlayerDialog(playerid, 40, DIALOG_STYLE_INPUT, "Change flying speed", "Please put in the desired flying speed:\n\n", "OK", "Quit");
  86.  
  87.             return 1;
  88.         }
  89.    
  90.     }
  91.     return 0;
  92. }
  93.  
  94.  
  95. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  96. {
  97.     if ((newkeys & KEY_JUMP) && !(oldkeys & KEY_JUMP))
  98.     {
  99.         if(GetPVarInt(playerid, "Flymode") == 1)
  100.         {
  101.             if(GetPVarInt(playerid, "Flying") == 0)
  102.             {
  103.                 SetPVarInt(playerid, "Flying", 1);
  104.                 //SetPlayerAttachedObject(playerid, 2, 2237, 7, -0.08,0.5,-0.2, 271.4781,0,0);
  105.                 return 1;
  106.             }
  107.             if(GetPVarInt(playerid, "Flying") == 1)
  108.             {
  109.                 SetPVarInt(playerid, "Flying", 0);
  110.                 GetPlayerVelocity(playerid, x, y, z);
  111.                 ClearAnimations(playerid);
  112.                 SetPlayerVelocity(playerid, x/2, y/2, z/2);
  113.                 //RemovePlayerAttachedObject(playerid, 2);
  114.                 return 1;
  115.             }
  116.         }
  117.     }
  118.     return 1;
  119. }
  120.  
  121.  
  122. public OnPlayerUpdate(playerid)
  123. {
  124.     if(GetPVarInt(playerid, "Flymode") == 1 && GetPVarInt(playerid, "Flying") == 1)
  125.     {
  126.     GetPlayerKeys(playerid,PlayerToetsen,OmhoogLaag,LinksRechts);
  127.     if(PlayerToetsen & KEY_SPRINT)
  128.     {
  129.         GetPlayerPos(playerid, x2, y2, z2);
  130.         GetPlayerCameraFrontVector(playerid, x, y, z);
  131.         SetPlayerToFacePos(playerid, x + x2, y+y2);
  132.         SetPlayerVelocity(playerid, x*FLYMODESPEED, y*FLYMODESPEED, z*FLYMODESPEED);
  133.         //ApplyAnimation(playerid,"PARACHUTE","FALL_SkyDive_Accel",4.1,1,1,1,1,0);
  134.         ApplyAnimation(playerid,"ped","run_player",4.1,1,1,1,1,0);
  135.     }
  136.     else
  137.     {
  138.         SetPlayerVelocity(playerid, 0, 0, 0);
  139.         ApplyAnimation(playerid,"FAT","FatIdle",4.1,0,1,1,1,0);
  140.     }
  141.     }
  142.  
  143.     return 1;
  144. }
  145.  
  146. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  147. {
  148.     if(dialogid == 40)
  149.     {
  150.         if(response && strlen(inputtext))
  151.         {
  152.             new Float:speed;
  153.             if (sscanf(inputtext, "f", speed)) SendClientMessage(playerid, 0xFF0000AA, "Please put in a valid number!");
  154.             else
  155.             {
  156.                 SetPVarFloat(playerid, "FlymodeSpeed", speed);
  157.                 SendClientMessage(playerid, 0xFF0000AA, "Speed changed.");
  158.             }
  159.         }
  160.     }
  161.     return 1;
  162. }
  163.  
  164. stock sscanf(string[], format[], {Float,_}:...)
  165. {
  166.     #if defined isnull
  167.         if (isnull(string))
  168.     #else
  169.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  170.     #endif
  171.         {
  172.             return format[0];
  173.         }
  174.     #pragma tabsize 4
  175.     new
  176.         formatPos = 0,
  177.         stringPos = 0,
  178.         paramPos = 2,
  179.         paramCount = numargs(),
  180.         delim = ' ';
  181.     while (string[stringPos] && string[stringPos] <= ' ')
  182.     {
  183.         stringPos++;
  184.     }
  185.     while (paramPos < paramCount && string[stringPos])
  186.     {
  187.         switch (format[formatPos++])
  188.         {
  189.             case '\0':
  190.             {
  191.                 return 0;
  192.             }
  193.             case 'i', 'd':
  194.             {
  195.                 new
  196.                     neg = 1,
  197.                     num = 0,
  198.                     ch = string[stringPos];
  199.                 if (ch == '-')
  200.                 {
  201.                     neg = -1;
  202.                     ch = string[++stringPos];
  203.                 }
  204.                 do
  205.                 {
  206.                     stringPos++;
  207.                     if ('0' <= ch <= '9')
  208.                     {
  209.                         num = (num * 10) + (ch - '0');
  210.                     }
  211.                     else
  212.                     {
  213.                         return -1;
  214.                     }
  215.                 }
  216.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  217.                 setarg(paramPos, 0, num * neg);
  218.             }
  219.             case 'h', 'x':
  220.             {
  221.                 new
  222.                     num = 0,
  223.                     ch = string[stringPos];
  224.                 do
  225.                 {
  226.                     stringPos++;
  227.                     switch (ch)
  228.                     {
  229.                         case 'x', 'X':
  230.                         {
  231.                             num = 0;
  232.                             continue;
  233.                         }
  234.                         case '0' .. '9':
  235.                         {
  236.                             num = (num << 4) | (ch - '0');
  237.                         }
  238.                         case 'a' .. 'f':
  239.                         {
  240.                             num = (num << 4) | (ch - ('a' - 10));
  241.                         }
  242.                         case 'A' .. 'F':
  243.                         {
  244.                             num = (num << 4) | (ch - ('A' - 10));
  245.                         }
  246.                         default:
  247.                         {
  248.                             return -1;
  249.                         }
  250.                     }
  251.                 }
  252.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  253.                 setarg(paramPos, 0, num);
  254.             }
  255.             case 'c':
  256.             {
  257.                 setarg(paramPos, 0, string[stringPos++]);
  258.             }
  259.             case 'f':
  260.             {
  261.  
  262.                 new changestr[16], changepos = 0, strpos = stringPos;
  263.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  264.                 {
  265.                     changestr[changepos++] = string[strpos++];
  266.                     }
  267.                 changestr[changepos] = '\0';
  268.                 setarg(paramPos,0,_:floatstr(changestr));
  269.             }
  270.             case 'p':
  271.             {
  272.                 delim = format[formatPos++];
  273.                 continue;
  274.             }
  275.             case '\'':
  276.             {
  277.                 new
  278.                     end = formatPos - 1,
  279.                     ch;
  280.                 while ((ch = format[++end]) && ch != '\'') {}
  281.                 if (!ch)
  282.                 {
  283.                     return -1;
  284.                 }
  285.                 format[end] = '\0';
  286.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  287.                 {
  288.                     if (format[end + 1])
  289.                     {
  290.                         return -1;
  291.                     }
  292.                     return 0;
  293.                 }
  294.                 format[end] = '\'';
  295.                 stringPos = ch + (end - formatPos);
  296.                 formatPos = end + 1;
  297.             }
  298.             case 'u':
  299.             {
  300.                 new
  301.                     end = stringPos - 1,
  302.                     id = 0,
  303.                     bool:num = true,
  304.                     ch;
  305.                 while ((ch = string[++end]) && ch != delim)
  306.                 {
  307.                     if (num)
  308.                     {
  309.                         if ('0' <= ch <= '9')
  310.                         {
  311.                             id = (id * 10) + (ch - '0');
  312.                         }
  313.                         else
  314.                         {
  315.                             num = false;
  316.                         }
  317.                     }
  318.                 }
  319.                 if (num && IsPlayerConnected(id))
  320.                 {
  321.                     setarg(paramPos, 0, id);
  322.                 }
  323.                 else
  324.                 {
  325.                     #if !defined foreach
  326.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  327.                         #define __SSCANF_FOREACH__
  328.                     #endif
  329.                     string[end] = '\0';
  330.                     num = false;
  331.                     new
  332.                         name[MAX_PLAYER_NAME];
  333.                     id = end - stringPos;
  334.                     foreach (Player, playerid)
  335.                     {
  336.                         GetPlayerName(playerid, name, sizeof (name));
  337.                         if (!strcmp(name, string[stringPos], true, id))
  338.                         {
  339.                             setarg(paramPos, 0, playerid);
  340.                             num = true;
  341.                             break;
  342.                         }
  343.                     }
  344.                     if (!num)
  345.                     {
  346.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  347.                     }
  348.                     string[end] = ch;
  349.                     #if defined __SSCANF_FOREACH__
  350.                         #undef foreach
  351.                         #undef __SSCANF_FOREACH__
  352.                     #endif
  353.                 }
  354.                 stringPos = end;
  355.             }
  356.             case 's', 'z':
  357.             {
  358.                 new
  359.                     i = 0,
  360.                     ch;
  361.                 if (format[formatPos])
  362.                 {
  363.                     while ((ch = string[stringPos++]) && ch != delim)
  364.                     {
  365.                         setarg(paramPos, i++, ch);
  366.                     }
  367.                     if (!i)
  368.                     {
  369.                         return -1;
  370.                     }
  371.                 }
  372.                 else
  373.                 {
  374.                     while ((ch = string[stringPos++]))
  375.                     {
  376.                         setarg(paramPos, i++, ch);
  377.                     }
  378.                 }
  379.                 stringPos--;
  380.                 setarg(paramPos, i, '\0');
  381.             }
  382.             default:
  383.             {
  384.                 continue;
  385.             }
  386.         }
  387.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  388.         {
  389.             stringPos++;
  390.         }
  391.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  392.         {
  393.             stringPos++;
  394.         }
  395.         paramPos++;
  396.     }
  397.     do
  398.     {
  399.         if ((delim = format[formatPos++]) > ' ')
  400.         {
  401.             if (delim == '\'')
  402.             {
  403.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  404.             }
  405.             else if (delim != 'z')
  406.             {
  407.                 return delim;
  408.             }
  409.         }
  410.     }
  411.     while (delim > ' ');
  412.     return 0;
  413. }
  414.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement