Advertisement
ErikSon_

Drogensystem by ErikSon

Aug 5th, 2014
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.72 KB | None | 0 0
  1. #include <a_samp>
  2. #include <ocmd>
  3.  
  4. /*      Settings        */
  5. //  Bitte anpassen!
  6. #define MAX_PLANTS      50          //Maximale Plantagen insgesamt
  7. #define ReifZeit        30          //Zeit in Minute, die die Plantagen reifen müssen
  8. #define Drugs           1000        //Drogen in Gramm, die der Spieler bekommt, wenn er Drogen erntet ( in PVars! "Drogen" )
  9. #define SamenKosten     500         //Preis pro 10 Samen (PVars! "Samen")
  10. #define D_FILE          "/Plantagen.ini" //Datei, wo die Drogen gespeichert werden sollen.
  11.  
  12. stock bool:IsCop(playerid){
  13.     switch(GetPVarInt(playerid,"Fraktion")){
  14.         case 1,2,3:return true; //Hier die Copfraktionen eintragen
  15.         default: return false;
  16.     }
  17.     return false;
  18. }
  19.  
  20. /*      Settings        */
  21.  
  22. //Farben
  23. #define Schwarz 0x000000FF
  24. #define Rot 0xE10000FF
  25. #define Gelb 0xFFE600FF
  26. #define HBlau 0x00FFFFFF
  27. #define DBlau 0x0000FFFF
  28. #define Blau 0x2E9AFEFF
  29. #define HGruen 0x00FF00FF
  30. #define HHGruen 0xCDFF00FF
  31. #define Orange 0xFFAB00FF
  32. #define Weiss 0xFFFFFFFF
  33. #define Grau 0xDCDCDCFF
  34. #define Lila 0x8C00FFFF
  35.  
  36. new fmex[128];
  37. #define D_SCM(%0,%1,%2)  format(fmex,128,%2) && SendClientMessage(%0,%1,fmex)
  38.  
  39.  
  40. forward ZeitTimer_(plant);
  41.  
  42. enum EPlantage
  43. {
  44.     d_besitzer[MAX_PLAYER_NAME],
  45.     d_zeit,
  46.     Float:d_pos[3],
  47.     d_obj,
  48.     d_timer,
  49.     Text3D:d_label,
  50.     bool:d_erstellt
  51. }
  52. new Plantage[MAX_PLANTS][EPlantage];
  53.  
  54.  
  55. public OnFilterScriptInit(){
  56.     print("\n--------------------------------------");
  57.     print(" Drogensystem by ErikSon");
  58.     print("--------------------------------------\n");
  59.     if(!fexist(D_FILE))SavePlants();
  60.     return LoadPlants();
  61. }
  62. public OnFilterScriptExit()return SavePlants(),DestroyPlants();
  63.  
  64.  
  65. //Befehle
  66. ocmd:buysamen(playerid){
  67.     if(GetPlayerMoney(playerid) < SamenKosten)return D_SCM(playerid,Rot,"Du hast nicht genug Geld bei! Benötigt: %i$",SamenKosten);
  68.     D_SCM(playerid,Blau,"*Du hast dir 10 Samen für %i$ gekauft.*",SamenKosten);
  69.     SetPVarInt(playerid,"Samen",GetPVarInt(playerid,"Samen") +10);
  70.     return GivePlayerMoney(playerid,-SamenKosten);
  71. }
  72.  
  73. ocmd:plantdrugs(playerid){
  74.     new Float:x,Float:y,Float:z,string[64],i = 0;
  75.     GetPlayerPos(playerid,x,y,z);
  76.     if(GetPVarInt(playerid,"Samen") < 10)return D_SCM(playerid,Rot,"*Du besitzt nicht genug Samen! Benötigt: 10 | Besitz: %i*",GetPVarInt(playerid,"Samen"));
  77.     for(; i<MAX_PLANTS; i++){
  78.         if(Plantage[i][d_erstellt])continue;
  79.         Plantage[i][d_obj] = CreateObject(822,x,y,z,0,0,0,100);
  80.         format(Plantage[i][d_besitzer],MAX_PLAYER_NAME,"%s",SpielerName(playerid));
  81.         Plantage[i][d_pos][0] = x,
  82.         Plantage[i][d_pos][1] = y,
  83.         Plantage[i][d_pos][2] = z,
  84.         Plantage[i][d_zeit] = 0,
  85.         Plantage[i][d_erstellt] = true;
  86.         format(string,64,"Besitzer: '%s'\nZeit: %i / %i Minuten",Plantage[i][d_besitzer],Plantage[i][d_zeit],ReifZeit);
  87.         Plantage[i][d_label] = Create3DTextLabel(string,Weiss,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2],50,0,1);
  88.         Plantage[i][d_timer] = SetTimerEx("ZeitTimer_",1000*60,true,"i",i);
  89.         SetPVarInt(playerid,"Samen",GetPVarInt(playerid,"Samen") -10);
  90.         SendClientMessage(playerid,Blau,"*Du hast dir erfolgreich eine Plantage angebaut.*");
  91.         return D_SCM(playerid,Blau,"*Du musst nun %i Minuten warten, bis die Drogen reif sind.*",ReifZeit);
  92.     }
  93.     return 1;
  94. }
  95.  
  96. ocmd:takepdrugs(playerid){
  97.     new i = 0;
  98.     for(; i<MAX_PLANTS; i++){
  99.         if(Plantage[i][d_erstellt] != true)continue;
  100.         if(!IsPlayerInRangeOfPoint(playerid,5,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]))continue;
  101.         if(strcmp(Plantage[i][d_besitzer],SpielerName(playerid)))continue;
  102.         else if(Plantage[i][d_zeit] < ReifZeit)return SendClientMessage(playerid,Rot,"*Die Plantage ist noch nicht ausgereift!*");
  103.         DestroyObject(Plantage[i][d_obj]),Delete3DTextLabel(Plantage[i][d_label]);
  104.         Plantage[i][d_pos][0] = 0,Plantage[i][d_pos][1] = 0,Plantage[i][d_pos][2] = 0,Plantage[i][d_erstellt] = false;
  105.         D_SCM(playerid,Blau,"*Du hast die Drogen der Plantage genommen und erhälst %i Gramm Drogen*",Drugs);
  106.         return SetPVarInt(playerid,"Drogen",GetPVarInt(playerid,"Drogen") +Drugs);
  107.     }
  108.     return 1;
  109. }
  110.  
  111. ocmd:removeplant(playerid){
  112.     new i = 0;
  113.     for(; i<MAX_PLANTS; i++){
  114.         if(Plantage[i][d_erstellt] != true)continue;
  115.         if(!IsPlayerInRangeOfPoint(playerid,5,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]))continue;
  116.         if(strcmp(Plantage[i][d_besitzer],SpielerName(playerid)) && !IsCop(playerid))continue;
  117.         Plantage[i][d_pos][0] = 0,Plantage[i][d_pos][1] = 0,Plantage[i][d_pos][2] = 0,Plantage[i][d_erstellt] = false;
  118.         DestroyObject(Plantage[i][d_obj]), Delete3DTextLabel(Plantage[i][d_label]);
  119.         return SendClientMessage(playerid,Blau,"*Du hast die Plantage erfolgreich entfernt.*");
  120.     }
  121.     return 1;
  122. }
  123.  
  124. ocmd:planthelp(playerid)return SendClientMessage(playerid,-1,"'/buysamen' | '/plantdrugs' | '/takepdrugs' | '/removeplant'");
  125.  
  126. public ZeitTimer_(plant){
  127.     if(Plantage[plant][d_zeit] ++ >= ReifZeit){
  128.         Plantage[plant][d_zeit] ++;
  129.         SendClientMessage(Plantage[plant][d_besitzer],Blau,"*Deine Plantage ist nun reif. Du kannst die Drogen mit >/takepdrugs< an dich nehmen.*");
  130.         return KillTimer(Plantage[plant][d_timer]);
  131.     }
  132.     Plantage[plant][d_zeit] ++;
  133.     new string[64]; format(string,sizeof(string),"Besitzer: '%s'\nZeit: %i / %i Minuten",Plantage[plant][d_besitzer],Plantage[plant][d_zeit]);
  134.     return Update3DTextLabelText(Plantage[plant][d_label],Weiss,string);
  135. }
  136.  
  137. stock SpielerName(playerid){
  138.     new GetName[MAX_PLAYER_NAME];
  139.     GetPlayerName(playerid,GetName,sizeof(GetName));
  140.     return GetName;
  141. }
  142.  
  143. stock LoadPlants(){
  144.     if(!fexist(D_FILE)){
  145.         new File:tfFile=fopen(D_FILE,io_write);
  146.         fclose(tfFile);
  147.     }
  148.     new File:fFile=fopen(D_FILE,io_read),Content[128],i,string[64];
  149.     while(fread(fFile,Content))
  150.     {
  151.         StripNewLine(Content);
  152.         d_sscanf(Content,"sifff",Plantage[i][d_besitzer],Plantage[i][d_zeit],Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]);
  153.        
  154.         Plantage[i][d_obj] = CreateObject(822,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2],0,0,0,100);
  155.         Plantage[i][d_erstellt] = true;
  156.         format(string,64,"Besitzer: '%s'\nZeit: %i / %i Minuten",Plantage[i][d_besitzer],Plantage[i][d_zeit],ReifZeit);
  157.         Plantage[i][d_label] = Create3DTextLabel(string,Weiss,Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2],50,0,1);
  158.         Plantage[i][d_timer] = SetTimerEx("ZeitTimer_",1000*60,true,"i",i);
  159.        
  160.         i++;
  161.     }
  162.     fclose(fFile);
  163.     return printf("  '%d' Plantage(n) wurde(n) geladen & erstellt.",i++);
  164. }
  165. stock SavePlants(){
  166.     if(fexist(D_FILE))fremove(D_FILE);
  167.     new File:fFile=fopen(D_FILE,io_append),Content[128];
  168.     new i;while(i<MAX_PLANTS)
  169.     {
  170.         if(Plantage[i][d_erstellt])
  171.         {
  172.             format(Content,sizeof(Content),"%s %i %f %f %f\r\n",Plantage[i][d_besitzer],Plantage[i][d_zeit],Plantage[i][d_pos][0],Plantage[i][d_pos][1],Plantage[i][d_pos][2]);
  173.             fwrite(fFile,Content);
  174.         }i++;
  175.     }return fclose(fFile);
  176. }
  177.  
  178. stock DestroyPlants(){
  179.     for(new i = 0; i<MAX_PLANTS; i++){
  180.         DestroyObject(Plantage[i][d_obj]);
  181.         Delete3DTextLabel(Plantage[i][d_label]);
  182.     }
  183.     return 1;
  184. }
  185.  
  186. stock StripNewLine(string[]){
  187.     new len=strlen(string);
  188.     if(string[0]==0)return;if((string[len-1]=='\n')||(string[len-1]=='\r')){
  189.         string[len-1]=0; if(string[0]==0) return; if((string[len-2]=='\n')||(string[len-2]=='\r'))string[len-2]=0;
  190.     }
  191. }
  192.  
  193. stock d_sscanf(string[], format[], {Float,_}:...)
  194. {
  195.     #if defined isnull
  196.         if (isnull(string))
  197.     #else
  198.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  199.     #endif
  200.         {
  201.             return format[0];
  202.         }
  203.     #pragma tabsize 4
  204.     new
  205.         formatPos = 0,
  206.         stringPos = 0,
  207.         paramPos = 2,
  208.         paramCount = numargs(),
  209.         delim = ' ';
  210.     while (string[stringPos] && string[stringPos] <= ' ')
  211.     {
  212.         stringPos++;
  213.     }
  214.     while (paramPos < paramCount && string[stringPos])
  215.     {
  216.         switch (format[formatPos++])
  217.         {
  218.             case '\0':
  219.             {
  220.                 return 0;
  221.             }
  222.             case 'i', 'd':
  223.             {
  224.                 new
  225.                     neg = 1,
  226.                     num = 0,
  227.                     ch = string[stringPos];
  228.                 if (ch == '-')
  229.                 {
  230.                     neg = -1;
  231.                     ch = string[++stringPos];
  232.                 }
  233.                 do
  234.                 {
  235.                     stringPos++;
  236.                     if ('0' <= ch <= '9')
  237.                     {
  238.                         num = (num * 10) + (ch - '0');
  239.                     }
  240.                     else
  241.                     {
  242.                         return -1;
  243.                     }
  244.                 }
  245.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  246.                 setarg(paramPos, 0, num * neg);
  247.             }
  248.             case 'h', 'x':
  249.             {
  250.                 new
  251.                     num = 0,
  252.                     ch = string[stringPos];
  253.                 do
  254.                 {
  255.                     stringPos++;
  256.                     switch (ch)
  257.                     {
  258.                         case 'x', 'X':
  259.                         {
  260.                             num = 0;
  261.                             continue;
  262.                         }
  263.                         case '0' .. '9':
  264.                         {
  265.                             num = (num << 4) | (ch - '0');
  266.                         }
  267.                         case 'a' .. 'f':
  268.                         {
  269.                             num = (num << 4) | (ch - ('a' - 10));
  270.                         }
  271.                         case 'A' .. 'F':
  272.                         {
  273.                             num = (num << 4) | (ch - ('A' - 10));
  274.                         }
  275.                         default:
  276.                         {
  277.                             return -1;
  278.                         }
  279.                     }
  280.                 }
  281.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  282.                 setarg(paramPos, 0, num);
  283.             }
  284.             case 'c':
  285.             {
  286.                 setarg(paramPos, 0, string[stringPos++]);
  287.             }
  288.             case 'f':
  289.             {
  290.  
  291.                 new changestr[16], changepos = 0, strpos = stringPos;    
  292.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  293.                 {
  294.                     changestr[changepos++] = string[strpos++];
  295.                     }
  296.                 changestr[changepos] = '\0';
  297.                 setarg(paramPos,0,_:floatstr(changestr));
  298.             }
  299.             case 'p':
  300.             {
  301.                 delim = format[formatPos++];
  302.                 continue;
  303.             }
  304.             case '\'':
  305.             {
  306.                 new
  307.                     end = formatPos - 1,
  308.                     ch;
  309.                 while ((ch = format[++end]) && ch != '\'') {}
  310.                 if (!ch)
  311.                 {
  312.                     return -1;
  313.                 }
  314.                 format[end] = '\0';
  315.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  316.                 {
  317.                     if (format[end + 1])
  318.                     {
  319.                         return -1;
  320.                     }
  321.                     return 0;
  322.                 }
  323.                 format[end] = '\'';
  324.                 stringPos = ch + (end - formatPos);
  325.                 formatPos = end + 1;
  326.             }
  327.             case 'u':
  328.             {
  329.                 new
  330.                     end = stringPos - 1,
  331.                     id = 0,
  332.                     bool:num = true,
  333.                     ch;
  334.                 while ((ch = string[++end]) && ch != delim)
  335.                 {
  336.                     if (num)
  337.                     {
  338.                         if ('0' <= ch <= '9')
  339.                         {
  340.                             id = (id * 10) + (ch - '0');
  341.                         }
  342.                         else
  343.                         {
  344.                             num = false;
  345.                         }
  346.                     }
  347.                 }
  348.                 if (num && IsPlayerConnected(id))
  349.                 {
  350.                     setarg(paramPos, 0, id);
  351.                 }
  352.                 else
  353.                 {
  354.                     #if !defined foreach
  355.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  356.                         #define __SSCANF_FOREACH__
  357.                     #endif
  358.                     string[end] = '\0';
  359.                     num = false;
  360.                     new
  361.                         name[MAX_PLAYER_NAME];
  362.                     id = end - stringPos;
  363.                     foreach (Player, playerid)
  364.                     {
  365.                         GetPlayerName(playerid, name, sizeof (name));
  366.                         if (!strcmp(name, string[stringPos], true, id))
  367.                         {
  368.                             setarg(paramPos, 0, playerid);
  369.                             num = true;
  370.                             break;
  371.                         }
  372.                     }
  373.                     if (!num)
  374.                     {
  375.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  376.                     }
  377.                     string[end] = ch;
  378.                     #if defined __SSCANF_FOREACH__
  379.                         #undef foreach
  380.                         #undef __SSCANF_FOREACH__
  381.                     #endif
  382.                 }
  383.                 stringPos = end;
  384.             }
  385.             case 's', 'z':
  386.             {
  387.                 new
  388.                     i = 0,
  389.                     ch;
  390.                 if (format[formatPos])
  391.                 {
  392.                     while ((ch = string[stringPos++]) && ch != delim)
  393.                     {
  394.                         setarg(paramPos, i++, ch);
  395.                     }
  396.                     if (!i)
  397.                     {
  398.                         return -1;
  399.                     }
  400.                 }
  401.                 else
  402.                 {
  403.                     while ((ch = string[stringPos++]))
  404.                     {
  405.                         setarg(paramPos, i++, ch);
  406.                     }
  407.                 }
  408.                 stringPos--;
  409.                 setarg(paramPos, i, '\0');
  410.             }
  411.             default:
  412.             {
  413.                 continue;
  414.             }
  415.         }
  416.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  417.         {
  418.             stringPos++;
  419.         }
  420.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  421.         {
  422.             stringPos++;
  423.         }
  424.         paramPos++;
  425.     }
  426.     do
  427.     {
  428.         if ((delim = format[formatPos++]) > ' ')
  429.         {
  430.             if (delim == '\'')
  431.             {
  432.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  433.             }
  434.             else if (delim != 'z')
  435.             {
  436.                 return delim;
  437.             }
  438.         }
  439.     }
  440.     while (delim > ' ');
  441.     return 0;
  442. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement