Juuh

x-Drogas.pwn

Jul 14th, 2013
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 20.45 KB | None | 0 0
  1. #include    < a_samp >
  2. #include    < zcmd >
  3. #include    < DOF2 >
  4. #define MAX_OBJ 50
  5.  
  6. enum dDrogasEnum
  7. {
  8.     OID,
  9.     Text3D:TID,
  10.     DDATA[2],
  11.     Float:OPOS[3]
  12. };
  13.  
  14. enum pDrogasEnum
  15. {
  16.     pMaconha,
  17.     pCocaina,
  18.     pCrack
  19. }
  20.  
  21. new pInfoDrogas[MAX_PLAYERS][pDrogasEnum];
  22. new iDrogaData[MAX_OBJ][dDrogasEnum];
  23.  
  24. public OnFilterScriptInit(){for(new n = 0; n < MAX_OBJ; n++) iDrogaData[n][OID] = -1;return 1;}
  25. public OnFilterScriptExit(){DOF2_Exit();return 1;}
  26. public OnPlayerSpawn(playerid){CarregarDrogas(playerid);return 1;}
  27. public OnPlayerConnect(playerid){if(!DOF2_FileExists(NomeDoArquivo(playerid))) DOF2_CreateFile(NomeDoArquivo(playerid));return 1;}
  28. public OnPlayerDisconnect(playerid){SalvarDrogas(playerid);return 1;}
  29.  
  30. CMD:drogas(playerid)
  31. {
  32.     SendClientMessage(playerid, -1,"[X] </minhasdrogas/usardrogas/dardrogas/deixardrogas/pegardrogas/> ");
  33.     return 1;
  34. }
  35.  
  36. CMD:minhasdrogas(playerid)
  37. {
  38.     new _String[128];
  39.     SendClientMessage(playerid, 0x33AA3300, "____Minhas Drogas____");
  40.     format(_String, sizeof(_String), "[X]Info.Drogas.Maconha [%d]", pInfoDrogas[playerid][pMaconha]);
  41.     SendClientMessage(playerid, 0x33AA3300, _String);
  42.     format(_String, sizeof(_String), "[X]Info.Drogas.Cocaina [%d]", pInfoDrogas[playerid][pCocaina]);
  43.     SendClientMessage(playerid, 0x33AA3300, _String);
  44.     format(_String, sizeof(_String), "[X]Info.Drogas.Crack [%d]", pInfoDrogas[playerid][pCrack]);
  45.     SendClientMessage(playerid, 0x33AA3300, _String);
  46.     SendClientMessage(playerid, 0x33AA3300, "____Minhas Drogas____");
  47.     return true;
  48. }
  49.  
  50. CMD:dorgas(playerid)
  51. {
  52.     if(IsPlayerAdmin(playerid))
  53.     {
  54.         pInfoDrogas[playerid][pMaconha] = 100;
  55.         pInfoDrogas[playerid][pCocaina] = 100;
  56.         pInfoDrogas[playerid][pCrack] = 100;
  57.     }
  58.     return 1;
  59. }
  60.  
  61. CMD:usardrogas(playerid, params [])
  62. {
  63.     new tipo;
  64.     if(sscanf(params, "d", tipo)) return SendClientMessage(playerid, -1, "[X]<tipo>/<1 = Cocaina, 2 = Crack, 3 = Maconha>");
  65.     if(tipo == 1)
  66.     {
  67.         RemovePlayerCocaina(playerid, 3);
  68.         SetPlayerDrunkLevel(playerid, 2005);
  69.         SetPlayerWeather(playerid, -22);
  70.         SetTimerEx("DrogasPararEfeito",420000,false,"d",playerid);
  71.         ApplyAnimation(playerid, "MISC", "plyr_shkhead", 4.1, 0, 0, 0, 0, 0);
  72.         SendClientMessage(playerid, -1, "[X]Você usou 3 gramas de cocaina.");
  73.     }
  74.     if(tipo == 2)
  75.     {
  76.         RemovePlayerCrack(playerid, 3);
  77.         SetPlayerSpecialAction(playerid, SPECIAL_ACTION_SMOKE_CIGGY);
  78.         SetPlayerDrunkLevel(playerid, 2005);
  79.         SetPlayerWeather(playerid, -22);
  80.         SetTimerEx("DrogasPararEfeito",420000,false,"d",playerid);
  81.         SendClientMessage(playerid, -1, "[X]Você usou 3 gramas de crack.");
  82.     }
  83.     if(tipo == 3)
  84.     {
  85.         RemovePlayerMaconha(playerid, 3);
  86.         SetPlayerSpecialAction(playerid, SPECIAL_ACTION_SMOKE_CIGGY);
  87.         SetPlayerWeather(playerid, -22);
  88.         SetTimerEx("DrogasPararEfeito",420000,false,"d",playerid);
  89.         SendClientMessage(playerid, -1, "[X]Você usou 3 gramas de maconha.");
  90.     }
  91.     return 1;
  92. }
  93.  
  94. CMD:dardrogas(playerid, params [])
  95. {
  96.     new id, tipo, quant;
  97.     if(sscanf(params, "idd", id, tipo, quant)) return SendClientMessage(playerid, -1, "[X]<id/tipo/quantidade>/<1 = cocaina, 2 = Crack, 3 = Maconha>");
  98.     if(!IsPlayerConnected(id)) return SendClientMessage(playerid, -1, "[X]Jogador não conectado.");
  99.     if(tipo == 1)
  100.     {
  101.         if(pInfoDrogas[playerid][pCocaina] > 0)
  102.         {
  103.             if(pInfoDrogas[playerid][pCocaina] > quant)
  104.             {
  105.                 new _String[128];
  106.                 new idname[MAX_PLAYER_NAME];
  107.                 new playeridname[MAX_PLAYER_NAME];
  108.                 GetPlayerName(id, idname, sizeof(idname));
  109.                 GetPlayerName(playerid, playeridname, sizeof(playeridname));
  110.  
  111.                 RemovePlayerCocaina(playerid, quant);
  112.                 GivePlayerCocaina(id, quant);
  113.  
  114.                 format(_String, sizeof(_String), "[X]Voce entregou drogas para %s.", idname);
  115.                 SendClientMessage(playerid, 0x33AA3300, _String);
  116.                 format(_String, sizeof(_String), "[X]Voce recebeu drogas de %s.", playeridname);
  117.                 SendClientMessage(id, 0x33AA3300, _String);
  118.             }
  119.             else
  120.             {
  121.                 SendClientMessage(playerid, -1, "[X]A quantidade que você possue é menor.");
  122.             }
  123.         }
  124.         else
  125.         {
  126.             SendClientMessage(playerid, -1, "[X]Você não tem Cocaina.");
  127.         }
  128.     }
  129.     else if(tipo == 2)
  130.     {
  131.         if(pInfoDrogas[playerid][pCrack] > 0)
  132.         {
  133.             if(pInfoDrogas[playerid][pCrack] > quant)
  134.             {
  135.                 new _String[128];
  136.                 new idname[MAX_PLAYER_NAME];
  137.                 new playeridname[MAX_PLAYER_NAME];
  138.                 GetPlayerName(id, idname, sizeof(idname));
  139.                 GetPlayerName(playerid, playeridname, sizeof(playeridname));
  140.  
  141.                 RemovePlayerCrack(playerid, quant);
  142.                 GivePlayerCrack(id, quant);
  143.  
  144.                 format(_String, sizeof(_String), "[X]Voce entregou drogas para %s.", idname);
  145.                 SendClientMessage(playerid, 0x33AA3300, _String);
  146.                 format(_String, sizeof(_String), "[X]Voce recebeu drogas de %s.", playeridname);
  147.                 SendClientMessage(id, 0x33AA3300, _String);
  148.             }
  149.             else
  150.             {
  151.                 SendClientMessage(playerid, -1, "[X]A quantidade que você possue é menor.");
  152.             }
  153.         }
  154.         else
  155.         {
  156.             SendClientMessage(playerid, -1, "[X]Você não tem Crack.");
  157.         }
  158.     }
  159.     else if(tipo == 3)
  160.     {
  161.         if(pInfoDrogas[playerid][pMaconha] > 0)
  162.         {
  163.             if(pInfoDrogas[playerid][pMaconha] > quant)
  164.             {
  165.                 new _String[128];
  166.                 new idname[MAX_PLAYER_NAME];
  167.                 new playeridname[MAX_PLAYER_NAME];
  168.                 GetPlayerName(id, idname, sizeof(idname));
  169.                 GetPlayerName(playerid, playeridname, sizeof(playeridname));
  170.  
  171.                 RemovePlayerMaconha(playerid, quant);
  172.                 GivePlayerMaconha(id, quant);
  173.  
  174.                 format(_String, sizeof(_String), "[X]Voce entregou drogas para %s.", idname);
  175.                 SendClientMessage(playerid, 0x33AA3300, _String);
  176.                 format(_String, sizeof(_String), "[X]Voce recebeu drogas de %s.", playeridname);
  177.                 SendClientMessage(id, 0x33AA3300, _String);
  178.             }
  179.             else
  180.             {
  181.                 SendClientMessage(playerid, -1, "[X]A quantidade que você possue é menor.");
  182.             }
  183.         }
  184.         else
  185.         {
  186.             SendClientMessage(playerid, -1, "[X]Você não tem Maconha.");
  187.         }
  188.     }
  189.     return 1;
  190. }
  191.  
  192. CMD:deixardrogas(playerid, params [])
  193. {
  194.     new _String[128];
  195.     new tipo, quant;
  196.     new f = MAX_OBJ+1;
  197.     if(sscanf(params, "dd", tipo, quant)) return SendClientMessage(playerid, -1, "[X]<tipo/quantidade>");
  198.     if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
  199.     for(new a = 0; a < MAX_OBJ; a++)
  200.     {
  201.         if(iDrogaData[a][OPOS][0] == 0.0)
  202.         {
  203.             f = a;
  204.             break;
  205.         }
  206.     }
  207.     if(f > MAX_OBJ) return SendClientMessage(playerid, 0x33AA3300, "[X]O maximo de itens no chao foi atingido, por favor relate a um administrador.");
  208.     if(tipo == 1)
  209.     {
  210.         if(pInfoDrogas[playerid][pCocaina] >= quant)
  211.         {
  212.             GetPlayerPos(playerid, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2]);
  213.             iDrogaData[f][OID] = CreateObject(1580, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2]-1, 0.0, 0.0, 0.0);
  214.             format(_String, sizeof(_String), "<Cocaina>\n[X]Quantidade:\n%d\n</>", quant);
  215.             iDrogaData[f][TID] = Create3DTextLabel(_String, -1, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2], 3.0, 0, 0);
  216.             SendClientMessage(playerid, 0x33AA3300, "[X]Você largou um pacote de cocaina.");
  217.             RemovePlayerCocaina(playerid, quant);
  218.             iDrogaData[f][DDATA][0] = tipo;
  219.             iDrogaData[f][DDATA][1] = quant;
  220.         }
  221.     }
  222.     else if(tipo == 2)
  223.     {
  224.         if(pInfoDrogas[playerid][pCrack] >= quant)
  225.         {
  226.             GetPlayerPos(playerid, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2]);
  227.             iDrogaData[f][OID] = CreateObject(1580, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2]-1, 0.0, 0.0, 0.0);
  228.             format(_String, sizeof(_String), "<Crack>\n[X]Quantidade:\n%d\n</>", quant);
  229.             iDrogaData[f][TID] = Create3DTextLabel(_String, -1, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2], 3.0, 0, 0);
  230.             SendClientMessage(playerid, 0x33AA3300, "[X]Você largou um pacote de crack");
  231.             RemovePlayerCrack(playerid, quant);
  232.             iDrogaData[f][DDATA][0] = tipo;
  233.             iDrogaData[f][DDATA][1] = quant;
  234.         }
  235.     }
  236.     else if(tipo == 3)
  237.     {
  238.         if(pInfoDrogas[playerid][pMaconha] >= quant)
  239.         {
  240.             GetPlayerPos(playerid, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2]);
  241.             iDrogaData[f][OID] = CreateObject(1580, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2]-1, 0.0, 0.0, 0.0);
  242.             format(_String, sizeof(_String), "<Maconha>\n[X]Quantidade:\n%d\n</>", quant);
  243.             iDrogaData[f][TID] = Create3DTextLabel(_String, -1, iDrogaData[f][OPOS][0], iDrogaData[f][OPOS][1], iDrogaData[f][OPOS][2], 3.0, 0, 0);
  244.             SendClientMessage(playerid, 0x33AA3300, "[X]Você largou um pacote de maconha");
  245.             RemovePlayerMaconha(playerid, quant);
  246.             iDrogaData[f][DDATA][0] = tipo;
  247.             iDrogaData[f][DDATA][1] = quant;
  248.         }
  249.     }
  250.     return 1;
  251. }
  252.  
  253. CMD:pegardrogas(playerid)
  254. {
  255.     new tipo;
  256.     new f = MAX_OBJ+1;
  257.     new pegou; pegou = 5;
  258.     if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
  259.     for(new a = 0; a < MAX_OBJ; a++)
  260.     {
  261.         if(IsPlayerInRangeOfPoint(playerid, 1.0, iDrogaData[a][OPOS][0], iDrogaData[a][OPOS][1], iDrogaData[a][OPOS][2]))
  262.         {
  263.             f = a;
  264.             pegou = 10;
  265.             break;
  266.         }
  267.     }
  268.     if(f > MAX_OBJ) return SendClientMessage(playerid, 0x33AA3300, "[X]Você não pode pegar, pois não tem nada no chao.");
  269.     tipo = iDrogaData[f][DDATA][0];
  270.     if(pegou == 10)
  271.     {
  272.         if(tipo == 1)
  273.         {
  274.             pegou = 5;
  275.             DestroyObject(iDrogaData[f][OID]);
  276.             Delete3DTextLabel(iDrogaData[f][TID]);
  277.             GivePlayerCocaina(playerid, iDrogaData[f][DDATA][1]);
  278.             SendClientMessage(playerid, 0x33AA3300, "[X]Você pegou a cocaina que havia no chão.");
  279.         }
  280.         if(tipo == 2)
  281.         {
  282.             pegou = 5;
  283.             DestroyObject(iDrogaData[f][OID]);
  284.             Delete3DTextLabel(iDrogaData[f][TID]);
  285.             GivePlayerCrack(playerid, iDrogaData[f][DDATA][1]);
  286.             SendClientMessage(playerid, 0x33AA3300, "[X]Você pegou o crack que havia no chão.");
  287.         }
  288.         if(tipo == 3)
  289.         {
  290.             pegou = 5;
  291.             DestroyObject(iDrogaData[f][OID]);
  292.             Delete3DTextLabel(iDrogaData[f][TID]);
  293.             GivePlayerMaconha(playerid, iDrogaData[f][DDATA][1]);
  294.             SendClientMessage(playerid, 0x33AA3300, "[X]Você pegou a maconha que havia no chão.");
  295.         }
  296.     }
  297.     return 1;
  298. }
  299.  
  300. forward DrogasPararEfeito(playerid);
  301. public DrogasPararEfeito(playerid)
  302. {
  303.     SetPlayerWeather(playerid, 5);
  304. }
  305. //get
  306. stock GetPlayerCocaina(playerid)
  307. {
  308.     new Cocaina;
  309.     Cocaina = pInfoDrogas[playerid][pCocaina];
  310.     return Cocaina;
  311. }
  312. stock GetPlayerCrack(playerid)
  313. {
  314.     new Crack;
  315.     Crack = pInfoDrogas[playerid][pCrack];
  316.     return Crack;
  317. }
  318. stock GetPlayerMaconha(playerid)
  319. {
  320.     new Maconha;
  321.     Maconha = pInfoDrogas[playerid][pMaconha];
  322.     return Maconha;
  323. }
  324. //give
  325. stock GivePlayerCocaina(playerid, quantidade)
  326. {
  327.     pInfoDrogas[playerid][pCocaina] += quantidade;
  328.     return 1;
  329. }
  330. stock GivePlayerCrack(playerid, quantidade)
  331. {
  332.     pInfoDrogas[playerid][pCrack] += quantidade;
  333.     return 1;
  334. }
  335. stock GivePlayerMaconha(playerid, quantidade)
  336. {
  337.     pInfoDrogas[playerid][pMaconha] += quantidade;
  338.     return 1;
  339. }
  340. //remove
  341. stock RemovePlayerCocaina(playerid, quantidade)
  342. {
  343.     pInfoDrogas[playerid][pCocaina] -= quantidade;
  344.     return 1;
  345. }
  346. stock RemovePlayerCrack(playerid, quantidade)
  347. {
  348.     pInfoDrogas[playerid][pCrack] -= quantidade;
  349.     return 1;
  350. }
  351. stock RemovePlayerMaconha(playerid, quantidade)
  352. {
  353.     pInfoDrogas[playerid][pMaconha] -= quantidade;
  354.     return 1;
  355. }
  356.  
  357. /*stock SetPlayerCocaina(playerid, quantidade)
  358. {
  359.     pInfoDrogas[playerid][pCocaina] = quantidade;
  360. }
  361. stock SetPlayerCrack(playerid, quantidade)
  362. {
  363.     pInfoDrogas[playerid][pCrack] = quantidade;
  364. }
  365. stock SetPlayerMaconha(playerid, quantidade)
  366. {
  367.     pInfoDrogas[playerid][pMaconha] = quantidade;
  368. }
  369.  
  370. stock ResetPlayerDrug(playerid, tipo)
  371. {
  372.     new a;
  373.     a = tipo;
  374.     if(a == 0)
  375.     {
  376.         pInfoDrogas[playerid][pCocaina] = 0;
  377.         pInfoDrogas[playerid][pCrack] = 0;
  378.         pInfoDrogas[playerid][pMaconha] = 0;
  379.     }
  380.     if(a == 1){pInfoDrogas[playerid][pCocaina] = 0;}
  381.     if(a == 2){pInfoDrogas[playerid][pCrack] = 0;}
  382.     if(a == 3){pInfoDrogas[playerid][pMaconha] = 0;}
  383. }*/
  384.  
  385. stock CarregarDrogas(playerid)
  386. {
  387.     pInfoDrogas[playerid][pCocaina] = DOF2_GetInt(NomeDoArquivo(playerid), "Cocaina");
  388.     pInfoDrogas[playerid][pCrack] = DOF2_GetInt(NomeDoArquivo(playerid), "Crack");
  389.     pInfoDrogas[playerid][pMaconha] = DOF2_GetInt(NomeDoArquivo(playerid), "Maconha");
  390.     return 1;
  391. }
  392.  
  393.  
  394. stock NomeDoArquivo(playerid)
  395. {
  396.     new arquivo[40], name[MAX_PLAYER_NAME];
  397.     GetPlayerName(playerid, name, 32);
  398.     format(arquivo, 40, "Drogas/%s.ini", name);
  399.     return arquivo;
  400. }
  401.  
  402. stock SalvarDrogas(playerid)
  403. {
  404.     if(!DOF2_FileExists(NomeDoArquivo(playerid))) DOF2_CreateFile(NomeDoArquivo(playerid));
  405.     else
  406.     {
  407.  
  408.         DOF2_SetInt(NomeDoArquivo(playerid), "Cocaina", pInfoDrogas[playerid][pCocaina]);
  409.         DOF2_SetInt(NomeDoArquivo(playerid), "Crack", pInfoDrogas[playerid][pCrack]);
  410.         DOF2_SetInt(NomeDoArquivo(playerid), "Maconha", pInfoDrogas[playerid][pMaconha]);
  411.         DOF2_SaveFile();
  412.     }
  413.     return 1;
  414. }
  415.  
  416. stock sscanf(string[], format[], {Float,_}:...)
  417. {
  418.     #if defined isnull
  419.         if (isnull(string))
  420.     #else
  421.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  422.     #endif
  423.         {
  424.             return format[0];
  425.         }
  426.     #pragma tabsize 4
  427.     new
  428.         formatPos = 0,
  429.         stringPos = 0,
  430.         paramPos = 2,
  431.         paramCount = numargs(),
  432.         delim = ' ';
  433.     while (string[stringPos] && string[stringPos] <= ' ')
  434.     {
  435.         stringPos++;
  436.     }
  437.     while (paramPos < paramCount && string[stringPos])
  438.     {
  439.         switch (format[formatPos++])
  440.         {
  441.             case '\0':
  442.             {
  443.                 return 0;
  444.             }
  445.             case 'i', 'd':
  446.             {
  447.                 new
  448.                     neg = 1,
  449.                     num = 0,
  450.                     ch = string[stringPos];
  451.                 if (ch == '-')
  452.                 {
  453.                     neg = -1;
  454.                     ch = string[++stringPos];
  455.                 }
  456.                 do
  457.                 {
  458.                     stringPos++;
  459.                     if ('0' <= ch <= '9')
  460.                     {
  461.                         num = (num * 10) + (ch - '0');
  462.                     }
  463.                     else
  464.                     {
  465.                         return -1;
  466.                     }
  467.                 }
  468.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  469.                 setarg(paramPos, 0, num * neg);
  470.             }
  471.             case 'h', 'x':
  472.             {
  473.                 new
  474.                     num = 0,
  475.                     ch = string[stringPos];
  476.                 do
  477.                 {
  478.                     stringPos++;
  479.                     switch (ch)
  480.                     {
  481.                         case 'x', 'X':
  482.                         {
  483.                             num = 0;
  484.                             continue;
  485.                         }
  486.                         case '0' .. '9':
  487.                         {
  488.                             num = (num << 4) | (ch - '0');
  489.                         }
  490.                         case 'a' .. 'f':
  491.                         {
  492.                             num = (num << 4) | (ch - ('a' - 10));
  493.                         }
  494.                         case 'A' .. 'F':
  495.                         {
  496.                             num = (num << 4) | (ch - ('A' - 10));
  497.                         }
  498.                         default:
  499.                         {
  500.                             return -1;
  501.                         }
  502.                     }
  503.                 }
  504.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  505.                 setarg(paramPos, 0, num);
  506.             }
  507.             case 'c':
  508.             {
  509.                 setarg(paramPos, 0, string[stringPos++]);
  510.             }
  511.             case 'f':
  512.             {
  513.  
  514.                 new changestr[16], changepos = 0, strpos = stringPos;
  515.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  516.                 {
  517.                     changestr[changepos++] = string[strpos++];
  518.                     }
  519.                 changestr[changepos] = '\0';
  520.                 setarg(paramPos,0,_:floatstr(changestr));
  521.             }
  522.             case 'p':
  523.             {
  524.                 delim = format[formatPos++];
  525.                 continue;
  526.             }
  527.             case '\'':
  528.             {
  529.                 new
  530.                     end = formatPos - 1,
  531.                     ch;
  532.                 while ((ch = format[++end]) && ch != '\'') {}
  533.                 if (!ch)
  534.                 {
  535.                     return -1;
  536.                 }
  537.                 format[end] = '\0';
  538.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  539.                 {
  540.                     if (format[end + 1])
  541.                     {
  542.                         return -1;
  543.                     }
  544.                     return 0;
  545.                 }
  546.                 format[end] = '\'';
  547.                 stringPos = ch + (end - formatPos);
  548.                 formatPos = end + 1;
  549.             }
  550.             case 'u':
  551.             {
  552.                 new
  553.                     end = stringPos - 1,
  554.                     id = 0,
  555.                     bool:num = true,
  556.                     ch;
  557.                 while ((ch = string[++end]) && ch != delim)
  558.                 {
  559.                     if (num)
  560.                     {
  561.                         if ('0' <= ch <= '9')
  562.                         {
  563.                             id = (id * 10) + (ch - '0');
  564.                         }
  565.                         else
  566.                         {
  567.                             num = false;
  568.                         }
  569.                     }
  570.                 }
  571.                 if (num && IsPlayerConnected(id))
  572.                 {
  573.                     setarg(paramPos, 0, id);
  574.                 }
  575.                 else
  576.                 {
  577.                     #if !defined foreach
  578.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  579.                         #define __SSCANF_FOREACH__
  580.                     #endif
  581.                     string[end] = '\0';
  582.                     num = false;
  583.                     new
  584.                         name[MAX_PLAYER_NAME];
  585.                     id = end - stringPos;
  586.                     foreach (Player, playerid)
  587.                     {
  588.                         GetPlayerName(playerid, name, sizeof (name));
  589.                         if (!strcmp(name, string[stringPos], true, id))
  590.                         {
  591.                             setarg(paramPos, 0, playerid);
  592.                             num = true;
  593.                             break;
  594.                         }
  595.                     }
  596.                     if (!num)
  597.                     {
  598.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  599.                     }
  600.                     string[end] = ch;
  601.                     #if defined __SSCANF_FOREACH__
  602.                         #undef foreach
  603.                         #undef __SSCANF_FOREACH__
  604.                     #endif
  605.                 }
  606.                 stringPos = end;
  607.             }
  608.             case 's', 'z':
  609.             {
  610.                 new
  611.                     i = 0,
  612.                     ch;
  613.                 if (format[formatPos])
  614.                 {
  615.                     while ((ch = string[stringPos++]) && ch != delim)
  616.                     {
  617.                         setarg(paramPos, i++, ch);
  618.                     }
  619.                     if (!i)
  620.                     {
  621.                         return -1;
  622.                     }
  623.                 }
  624.                 else
  625.                 {
  626.                     while ((ch = string[stringPos++]))
  627.                     {
  628.                         setarg(paramPos, i++, ch);
  629.                     }
  630.                 }
  631.                 stringPos--;
  632.                 setarg(paramPos, i, '\0');
  633.             }
  634.             default:
  635.             {
  636.                 continue;
  637.             }
  638.         }
  639.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  640.         {
  641.             stringPos++;
  642.         }
  643.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  644.         {
  645.             stringPos++;
  646.         }
  647.         paramPos++;
  648.     }
  649.     do
  650.     {
  651.         if ((delim = format[formatPos++]) > ' ')
  652.         {
  653.             if (delim == '\'')
  654.             {
  655.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  656.             }
  657.             else if (delim != 'z')
  658.             {
  659.                 return delim;
  660.             }
  661.         }
  662.     }
  663.     while (delim > ' ');
  664.     return 0;
  665. }
Add Comment
Please, Sign In to add comment