Advertisement
N3to

Sistema de drogas v1

Oct 18th, 2014
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.37 KB | None | 0 0
  1. // Este FS foi feito por Neto(iTzDemon no forum sa-mp).
  2. // A sua utilização deverá conter sempre os créditos
  3.  
  4. #include <a_samp>
  5. #include <zcmd>
  6. #include <sscanf2>
  7. #include <dof2>
  8.  
  9. #define MAX_DROGAS 250
  10. #define TEMPODROGAS 7200
  11. #define PASTA "drogas/%d.ini"
  12. enum Info {
  13.     Dono[24],
  14.     Tempo,
  15.     Tipo,
  16.     Float:X,
  17.     Float:Y,
  18.     Float:Z,
  19.     objecto
  20. };
  21. new arquivo[MAX_DROGAS][Info];
  22.  
  23. enum pInfo {
  24.     Erva,
  25.     Coca,
  26.     Hero,
  27. };
  28. new PlayerInfo[MAX_PLAYERS][pInfo];
  29.  
  30.  
  31. public OnFilterScriptInit()
  32. {
  33.     new string[64];
  34.     print("FS por Neto");
  35.     format(string,64,"Arquivos carregados: %d",getarquivos());
  36.     print(string);
  37.     SetTimer("Update",1000,true);
  38.     return 1;
  39. }
  40.  
  41. public OnFilterScriptExit()
  42. {
  43.     for(new a = 0; a < MAX_DROGAS; a++)
  44.     {
  45.         if(DOF2_FileExists(Arquivo(a)))
  46.         {
  47.             DOF2_SetInt(Arquivo(a),"Tempo",arquivo[a][Tempo]);
  48.             DOF2_SaveFile();
  49.         }
  50.     }
  51.     DOF2_Exit();
  52.     return 1;
  53. }
  54.  
  55. stock getarquivos()
  56. {
  57.     new count = 0;
  58.     for(new a = 0; a < MAX_DROGAS; a++)
  59.     {
  60.         if(DOF2_FileExists(Arquivo(a)))
  61.         {
  62.             count++;
  63.             format(arquivo[a][Dono],MAX_PLAYER_NAME,"%s",DOF2_GetString(Arquivo(a),"Dono"));
  64.             arquivo[a][Tempo] = DOF2_GetInt(Arquivo(a),"Tempo");
  65.             arquivo[a][Tipo] = DOF2_GetInt(Arquivo(a),"Tipo");
  66.             arquivo[a][X] = DOF2_GetFloat(Arquivo(a),"X");
  67.             arquivo[a][Y] = DOF2_GetFloat(Arquivo(a),"Y");
  68.             arquivo[a][Z] = DOF2_GetFloat(Arquivo(a),"Z");
  69.             if(arquivo[a][Tempo] == 0) arquivo[a][objecto] = CreateObject(1279, arquivo[a][X], arquivo[a][Y], arquivo[a][Z]-1,0,0,0);
  70.             else arquivo[a][objecto] = CreateObject(823, arquivo[a][X], arquivo[a][Y], arquivo[a][Z],0,0,0);
  71.         }
  72.     }
  73.     return count;
  74. }
  75.  
  76. stock Arquivo(id)
  77. {
  78.     new sm[32];
  79.     format(sm,sizeof(sm),PASTA,id);
  80.     return sm;
  81. }
  82.  
  83. stock GetPlayerNameEx(playerid)
  84. {
  85.     new name[MAX_PLAYER_NAME];
  86.     GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  87.     return name;
  88. }
  89.  
  90. forward Update();
  91. public Update()
  92. {
  93.     for(new a = 0; a < MAX_DROGAS; a++)
  94.     {
  95.         if(DOF2_FileExists(Arquivo(a)))
  96.         {
  97.             if(arquivo[a][Tempo] == 1)
  98.             {
  99.                 arquivo[a][Tempo] = 0;
  100.                 DOF2_SetInt(Arquivo(a),"Tempo",arquivo[a][Tempo]);
  101.                 DestroyObject(arquivo[a][objecto]);
  102.                 arquivo[a][objecto] = CreateObject(1279, arquivo[a][X], arquivo[a][Y], arquivo[a][Z]-1,0,0,0);
  103.             }
  104.             else if(arquivo[a][Tempo] > 1) {
  105.                 arquivo[a][Tempo]--;
  106.                 DOF2_SetInt(Arquivo(a),"Tempo",arquivo[a][Tempo]);
  107.             }
  108.         }
  109.     }
  110.     return 1;
  111. }
  112.  
  113. forward CriarPlanta(playerid,tipo);
  114. public CriarPlanta(playerid,tipo)
  115. {
  116.     for(new a = 0; a < MAX_DROGAS; a++)
  117.     {
  118.         if(!DOF2_FileExists(Arquivo(a)))
  119.         {
  120.             DOF2_CreateFile(Arquivo(a));
  121.             format(arquivo[a][Dono],MAX_PLAYER_NAME,"%s",GetPlayerNameEx(playerid));
  122.             arquivo[a][Tempo] = TEMPODROGAS;
  123.             arquivo[a][Tipo] = tipo;
  124.             GetPlayerPos(playerid,arquivo[a][X],arquivo[a][Y],arquivo[a][Z]);
  125.             DOF2_SetString(Arquivo(a),"Dono",arquivo[a][Dono]);
  126.             DOF2_SetInt(Arquivo(a),"Tempo",arquivo[a][Tempo]);
  127.             DOF2_SetInt(Arquivo(a),"Tipo",arquivo[a][Tipo]);
  128.             DOF2_SetFloat(Arquivo(a),"X",arquivo[a][X]);
  129.             DOF2_SetFloat(Arquivo(a),"Y",arquivo[a][Y]);
  130.             DOF2_SetFloat(Arquivo(a),"Z",arquivo[a][Z]);
  131.             arquivo[a][objecto] = CreateObject(823, arquivo[a][X], arquivo[a][Y], arquivo[a][Z],0,0,0);
  132.             DOF2_SaveFile();
  133.             new nomedroga[16],string[128];
  134.             switch(tipo)
  135.             {
  136.                 case 0: nomedroga = "Erva";
  137.                 case 1: nomedroga = "Cocaina";
  138.                 case 2: nomedroga = "Heroina";
  139.             }
  140.             format(string,128,"[Drogas:] Parabens, criaste uma plantação de %s",nomedroga);
  141.             SendClientMessage(playerid,-1,string);
  142.             break;
  143.         }
  144.     }
  145.     return 1;
  146. }
  147.  
  148. forward Colher(playerid);
  149. public Colher(playerid)
  150. {
  151.     for(new a = 0; a < MAX_DROGAS; a++)
  152.     {
  153.         if(DOF2_FileExists(Arquivo(a)))
  154.         {
  155.             if(IsPlayerInRangeOfPoint(playerid, 2.0, arquivo[a][X], arquivo[a][Y], arquivo[a][Z]))
  156.             {
  157.                 if(arquivo[a][Tempo] == 0)
  158.                 {
  159.                     if(!strcmp(GetPlayerNameEx(playerid),arquivo[a][Dono],false))
  160.                     {
  161.                         new nomedroga[16],string[128],g;
  162.                         switch(arquivo[a][Tipo])
  163.                         {
  164.                             case 0: g = 200,PlayerInfo[playerid][Erva]+=g,nomedroga = "Erva";
  165.                             case 1: g = 100,PlayerInfo[playerid][Coca]+=g,nomedroga = "Cocaina";
  166.                             case 2: g = 50,PlayerInfo[playerid][Hero]+=g,nomedroga = "Heroina";
  167.                         }
  168.                         format(string,128,"[Drogas:] Parabens, colheste %d gramas de %s",g,nomedroga);
  169.                         SendClientMessage(playerid,-1,string);
  170.                         DOF2_RemoveFile(Arquivo(a));
  171.                         DestroyObject(arquivo[a][objecto]);
  172.                         format(arquivo[a][Dono],24,"");
  173.                         arquivo[a][Tempo] = 0;
  174.                         arquivo[a][Tipo] = 0;
  175.                         arquivo[a][X] = 0;
  176.                         arquivo[a][Y] = 0;
  177.                         arquivo[a][Z] = 0;
  178.                     }
  179.                     else SendClientMessage(playerid,-1,"[Drogas:] Essas drogas não são tuas");
  180.                 }
  181.                 else SendClientMessage(playerid,-1,"[Drogas:] Ainda não podes colher");
  182.             }
  183.         }
  184.     }
  185. }
  186.  
  187. CMD:plantar(playerid,params[])
  188. {
  189.     new count = 0;
  190.     for(new a = 0; a < MAX_DROGAS; a++) if(DOF2_FileExists(Arquivo(a))) count++;
  191.     if(count > MAX_DROGAS) return SendClientMessage(playerid,-1,"[Drogas:] As plantações estao cheias");
  192.     new tipo;
  193.     if(sscanf(params,"d",tipo)) return SendClientMessage(playerid,-1,"[Drogas:] Escolhe entre 0-Erva 1-Cocaina 2-Heroina");
  194.     CriarPlanta(playerid,tipo);
  195.     return 1;
  196. }
  197.  
  198. CMD:colher(playerid)
  199. {
  200.     Colher(playerid);
  201.     return 1;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement