Advertisement
Juuh

xDrogasv2

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