Guest User

Gandalv

a guest
Feb 17th, 2010
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 18.64 KB | None | 0 0
  1. //-Death Note Gamemode by Gandalv (2010)-//
  2.  
  3. //-Include and Define-//
  4.  
  5. #include <a_samp>
  6. #include <a_players>
  7. #define GREEN 0x33AA33AA
  8. #define YELLOW 0xFFFF33AA
  9. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  10.  
  11. //-Global Var. and Arrays-//
  12.  
  13. new Threads[100][7]; //Contains the entries of the Death Note
  14. //+->   <Line><Kira ID><Victim ID><gTimer at Start><gTimer at the end><Kind of Death><Line active?>
  15.  
  16. new RowStore[MAX_PLAYERS]; //Contains information about the actual Choose-a-person-menu
  17. new gKiraID; //ID of the Death Note Owner
  18. new gTimer; //Counts every Second
  19. new NeueZeile = 0; //Creates a new Line in -> Threads
  20. new gMenuTime; //The Value Shown in the Time Setting Menu Header
  21. new gMenuLine; //Stores the Line in Threads the Menu edits
  22. new gScore[MAX_PLAYERS]; //Score
  23. new gConnected = 0; //Number of Players on the Server
  24. new gKiraAktiv = 0; //1 = Someone is Kira 0 = Nobody is Kira
  25. new Float: gRandomSpawns[5][3] = { //Random Spawns
  26.  
  27.     { 1259.344, -1182.7743, 23.5781 },
  28.     { 1103.623, -1218.4854, 17.8047 },
  29.     { 967.6936, -1540.7489, 13.5896 },
  30.     { 1115.957, -1502.6890, 15.8003 },
  31.     { 1263.040, -1242.4493, 16.3846 }
  32. };
  33. new Menu:KiraPerson;
  34. new Menu:KiraTodesart;
  35. new Menu:KiraZeit; //The 3 Menus
  36.  
  37. //-Main Function-//
  38.  
  39. main()
  40. {
  41.     print("\n----------------------------------");
  42.     print("Kira 1.0");
  43.     print("----------------------------------\n");
  44.     SetTimer("Call", 1000, true);//Starting the scannig function every second
  45. }
  46.  
  47. //-Forwards-//
  48.  
  49. forward Call();
  50. forward Auswerter(HandleID);
  51. forward Infarkt(HandleID);
  52. forward Sturz(HandleID);
  53. forward Explosion(HandleID);
  54. forward CarKick(playerid);
  55. forward CreatePersonMenu();
  56. forward CreateTimeMenu();
  57. forward RefreshMenuHeader(playerid);
  58. forward SetKira(playerid, neukira);
  59. forward ZufallKira(playerid);
  60. forward SetPlayerRandomSpawn(playerid);
  61.  
  62. //-Init-//
  63.  
  64. public OnGameModeInit()
  65. {
  66.     SetGameModeText("DeathNote 1.0");
  67.     AddPlayerClass(0, 977.2250, -1322.6969, 13.3703, 100.3185, 0, 0, 0, 0, 27, 100);
  68.  
  69.     KiraTodesart = CreateMenu("Todesart", 1, 200.0, 100.0, 150.0, 150.0);
  70.     AddMenuItem(KiraTodesart, 0, "Herzinfarkt");
  71.     AddMenuItem(KiraTodesart, 0, "Sturz");
  72.     AddMenuItem(KiraTodesart, 0, "Explosion");
  73. }
  74.  
  75. //-Class Request-//
  76.  
  77. public OnPlayerRequestClass(playerid, classid)
  78. {
  79.     SetPlayerPos(playerid,398.4077,2540.5049,19.6311);
  80.     SetPlayerCameraPos(playerid,398.4077,2530.5049,19.6311);
  81.     SetPlayerCameraLookAt(playerid,398.4077,2540.5049,19.6311);
  82.     SetPlayerFacingAngle(playerid, 180.0);
  83.     return 1;
  84. }
  85.  
  86. //-Player connect and gets information-//
  87.  
  88. public OnPlayerConnect(playerid)
  89. {
  90.     gConnected++;
  91.  
  92.     if(gConnected >= 3 && gKiraAktiv == 0) //With this the gammeode will start only with minimum 3 people on the Server
  93.     {
  94.         gKiraAktiv = 1;
  95.         ZufallKira(99);
  96.     }
  97. }
  98.  
  99. //-Player disconnect-//
  100.  
  101. public OnPlayerDisconnect(playerid)
  102. {
  103.     gConnected--;
  104.     if(playerid == gKiraID) //If Kira leaves, a new one is needed
  105.     {
  106.         ZufallKira(playerid);
  107.     }
  108.     gScore[playerid] = 0; //Score reset
  109. }
  110.  
  111. //-Choosing a random person-//
  112. public ZufallKira(playerid)
  113. {
  114.     if(gConnected >= 3)
  115.     {
  116.         new X = 0;
  117.  
  118.         while(X == 0)
  119.         {
  120.             new NeuKira = random(MAX_PLAYERS);
  121.  
  122.             if(IsPlayerConnected(NeuKira) && NeuKira != playerid)
  123.             {
  124.                 gKiraID = NeuKira;
  125.                 SendClientMessage(NeuKira, YELLOW, "Du hast nun die Macht/das Notizbuch");
  126.                 X = 1;
  127.             }
  128.         }
  129.     }
  130. }
  131.  
  132. //-Managing the score-//
  133.  
  134. public OnPlayerDeath(playerid, killerid, reason)
  135. {
  136.     SendDeathMessage(killerid, playerid, reason);
  137.  
  138.     if(playerid == gKiraID && killerid != INVALID_PLAYER_ID)
  139.     {
  140.         gScore[killerid] = gScore[killerid]+3;
  141.         SetPlayerScore(killerid, gScore[killerid]);
  142.         SendClientMessage(killerid, YELLOW, "Du hast Kira erwischt: +3Punkte");
  143.  
  144.         new Killer[MAX_PLAYER_NAME], Ausgabe[48];
  145.         GetPlayerName(killerid, Killer, sizeof(Killer));
  146.         format(Ausgabe, sizeof(Ausgabe), "%s hat Kira erledigt", Killer);
  147.         SendClientMessageToAll(YELLOW, Ausgabe);
  148.  
  149.         SendClientMessage(playerid, YELLOW, "Der Zentralrat der Shinigami ist emp�rt!");
  150.         gScore[playerid] = gScore[playerid]-3;
  151.         SetPlayerScore(playerid, gScore[playerid]);
  152.  
  153.         ZufallKira(playerid);
  154.     }
  155.     else
  156.     {
  157.         gScore[killerid] = gScore[killerid]-1;
  158.         SetPlayerScore(killerid, gScore[killerid]);
  159.     }
  160.  
  161. }
  162.  
  163. //-Spawn-//
  164.  
  165. public OnPlayerSpawn(playerid)
  166. {
  167.     SetPlayerRandomSpawn(playerid);
  168. }
  169.  
  170. //RandomSpawn
  171.  
  172. public SetPlayerRandomSpawn(playerid)
  173. {
  174.     new rand = random(sizeof(gRandomSpawns));
  175.     SetPlayerPos(playerid, gRandomSpawns[rand][0], gRandomSpawns[rand][1], gRandomSpawns[rand][2]);
  176. }
  177.  
  178. //-Player Input-//
  179.  
  180. public OnPlayerCommandText(playerid, cmdtext[])
  181. {
  182.     dcmd(hefteintrag, 11, cmdtext);
  183.     dcmd(menu, 4, cmdtext);
  184.     dcmd(Give, 4, cmdtext);
  185.     dcmd(asdf, 4, cmdtext);
  186.     return 0;
  187. }
  188.  
  189. //--If the current Kira is a dork, use this--//
  190.  
  191. dcmd_asdf(playerid, params[])
  192. {
  193.     if(IsPlayerAdmin(playerid))
  194.     {
  195.         new str[128];
  196.         format(str, sizeof(str), "Aktuelle Teilnehmerzahl: %d", gConnected);
  197.         SendClientMessage(playerid, GREEN, str);
  198.         ZufallKira(gKiraID);
  199.     }
  200. }
  201.  
  202. //--Give the Death Note to somebody--//
  203.  
  204. dcmd_Give(playerid, params[])
  205. {
  206.     new NewKira;
  207.  
  208.     if(sscanf(params, "d", NewKira))
  209.     {
  210.         SendClientMessage(playerid, GREEN, "Verwendung: /Give <neuerKira>");
  211.     }
  212.     else
  213.     {
  214.         SetKira(playerid, NewKira);
  215.     }
  216. }
  217.  
  218. //-Choose Kira by ID-//
  219.  
  220. public SetKira(playerid, neukira)
  221. {
  222.     if(playerid == gKiraID)
  223.     {
  224.         gKiraID = neukira;
  225.  
  226.         new NeuKiraName[MAX_PLAYER_NAME], AusgabeA[48];
  227.         GetPlayerName(neukira, NeuKiraName, sizeof(NeuKiraName));
  228.         format(AusgabeA, sizeof(AusgabeA), "Du hast %s das Death Note gegeben", NeuKiraName);
  229.  
  230.         new AltKiraName[MAX_PLAYER_NAME], AusgabeB[48];
  231.         GetPlayerName(playerid, AltKiraName, sizeof(AltKiraName));
  232.         format(AusgabeB, sizeof(AusgabeB), "%s hat dir das Death Note gegeben", AltKiraName);
  233.  
  234.         SendClientMessage(playerid, YELLOW, AusgabeA);
  235.         SendClientMessage(neukira, YELLOW, AusgabeB);
  236.         SendClientMessage(neukira, YELLOW, "nutze deine Macht weise!");
  237.     }
  238.     else
  239.     {
  240.         SendClientMessage(playerid, GREEN, "Du musst das Death Note schon besitzen um es weiterzugeben...");
  241.     }
  242. }
  243.  
  244. //-Create an entry with CMD-//
  245.  
  246. dcmd_hefteintrag(playerid, params[])
  247. {
  248.     if(playerid == gKiraID)
  249.     {
  250.         new Opfer,
  251.         Zeit,
  252.         Art;
  253.  
  254.         if(sscanf(params, "ddd", Opfer, Zeit, Art))
  255.         {
  256.             SendClientMessage(playerid, GREEN, "/hefteintrag [OpferID] [Verz�gerung] [TodesArtID]");
  257.         }
  258.         else
  259.         {
  260.             //Filling the line of the array
  261.             Threads[NeueZeile][1] = playerid;
  262.             Threads[NeueZeile][2] = Opfer;
  263.             Threads[NeueZeile][3] = gTimer;
  264.             Threads[NeueZeile][4] = gTimer + Zeit;
  265.             Threads[NeueZeile][5] = Art;
  266.             Threads[NeueZeile][6] = 1;
  267.             Threads[NeueZeile][0] = NeueZeile;
  268.             SendClientMessage(playerid, GREEN, "Eintrag angefertigt");
  269.             printf("Kira: %d %d %d %d %d %d %d", Threads[NeueZeile][0], Threads[NeueZeile][1],  Threads[NeueZeile][2],  Threads[NeueZeile][3],  Threads[NeueZeile][4], Threads[NeueZeile][5], Threads[NeueZeile][6]);
  270.             NeueZeile++; //jump to the next line, so the function won't overwrite the older entries
  271.         }
  272.     }
  273.     else
  274.     {
  275.        SendClientMessage(playerid, GREEN, "Ohne Death Note funktioniert das nicht");
  276.     }
  277. }
  278.  
  279. //-Create an entry the easier way, menu-//
  280.  
  281. dcmd_menu(playerid, params[])
  282. {
  283.     if(playerid == gKiraID)
  284.     {
  285.         CreatePersonMenu(); //Creates the first menu new (to be sure that there are no people on offliner on the list)
  286.         gMenuLine = NeueZeile; //Sets the Line the following functions will write in
  287.         ShowMenuForPlayer(KiraPerson, playerid);
  288.     }
  289.     else
  290.     {
  291.         SendClientMessage(playerid, GREEN, "Ohne Death Note funktioniert das nicht");
  292.     }
  293. }
  294.  
  295. //-Creates the first menu-//
  296.  
  297. public CreatePersonMenu()
  298. {
  299.     DestroyMenu(KiraPerson);
  300.     KiraPerson = CreateMenu("Death Note", 1, 200.0, 100.0, 150.0, 150.0);
  301.  
  302.     new x=0;
  303.     new y=0;
  304.     while(x < 1000)
  305.     {
  306.         if(IsPlayerConnected(x))
  307.         {
  308.             new name[MAX_PLAYER_NAME];
  309.             GetPlayerName(x, name, sizeof(name));
  310.             AddMenuItem(KiraPerson, 0, name);
  311.             RowStore[y] = x;
  312.             y++;
  313.             x++;
  314.         }
  315.         else
  316.         {
  317.             x++;
  318.         }
  319.     }
  320. }
  321.  
  322. //--->Second Menu is static ->Init
  323.  
  324. //-Creates third menu-//
  325.  
  326. public CreateTimeMenu()
  327. {
  328.     DestroyMenu(KiraZeit);
  329.     KiraZeit = CreateMenu("Zeit", 1, 200.0, 100.0, 150.0, 150.0);
  330.  
  331.     new str[128];
  332.     format(str, sizeof(str), "Zeit: %d", gMenuTime);
  333.     SetMenuColumnHeader(KiraZeit, 0, str);
  334.     AddMenuItem(KiraZeit, 0, "+10");
  335.     AddMenuItem(KiraZeit, 0, "-10");
  336.     AddMenuItem(KiraZeit, 0, "Confirm");
  337.  
  338. }
  339.  
  340. public RefreshMenuHeader(playerid)
  341. {
  342.     new str[128];
  343.     format(str, sizeof(str), "Zeit: %d", gMenuTime);
  344.     SetMenuColumnHeader(KiraZeit, 0 ,str);
  345.     ShowMenuForPlayer(KiraZeit,playerid);
  346. }
  347.  
  348. //-Making the menus work-//
  349.  
  350. public OnPlayerSelectedMenuRow(playerid, row)
  351. {
  352.     new Menu:CurrentMenu = GetPlayerMenu(playerid);
  353.  
  354.     gMenuLine = NeueZeile;
  355. //------------------------------------------------------------------------------
  356.     if(CurrentMenu == KiraPerson)
  357.     {
  358.         Threads[gMenuLine][1] = playerid; //Writing the ID of Kira
  359.         Threads[gMenuLine][2] = RowStore[row]; //Writing the ID of the Victim
  360.         Threads[gMenuLine][0] = gMenuLine; //unnecessary?
  361.         ShowMenuForPlayer(KiraTodesart, playerid); //lead Player to the next menu
  362.     }
  363. //------------------------------------------------------------------------------
  364.     else if(CurrentMenu == KiraTodesart)
  365.     {
  366.         gMenuTime = 10;
  367.         CreateTimeMenu();
  368.  
  369.         switch(row)
  370.         {
  371.             case 0:
  372.             {
  373.                 Threads[gMenuLine][5] = 1;
  374.                 ShowMenuForPlayer(KiraZeit, playerid);
  375.             }
  376.             case 1:
  377.             {
  378.                 Threads[gMenuLine][5] = 2;
  379.                 ShowMenuForPlayer(KiraZeit, playerid);
  380.             }
  381.             case 2:
  382.             {
  383.                 Threads[gMenuLine][5] = 3;
  384.                 ShowMenuForPlayer(KiraZeit, playerid);
  385.             }
  386.         }
  387.     }
  388. //------------------------------------------------------------------------------
  389.     else if(CurrentMenu == KiraZeit)
  390.     {
  391.         switch(row)
  392.         {
  393.             case 0:
  394.             {
  395.                 gMenuTime = gMenuTime+10;
  396.                 RefreshMenuHeader(playerid);
  397.             }
  398.             case 1:
  399.             {
  400.                 if(gMenuTime >= 20)
  401.                 {
  402.                 gMenuTime = gMenuTime-10;
  403.                 }
  404.                 RefreshMenuHeader(playerid);
  405.             }
  406.             case 2:
  407.             {
  408.                 Threads[gMenuLine][3] = gTimer;
  409.                 Threads[gMenuLine][4] = gTimer+gMenuTime;
  410.                 Threads[gMenuLine][6] = 1; //Activates the entry
  411.                 NeueZeile++;
  412.                 printf("Kira: %d %d %d %d %d %d %d", Threads[gMenuLine][0], Threads[gMenuLine][1],  Threads[gMenuLine][2],  Threads[gMenuLine][3],  Threads[gMenuLine][4], Threads[gMenuLine][5], Threads[gMenuLine][6]);
  413.             }
  414.         }
  415.     }
  416. //------------------------------------------------------------------------------
  417.     return 1;
  418. }
  419.  
  420. //-Now the array contains informaton, so it's time to read it out (one time per second)-//
  421.  
  422. public Call()
  423. {
  424.     new count;
  425.     gTimer++; //Counting seconds...
  426.     while(count < 1000) //Searching for active lines in the Death Note
  427.     {
  428.         if(Threads[count][6] == 1)
  429.         {
  430.             Auswerter(Threads[count][0]); //Transfering the information to the next function
  431.         }
  432.         count++;
  433.     }
  434. }
  435.  
  436. //-Checking how the victim will die-//
  437.  
  438. public Auswerter(HandleID)
  439. {
  440.     switch(Threads[HandleID][5])
  441.     {
  442.         case 1:
  443.         {
  444.         Infarkt(HandleID);
  445.         }
  446.         case 2:
  447.         {
  448.         Sturz(HandleID);
  449.         }
  450.         case 3:
  451.         {
  452.         Explosion(HandleID);
  453.         }
  454.     }
  455. }
  456.  
  457. //-Different Ways to die-//
  458. //Heart
  459. public Infarkt(HandleID)
  460. {
  461.     if(gTimer == Threads[HandleID][4]) //Waiting for the right time
  462.     {
  463.         CarKick(Threads[HandleID][2]);
  464.         ApplyAnimation(Threads[HandleID][2], "CRACK", "crckdeth3", 1, 1, 1, 1, 1, 1);
  465.     }
  466.     else if(gTimer == Threads[HandleID][4]+4)
  467.     {
  468.         ClearAnimations(Threads[HandleID][2]);
  469.         SetPlayerHealth(Threads[HandleID][2], 0); //Kill him
  470.         Threads[HandleID][6] = 0; //Don't kill him twice
  471.     }
  472. }
  473.  
  474. //Fall
  475. public Sturz(HandleID)
  476. {
  477.     if(gTimer == Threads[HandleID][4])
  478.     {
  479.         new Float:PosX, Float:PosY, Float:PosZ;
  480.         GetPlayerPos(Threads[HandleID][2], PosX, PosY, PosZ);
  481.         PosZ = PosZ + 300;
  482.         SetPlayerPos(Threads[HandleID][2], PosX, PosY, PosZ);
  483.     }
  484.     else if(gTimer == Threads[HandleID][4]+6)
  485.     {
  486.         SetPlayerHealth(Threads[HandleID][2], 0);
  487.         Threads[HandleID][6] = 0;
  488.     }
  489. }
  490.  
  491. //Explosion
  492. public Explosion(HandleID)
  493. {
  494.     if(gTimer == Threads[HandleID][4])
  495.     {
  496.         new Float:PosX, Float:PosY, Float:PosZ;
  497.         GetPlayerPos(Threads[HandleID][2], PosX, PosY, PosZ);
  498.         CreateExplosion(PosX, PosY, PosZ, 6, 10.0);
  499.         SetPlayerHealth(Threads[HandleID][2], 0);
  500.         Threads[HandleID][6] = 0;
  501.     }
  502. }
  503.  
  504. //-Remove from Vehicle-//
  505. public CarKick(playerid)
  506. {
  507.     if(IsPlayerInAnyVehicle(playerid))
  508.     {
  509.         RemovePlayerFromVehicle(playerid);
  510.     }
  511. }
  512.  
  513. //------------------------------------------------------------------------------
  514. /*----------------------------------------------------------------------------*-
  515. Function:
  516.     sscanf
  517. Params:
  518.     string[] - String to extract parameters from.
  519.     format[] - Parameter types to get.
  520.     {Float,_}:... - Data return variables.
  521. Return:
  522.     0 - Successful, not 0 - fail.
  523. Notes:
  524.     A fail is either insufficient variables to store the data or insufficient
  525.     data for the format string - excess data is disgarded.
  526.  
  527.     A string in the middle of the input data is extracted as a single word, a
  528.     string at the end of the data collects all remaining text.
  529.  
  530.     The format codes are:
  531.  
  532.     c - A character.
  533.     d, i - An integer.
  534.     h, x - A hex number (e.g. a colour).
  535.     f - A float.
  536.     s - A string.
  537.     z - An optional string.
  538.     pX - An additional delimiter where X is another character.
  539.     '' - Encloses a litteral string to locate.
  540.     u - User, takes a name, part of a name or an id and returns the id if they're connected.
  541.  
  542.     Now has IsNumeric integrated into the code.
  543.  
  544.     Added additional delimiters in the form of all whitespace and an
  545.     optioanlly specified one in the format string.
  546. -*----------------------------------------------------------------------------*/
  547.  
  548. stock sscanf(string[], format[], {Float,_}:...)
  549. {
  550.     #if defined isnull
  551.         if (isnull(string))
  552.     #else
  553.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  554.     #endif
  555.         {
  556.             return format[0];
  557.         }
  558.     #pragma tabsize 4
  559.     new
  560.         formatPos = 0,
  561.         stringPos = 0,
  562.         paramPos = 2,
  563.         paramCount = numargs(),
  564.         delim = ' ';
  565.     while (string[stringPos] && string[stringPos] <= ' ')
  566.     {
  567.         stringPos++;
  568.     }
  569.     while (paramPos < paramCount && string[stringPos])
  570.     {
  571.         switch (format[formatPos++])
  572.         {
  573.             case '\0':
  574.             {
  575.                 return 0;
  576.             }
  577.             case 'i', 'd':
  578.             {
  579.                 new
  580.                     neg = 1,
  581.                     num = 0,
  582.                     ch = string[stringPos];
  583.                 if (ch == '-')
  584.                 {
  585.                     neg = -1;
  586.                     ch = string[++stringPos];
  587.                 }
  588.                 do
  589.                 {
  590.                     stringPos++;
  591.                     if ('0' <= ch <= '9')
  592.                     {
  593.                         num = (num * 10) + (ch - '0');
  594.                     }
  595.                     else
  596.                     {
  597.                         return -1;
  598.                     }
  599.                 }
  600.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  601.                 setarg(paramPos, 0, num * neg);
  602.             }
  603.             case 'h', 'x':
  604.             {
  605.                 new
  606.                     num = 0,
  607.                     ch = string[stringPos];
  608.                 do
  609.                 {
  610.                     stringPos++;
  611.                     switch (ch)
  612.                     {
  613.                         case 'x', 'X':
  614.                         {
  615.                             num = 0;
  616.                             continue;
  617.                         }
  618.                         case '0' .. '9':
  619.                         {
  620.                             num = (num << 4) | (ch - '0');
  621.                         }
  622.                         case 'a' .. 'f':
  623.                         {
  624.                             num = (num << 4) | (ch - ('a' - 10));
  625.                         }
  626.                         case 'A' .. 'F':
  627.                         {
  628.                             num = (num << 4) | (ch - ('A' - 10));
  629.                         }
  630.                         default:
  631.                         {
  632.                             return -1;
  633.                         }
  634.                     }
  635.                 }
  636.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  637.                 setarg(paramPos, 0, num);
  638.             }
  639.             case 'c':
  640.             {
  641.                 setarg(paramPos, 0, string[stringPos++]);
  642.             }
  643.             case 'f':
  644.             {
  645.  
  646.                 new changestr[16], changepos = 0, strpos = stringPos;
  647.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  648.                 {
  649.                     changestr[changepos++] = string[strpos++];
  650.                     }
  651.                 changestr[changepos] = '\0';
  652.                 setarg(paramPos,0,_:floatstr(changestr));
  653.             }
  654.             case 'p':
  655.             {
  656.                 delim = format[formatPos++];
  657.                 continue;
  658.             }
  659.             case '\'':
  660.             {
  661.                 new
  662.                     end = formatPos - 1,
  663.                     ch;
  664.                 while ((ch = format[++end]) && ch != '\'') {}
  665.                 if (!ch)
  666.                 {
  667.                     return -1;
  668.                 }
  669.                 format[end] = '\0';
  670.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  671.                 {
  672.                     if (format[end + 1])
  673.                     {
  674.                         return -1;
  675.                     }
  676.                     return 0;
  677.                 }
  678.                 format[end] = '\'';
  679.                 stringPos = ch + (end - formatPos);
  680.                 formatPos = end + 1;
  681.             }
  682.             case 'u':
  683.             {
  684.                 new
  685.                     end = stringPos - 1,
  686.                     id = 0,
  687.                     bool:num = true,
  688.                     ch;
  689.                 while ((ch = string[++end]) && ch != delim)
  690.                 {
  691.                     if (num)
  692.                     {
  693.                         if ('0' <= ch <= '9')
  694.                         {
  695.                             id = (id * 10) + (ch - '0');
  696.                         }
  697.                         else
  698.                         {
  699.                             num = false;
  700.                         }
  701.                     }
  702.                 }
  703.                 if (num && IsPlayerConnected(id))
  704.                 {
  705.                     setarg(paramPos, 0, id);
  706.                 }
  707.                 else
  708.                 {
  709.                     #if !defined foreach
  710.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  711.                         #define __SSCANF_FOREACH__
  712.                     #endif
  713.                     string[end] = '\0';
  714.                     num = false;
  715.                     new
  716.                         name[MAX_PLAYER_NAME];
  717.                     id = end - stringPos;
  718.                     foreach (Player, playerid)
  719.                     {
  720.                         GetPlayerName(playerid, name, sizeof (name));
  721.                         if (!strcmp(name, string[stringPos], true, id))
  722.                         {
  723.                             setarg(paramPos, 0, playerid);
  724.                             num = true;
  725.                             break;
  726.                         }
  727.                     }
  728.                     if (!num)
  729.                     {
  730.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  731.                     }
  732.                     string[end] = ch;
  733.                     #if defined __SSCANF_FOREACH__
  734.                         #undef foreach
  735.                         #undef __SSCANF_FOREACH__
  736.                     #endif
  737.                 }
  738.                 stringPos = end;
  739.             }
  740.             case 's', 'z':
  741.             {
  742.                 new
  743.                     i = 0,
  744.                     ch;
  745.                 if (format[formatPos])
  746.                 {
  747.                     while ((ch = string[stringPos++]) && ch != delim)
  748.                     {
  749.                         setarg(paramPos, i++, ch);
  750.                     }
  751.                     if (!i)
  752.                     {
  753.                         return -1;
  754.                     }
  755.                 }
  756.                 else
  757.                 {
  758.                     while ((ch = string[stringPos++]))
  759.                     {
  760.                         setarg(paramPos, i++, ch);
  761.                     }
  762.                 }
  763.                 stringPos--;
  764.                 setarg(paramPos, i, '\0');
  765.             }
  766.             default:
  767.             {
  768.                 continue;
  769.             }
  770.         }
  771.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  772.         {
  773.             stringPos++;
  774.         }
  775.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  776.         {
  777.             stringPos++;
  778.         }
  779.         paramPos++;
  780.     }
  781.     do
  782.     {
  783.         if ((delim = format[formatPos++]) > ' ')
  784.         {
  785.             if (delim == '\'')
  786.             {
  787.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  788.             }
  789.             else if (delim != 'z')
  790.             {
  791.                 return delim;
  792.             }
  793.         }
  794.     }
  795.     while (delim > ' ');
  796.     return 0;
  797. }
  798. //------------------------------------------------------------------------------
  799.  
  800.  
  801.  
  802.  
Advertisement
Add Comment
Please, Sign In to add comment