Advertisement
ErikSon_

Dynamisches Clansystem by ErikSon

Aug 8th, 2014
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 14.23 KB | None | 0 0
  1. #include <a_samp>
  2. #include <ocmd>
  3. #include <dini>
  4.  
  5. /*      Settings        */
  6. #define MAX_CLANS           50              //Maximale Clans
  7. #define C_FILE          "/Clans.ini"        //Wo die Clans gespeichert werden
  8.  
  9. #define GetClanID(%0)        GetPVarInt(%0,"ClanID")
  10. #define GetClanRank(%0)      GetPVarInt(%0,"ClanRank")
  11. #define SetClanID(%0,%1)     SetPVarInt(%0,"ClanID",%1)
  12. #define SetClanRank(%0,%1)   SetPVarInt(%0,"ClanRank",%1)
  13. /*      Settings        */
  14.  
  15. #define Rot                     0xE10000FF
  16. #define HBlau                   0x00FFFFFF
  17. #define Blau                    0x2E9AFEFF
  18. #define Orange                  0xFFAB00FF
  19. #define Weiss                   0xFFFFFFFF
  20. #define Grau                    0xA0A0A0FF
  21.  
  22.  
  23. #define dClans      6050 //Dialog
  24. forward ClanShow();
  25. new PlayerName[MAX_PLAYERS][MAX_PLAYER_NAME];
  26.  
  27. #define dInt                    dini_Int
  28. #define dIntSet                 dini_IntSet
  29. #define dGet                    dini_Get
  30. #define dSet                    dini_Set
  31. #define dFloatSet               dini_FloatSet
  32. #define dFloat                  dini_Float
  33. #define dExist                  dini_Exists
  34.  
  35.  
  36. new fmex[128];
  37. #define SCMToAllF(%0,%1,%2)  format(fmex,128,%1,%2) && SendClientMessageToAll(%0, fmex)
  38. #define SCMF(%0,%1,%2)  format(fmex,128,%2) && SendClientMessage(%0,%1,fmex)
  39. #define SCMToAll(%0,%1) format(fmex,128,%1) && SendClientMessageToAll(%0,%1)
  40.  
  41. enum ECS{
  42.     ClanID,
  43.     ClanName[64],
  44.     ClanTag[8]
  45. }
  46. new Clan[MAX_CLANS][ECS];
  47.  
  48.  
  49.  
  50. public OnFilterScriptInit(){
  51.     print("\n--------------------------------------");
  52.     print(" Dynamisches Clansystem by ErikSon");
  53.     print("--------------------------------------\n");
  54.     SetTimer("ClanShow",888*60,true);
  55.     for(new i = 0; i<MAX_PLAYERS; i++){
  56.         if(!IsPlayerConnected(i))continue;
  57.         GetPlayerName(i,PlayerName[i],MAX_PLAYER_NAME);
  58.     }
  59.     return LoadClans();
  60. }
  61.  
  62. public OnFilterScriptExit()return SaveClans();
  63.  
  64. public OnPlayerConnect(playerid)return GetPlayerName(playerid,PlayerName[playerid],MAX_PLAYER_NAME);
  65.  
  66. public ClanShow(){
  67.     new _string[32];
  68.     for(new playerid = 0; playerid<MAX_PLAYERS; playerid++){
  69.         if(!IsPlayerConnected(playerid))continue;
  70.         if(GetClanID(playerid) > 0){
  71.             if(strfind(PlayerName[playerid],Clan[GetClanID(playerid)][ClanTag],true) == -1){
  72.                 format(_string,sizeof(_string),"%s[%s]",PlayerName[playerid],Clan[GetClanID(playerid)][ClanTag]);
  73.                 SetPlayerName(playerid,_string);
  74.             }
  75.         }
  76.     }
  77.     return 1;
  78. }
  79.  
  80.  
  81. stock LoadClans(){
  82.     new str[128],cd[64]; format(cd,sizeof(cd),C_FILE);
  83.     if(!dExist(cd))dini_Create(cd);
  84.     for(new i = 1; i<MAX_CLANS; i++){
  85.         format(str,128,"Clan%i_ClanID",i);
  86.         if(dInt(cd,str) <= 0)continue;
  87.         Clan[i][ClanID] = dInt(cd,str);
  88.         format(str,128,"Clan%i_ClanName",i);
  89.         format(Clan[i][ClanName],32,"%s",dGet(cd,str));
  90.         format(str,128,"Clan%i_Tag",i);
  91.         format(Clan[i][ClanTag],8,"%s",dGet(cd,str));
  92.     }
  93.     return 1;
  94. }
  95.  
  96. stock SaveClans(){
  97.     new str[128],cd[64]; format(cd,sizeof(cd),C_FILE);
  98.     if(!dExist(cd))dini_Create(cd);
  99.     for(new i = 1; i<MAX_CLANS; i++){
  100.         if(Clan[i][ClanID] <= 0)continue;
  101.         format(str,128,"Clan%i_ClanID",i);
  102.         dIntSet(cd,str,Clan[i][ClanID]);
  103.         format(str,128,"Clan%i_ClanName",i);
  104.         dSet(cd,str,Clan[i][ClanName]);
  105.         format(str,128,"Clan%i_Tag",i);
  106.         dSet(cd,str,Clan[i][ClanTag]);
  107.     }
  108.     return 1;
  109. }
  110.  
  111. ocmd:clans(playerid){
  112.     new string[512],buffer[512];
  113.     for(new i = 1; i<MAX_CLANS; i++){
  114.         if(Clan[i][ClanID] == 0)continue;
  115.         format(buffer,sizeof(buffer),"%d | %s%c",Clan[i][ClanID],Clan[i][ClanName],(i >= MAX_CLANS) ? '\0' : '\n'),strins(string,buffer,strlen(string),sizeof(string));
  116.     }
  117.     return ShowPlayerDialog(playerid,dClans,DIALOG_STYLE_MSGBOX,"Clans",string,"Okay","");
  118. }
  119.  
  120. ocmd:clanhelp(playerid){
  121.     SCMF(playerid,Orange,"===============> Clanbefehle <===============");
  122.     SCMF(playerid,Rot,"/c(lan), /cinvite, /cuninvite, /clans");
  123.     return SCMF(playerid,Orange,"===============> Clanbefehle <===============");
  124. }
  125.  
  126. ocmd@2:c,clan(playerid,params[]){
  127.     new text[128],string[140];
  128.     if(GetClanID(playerid) <1)return SCMF(playerid,Rot,"Du bist in keinem Clan!");
  129.     if(sscanf(params,"s",text))return SCMF(playerid,Rot,"Benutzung: /c(lan) [Text]");
  130.     format(string,140,"[%s] %s: %s",Clan[GetClanID(playerid)][ClanTag],PlayerName[playerid],text);
  131.     for(new i=0; i<MAX_PLAYERS; i++){
  132.         if(!IsPlayerConnected(i))continue;
  133.         if(GetClanID(i) != GetClanID(playerid))continue;
  134.         SCMF(i,HBlau,string);
  135.     }
  136.     return 1;
  137. }
  138.  
  139. ocmd@2:cinvite,ceinladen(playerid,params[]){
  140.     new pID,string[128];
  141.     if(GetClanID(playerid) <1)return SCMF(playerid,Rot,"Du bist in keinem Clan!");
  142.     if(GetClanRank(playerid) <2)return SCMF(playerid,Rot,"Du bist nicht der Leader des Clans!");
  143.     if(sscanf(params,"u",pID))return SCMF(playerid,Rot,"Benutzung: /cinvite [Spieler]");
  144.     if(!IsPlayerConnected(pID))return SCMF(playerid,Rot,"Dieser Spieler ist nicht online!");
  145.     if(GetClanID(playerid) != 0)return SCMF(playerid,Rot,"Der Spieler '%s' ist bereits / noch in einem Clan!",PlayerName[pID]);
  146.     format(string,128,"[%s] %s hat den Spieler %s in den Clan eingeladen.",Clan[GetClanID(playerid)][ClanTag],PlayerName[playerid],PlayerName[pID]);
  147.     for(new i=0; i<MAX_PLAYERS; i++){
  148.         if(!IsPlayerConnected(i))continue;
  149.         if(GetClanID(i) != GetClanID(playerid))continue;
  150.         SCMF(i,HBlau,string);
  151.     }
  152.     SetPVarInt(pID,"CEingeladen",GetClanID(playerid));
  153.     SCMF(pID,Orange,"[%s] %s von dem Clan '%s' hat dir eine Clan-Einladung geschickt.",Clan[GetClanID(playerid)][ClanTag],PlayerName[playerid],Clan[GetClanID(playerid)][ClanName]);
  154.     return SCMF(pID,Blau,"Tippe '/ceinladung annehmen | /ceinladung ablehnen' um die Einladung anzunehmen / abzulehnen.");
  155. }
  156.  
  157. ocmd:ceinladung(playerid,params[]){
  158.     new string[128],a[16];
  159.     if(GetPVarInt(playerid,"CEingeladen") <= 0)return SCMF(playerid,Rot,"Du hast keine Einladung eines Clans erhalten!");
  160.     if(sscanf(params,"s",a))return SCMF(playerid,Rot,"Benutzung: /ceinladung [annehmen / ablehnen]");
  161.     if(strcmp(a,"annehmen",false)){
  162.         format(string,128,"Spieler '%s' hat die Einladung in den Clan angenommen.",PlayerName[playerid]);
  163.         SCMF(playerid,Blau,"Du hast die Einladung in den Clan '%s' angemommen.",Clan[GetPVarInt(playerid,"CEingeladen")][ClanName]);
  164.         for(new i=0; i<MAX_PLAYERS; i++){
  165.             if(!IsPlayerConnected(i))continue;
  166.             if(GetClanID(i) != GetPVarInt(playerid,"CEingeladen"))continue;
  167.             SCMF(i,Blau,string);
  168.         }
  169.         SetClanID(playerid,GetPVarInt(playerid,"CEingeladen"));
  170.         return SetClanRank(playerid,1),SetPVarInt(playerid,"CEingeladen",0);
  171.     }
  172.     else if(strcmp(a,"ablehnen",false)){
  173.         format(string,128,"Spieler '%s' hat die Einladung in den Clan abgelehnt.",PlayerName[playerid]);
  174.         for(new i=0; i<MAX_PLAYERS; i++){
  175.             if(!IsPlayerConnected(i))continue;
  176.             if(GetClanID(i) != GetPVarInt(playerid,"CEingeladen"))continue;
  177.             SCMF(i,Blau,string);
  178.         }
  179.         return SetPVarInt(playerid,"CEingeladen",0);
  180.     }
  181.     return 1;
  182. }
  183.  
  184. ocmd@2:cuninvite,ckick(playerid,params[]){
  185.     new pID,string[128];
  186.     if(GetClanID(playerid) <1)return SCMF(playerid,Rot,"Du bist in keinem Clan!");
  187.     if(GetClanRank(playerid) <2)return SCMF(playerid,Rot,"Du bist nicht der Leader des Clans!");
  188.     if(sscanf(params,"u",pID))return SCMF(playerid,Rot,"Benutzung: /cuninvite [Spieler]");
  189.     if(!IsPlayerConnected(pID))return SCMF(playerid,Rot,"Dieser Spieler ist nicht online!");
  190.     if(GetClanID(pID) <= 0)return SCMF(playerid,Rot,"Der Spieler '%s' ist in keinem Clan!");
  191.     if(GetClanID(pID) != GetClanID(playerid))return SCMF(playerid,Rot,"Der Spieler '%s' ist nicht in deinem Clan!",PlayerName[pID]);
  192.     format(string,128,"%s hat den Spieler %s aus dem Clan ausgeschlossen.",PlayerName[playerid],PlayerName[pID]);
  193.     for(new i=0; i<MAX_PLAYERS; i++){
  194.         if(!IsPlayerConnected(i))continue;
  195.         if(GetClanID(i) != GetClanID(playerid))continue;
  196.         SCMF(i,Orange,string);
  197.     }
  198.     SetClanID(pID,0);
  199.     return SCMF(pID,Orange,"%s von dem Clan '%s' hat dich aus dem Clan ausgeschlossen.",PlayerName[playerid],Clan[GetClanID(playerid)][ClanName]);
  200. }
  201.  
  202. ocmd:cclan(playerid,p[]){
  203.     if(!IsPlayerAdmin(playerid))return 1;
  204.     new cn[32],ct[8];
  205.     if(sscanf(p,"ss",cn,ct))return SCMF(playerid,Rot,"Benutzung: /cclan [Clan-Name] [Clan-Tag |max 8 Zeichen|]");
  206.     for(new i = 1; i<MAX_CLANS; i++){
  207.         if(Clan[i][ClanID] >= 1)continue;
  208.         Clan[i][ClanID] = i;
  209.         format(Clan[i][ClanName],32,"%s",cn), format(Clan[i][ClanTag],8,"%s",ct);
  210.         SaveClans();
  211.         return SCMF(playerid,Blau,"Clan %i | '[%s]%s' erfolgreich erstellt.",i,ct,cn);
  212.     }
  213.     return 1;
  214. }
  215.  
  216. ocmd:dclan(playerid,p[]){
  217.     if(!IsPlayerAdmin(playerid))return 1;
  218.     new cid;
  219.     if(sscanf(p,"i",cid))return SCMF(playerid,Rot,"Benutzung: /dclan [Clan-ID]");
  220.     if(Clan[cid][ClanID] <= 0)return SCMF(playerid,Rot,"Dieser Clan existiert nicht!");
  221.     SCMF(playerid,Blau,"Du hast den Clan '%s' erfolgreich gelöscht.",Clan[cid][ClanName]);
  222.     return Clan[cid][ClanID] = 0, format(Clan[cid][ClanTag],5,""),format(Clan[cid][ClanName],32,"");
  223. }
  224.  
  225. ocmd:makecleader(playerid,p[]){
  226.     if(!IsPlayerAdmin(playerid))return 1;
  227.     new pID,wert;
  228.     if(sscanf(p,"ui",pID,wert))return SCMF(playerid,Rot,"Benutzung: /makecleader [Spieler] [Clan-ID ( Siehe '/clans' )]");
  229.     if(wert <= 0){
  230.         if(GetClanID(pID) > 0){
  231.             SetClanID(pID,0);
  232.             SetPlayerName(pID,PlayerName[pID]);
  233.             SCMF(playerid,Grau,"Du hast den Spieler '%s' aus seinem Clan rausgenommen.",PlayerName[pID]);
  234.             return SCMF(pID,Grau,"Admin %s hat dich aus deinem Clan rausgenommen.",PlayerName[playerid]);
  235.         }
  236.         return 1;
  237.     }
  238.     else if(Clan[wert][ClanID] <= 0)return SCMF(playerid,Rot,"Dieser Clan existiert nicht!");
  239.     else if(GetClanID(pID) > 0)SetPlayerName(pID,PlayerName[pID]);
  240.     SetClanID(pID,wert),SetClanRank(pID,2);
  241.     SCMF(playerid,Grau,"Du hast den Spieler '%s' in den Clan '%s' eingeladen.",PlayerName[pID],Clan[wert][ClanName]);
  242.     return SCMF(pID,Grau,"Admin %s hat dich in den Clan '%s' eingalden.",PlayerName[playerid],Clan[wert][ClanName]);
  243. }
  244.  
  245.  
  246. stock sscanf(string[], format[], {Float,_}:...){
  247.     #if defined isnull
  248.         if (isnull(string))
  249.     #else
  250.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  251.     #endif
  252.         {
  253.             return format[0];
  254.         }
  255.     #pragma tabsize 4
  256.     new
  257.         formatPos = 0,
  258.         stringPos = 0,
  259.         paramPos = 2,
  260.         paramCount = numargs(),
  261.         delim = ' ';
  262.     while (string[stringPos] && string[stringPos] <= ' ')
  263.     {
  264.         stringPos++;
  265.     }
  266.     while (paramPos < paramCount && string[stringPos])
  267.     {
  268.         switch (format[formatPos++])
  269.         {
  270.             case '\0':
  271.             {
  272.                 return 0;
  273.             }
  274.             case 'i', 'd':
  275.             {
  276.                 new
  277.                     neg = 1,
  278.                     num = 0,
  279.                     ch = string[stringPos];
  280.                 if (ch == '-')
  281.                 {
  282.                     neg = -1;
  283.                     ch = string[++stringPos];
  284.                 }
  285.                 do
  286.                 {
  287.                     stringPos++;
  288.                     if ('0' <= ch <= '9')
  289.                     {
  290.                         num = (num * 10) + (ch - '0');
  291.                     }
  292.                     else
  293.                     {
  294.                         return -1;
  295.                     }
  296.                 }
  297.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  298.                 setarg(paramPos, 0, num * neg);
  299.             }
  300.             case 'h', 'x':
  301.             {
  302.                 new
  303.                     num = 0,
  304.                     ch = string[stringPos];
  305.                 do
  306.                 {
  307.                     stringPos++;
  308.                     switch (ch)
  309.                     {
  310.                         case 'x', 'X':
  311.                         {
  312.                             num = 0;
  313.                             continue;
  314.                         }
  315.                         case '0' .. '9':
  316.                         {
  317.                             num = (num << 4) | (ch - '0');
  318.                         }
  319.                         case 'a' .. 'f':
  320.                         {
  321.                             num = (num << 4) | (ch - ('a' - 10));
  322.                         }
  323.                         case 'A' .. 'F':
  324.                         {
  325.                             num = (num << 4) | (ch - ('A' - 10));
  326.                         }
  327.                         default:
  328.                         {
  329.                             return -1;
  330.                         }
  331.                     }
  332.                 }
  333.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  334.                 setarg(paramPos, 0, num);
  335.             }
  336.             case 'c':
  337.             {
  338.                 setarg(paramPos, 0, string[stringPos++]);
  339.             }
  340.             case 'f':
  341.             {
  342.  
  343.                 new changestr[16], changepos = 0, strpos = stringPos;    
  344.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  345.                 {
  346.                     changestr[changepos++] = string[strpos++];
  347.                     }
  348.                 changestr[changepos] = '\0';
  349.                 setarg(paramPos,0,_:floatstr(changestr));
  350.             }
  351.             case 'p':
  352.             {
  353.                 delim = format[formatPos++];
  354.                 continue;
  355.             }
  356.             case '\'':
  357.             {
  358.                 new
  359.                     end = formatPos - 1,
  360.                     ch;
  361.                 while ((ch = format[++end]) && ch != '\'') {}
  362.                 if (!ch)
  363.                 {
  364.                     return -1;
  365.                 }
  366.                 format[end] = '\0';
  367.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  368.                 {
  369.                     if (format[end + 1])
  370.                     {
  371.                         return -1;
  372.                     }
  373.                     return 0;
  374.                 }
  375.                 format[end] = '\'';
  376.                 stringPos = ch + (end - formatPos);
  377.                 formatPos = end + 1;
  378.             }
  379.             case 'u':
  380.             {
  381.                 new
  382.                     end = stringPos - 1,
  383.                     id = 0,
  384.                     bool:num = true,
  385.                     ch;
  386.                 while ((ch = string[++end]) && ch != delim)
  387.                 {
  388.                     if (num)
  389.                     {
  390.                         if ('0' <= ch <= '9')
  391.                         {
  392.                             id = (id * 10) + (ch - '0');
  393.                         }
  394.                         else
  395.                         {
  396.                             num = false;
  397.                         }
  398.                     }
  399.                 }
  400.                 if (num && IsPlayerConnected(id))
  401.                 {
  402.                     setarg(paramPos, 0, id);
  403.                 }
  404.                 else
  405.                 {
  406.                     #if !defined foreach
  407.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  408.                         #define __SSCANF_FOREACH__
  409.                     #endif
  410.                     string[end] = '\0';
  411.                     num = false;
  412.                     new
  413.                         name[MAX_PLAYER_NAME];
  414.                     id = end - stringPos;
  415.                     foreach (Player, playerid)
  416.                     {
  417.                         GetPlayerName(playerid, name, sizeof (name));
  418.                         if (!strcmp(name, string[stringPos], true, id))
  419.                         {
  420.                             setarg(paramPos, 0, playerid);
  421.                             num = true;
  422.                             break;
  423.                         }
  424.                     }
  425.                     if (!num)
  426.                     {
  427.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  428.                     }
  429.                     string[end] = ch;
  430.                     #if defined __SSCANF_FOREACH__
  431.                         #undef foreach
  432.                         #undef __SSCANF_FOREACH__
  433.                     #endif
  434.                 }
  435.                 stringPos = end;
  436.             }
  437.             case 's', 'z':
  438.             {
  439.                 new
  440.                     i = 0,
  441.                     ch;
  442.                 if (format[formatPos])
  443.                 {
  444.                     while ((ch = string[stringPos++]) && ch != delim)
  445.                     {
  446.                         setarg(paramPos, i++, ch);
  447.                     }
  448.                     if (!i)
  449.                     {
  450.                         return -1;
  451.                     }
  452.                 }
  453.                 else
  454.                 {
  455.                     while ((ch = string[stringPos++]))
  456.                     {
  457.                         setarg(paramPos, i++, ch);
  458.                     }
  459.                 }
  460.                 stringPos--;
  461.                 setarg(paramPos, i, '\0');
  462.             }
  463.             default:
  464.             {
  465.                 continue;
  466.             }
  467.         }
  468.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  469.         {
  470.             stringPos++;
  471.         }
  472.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  473.         {
  474.             stringPos++;
  475.         }
  476.         paramPos++;
  477.     }
  478.     do
  479.     {
  480.         if ((delim = format[formatPos++]) > ' ')
  481.         {
  482.             if (delim == '\'')
  483.             {
  484.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  485.             }
  486.             else if (delim != 'z')
  487.             {
  488.                 return delim;
  489.             }
  490.         }
  491.     }
  492.     while (delim > ' ');
  493.     return 0;
  494. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement