Advertisement
Guest User

Gangs

a guest
May 14th, 2010
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.45 KB | None | 0 0
  1. #include <a_samp>
  2.  
  3. // Translate in English by DauerDicht
  4. // Translate bugs removed by Oxside
  5. // www.SAW-RL.com
  6. #define FILTERSCRIPT
  7.  
  8. #if defined FILTERSCRIPT
  9. forward PlayerLeaveGang(playerid);
  10.     #define COLOR_ORANGERED 0xE9370DFC
  11.     #define COLOR_GOLD 0xDEAD4370
  12.     #define COLOR_MEDIUMAQUA 0x83BFBFFF
  13.     #define COLOR_BLUE 0x0000FFAA
  14.     #define COLOR_GREY 0xAFAFAFAA
  15.     #define COLOR_GREEN 0x33AA33AA
  16.     #define COLOR_YELLOW 0xFFFF00AA
  17.     #define COLOR_WHITE 0xFFFFFFAA
  18.     #define COLOR_PURPLE 0x9900FFAA
  19.     #define COLOR_BROWN 0x993300AA
  20.     #define COLOR_ORANGE 0xFF9933AA
  21.     #define COLOR_CYAN 0x99FFFFAA
  22.     #define COLOR_TAN 0xFFFFCCAA
  23.     #define COLOR_PINK 0xFF66FFAA
  24.     #define COLOR_KHAKI 0x999900AA
  25.     #define COLOR_LIME 0x99FF00AA
  26.     #define COLOR_BLACK 0x000000AA
  27.     #define COLOR_TURQ 0x00A3C0AA
  28.     #define COLOR_LIGHTBLUE 0x00BFFFAA
  29.     #define COLOR_GREENISHGOLD 0xCCFFDD56
  30.     #define COLOR_LIGHTBLUEGREEN 0x0FFDD349
  31.     #define COLOR_LIGHTCYAN 0xAAFFCC33
  32.     #define COLOR_LEMON 0xDDDD2357
  33.     #define COLOR_LIGHTGREEN 0x7CFC00AA
  34.     #define COLOR_WHITEYELLOW 0xFFE87DAA
  35.     #define COLOR_BLUEAQUA 0x7E60FFAA
  36.     #define COLOR_GREENYELLOWWHITE 0xCBFF45AA
  37.     #define COLOR_DARKBLUE 0x15005EAA
  38.     #define COLOR_RED 0xAA3333AA
  39.     #define COLOR_LIGHTRED 0xFF0000AA
  40. #define NUMVALUES 4
  41.  
  42. new playerColors[100] = {
  43. 0xFF8C13FF,0xC715FFFF,0x20B2AAFF,0xDC143CFF,0x6495EDFF,0xf0e68cFF,0x778899FF,0xFF1493FF,0xF4A460FF,0xEE82EEFF,0xFFD720FF,
  44. 0x8b4513FF,0x4949A0FF,0x148b8bFF,0x14ff7fFF,0x556b2fFF,0x0FD9FAFF,0x10DC29FF,0x534081FF,0x0495CDFF,0xEF6CE8FF,0xBD34DAFF,
  45. 0x247C1BFF,0x0C8E5DFF,0x635B03FF,0xCB7ED3FF,0x65ADEBFF,0x5C1ACCFF,0xF2F853FF,0x11F891FF,0x7B39AAFF,0x53EB10FF,0x54137DFF,
  46. 0x275222FF,0xF09F5BFF,0x3D0A4FFF,0x22F767FF,0xD63034FF,0x9A6980FF,0xDFB935FF,0x3793FAFF,0x90239DFF,0xE9AB2FFF,0xAF2FF3FF,
  47. 0x057F94FF,0xB98519FF,0x388EEAFF,0x028151FF,0xA55043FF,0x0DE018FF,0x93AB1CFF,0x95BAF0FF,0x369976FF,0x18F71FFF,0x4B8987FF,
  48. 0x491B9EFF,0x829DC7FF,0xBCE635FF,0xCEA6DFFF,0x20D4ADFF,0x2D74FDFF,0x3C1C0DFF,0x12D6D4FF,0x48C000FF,0x2A51E2FF,0xE3AC12FF,
  49. 0xFC42A8FF,0x2FC827FF,0x1A30BFFF,0xB740C2FF,0x42ACF5FF,0x2FD9DEFF,0xFAFB71FF,0x05D1CDFF,0xC471BDFF,0x94436EFF,0xC1F7ECFF,
  50. 0xCE79EEFF,0xBD1EF2FF,0x93B7E4FF,0x3214AAFF,0x184D3BFF,0xAE4B99FF,0x7E49D7FF,0x4C436EFF,0xFA24CCFF,0xCE76BEFF,0xA04E0AFF,
  51. 0x9F945CFF,0xDCDE3DFF,0x10C9C5FF,0x70524DFF,0x0BE472FF,0x8A2CD7FF,0x6152C2FF,0xCF72A9FF,0xE59338FF,0xEEDC2DFF,0xD8C762FF,
  52. 0x3FE65CFF
  53. };
  54.  
  55. #define MAX_GANGS           32
  56. #define MAX_GANG_MEMBERS    6
  57. #define MAX_GANG_NAME       16
  58. new gangMembers[MAX_GANGS][MAX_GANG_MEMBERS];
  59. new gangNames[MAX_GANGS][MAX_GANG_NAME];
  60. new gangInfo[MAX_GANGS][3]; //0-created,1-members,2-color
  61. new gangBank[MAX_GANGS];
  62. new playerGang[MAX_PLAYERS];
  63. new gangInvite[MAX_PLAYERS];
  64.  
  65.  
  66.  
  67. public OnFilterScriptInit()
  68. {
  69.     print("****************************************");
  70.     print(" GoldenEye  - GangScript                ");
  71.     print("****************************************");
  72.     return 1;
  73. }
  74.  
  75. public OnFilterScriptExit()
  76. {
  77.     return 1;
  78. }
  79.  
  80. #else
  81.  
  82. main()
  83. {
  84.     print("****************************************");
  85.     print(" GoldenEye  - GangScript                ");
  86.     print("****************************************");
  87. }
  88.  
  89. #endif
  90.  
  91. public OnPlayerText(playerid, text[])
  92. {
  93.     if(text[0] == '!') {
  94.         if(playerGang[playerid] > 0) {
  95.             new gangChat[256];
  96.             new senderName[MAX_PLAYER_NAME];
  97.             new string[256];
  98.  
  99. //          for(new i = 1; i < strlen(text)+1; i++)
  100. //              gangChat[i]=text[i];
  101.  
  102.             strmid(gangChat,text,1,strlen(text));
  103.  
  104.             GetPlayerName(playerid, senderName, sizeof(senderName));
  105.             format(string, sizeof(string),"%s: %s", senderName, gangChat);
  106.  
  107.             for(new i = 0; i < gangInfo[playerGang[playerid]][1]; i++) {
  108.                 SendClientMessage(gangMembers[playerGang[playerid]][i], COLOR_LIGHTBLUE, string);
  109.             }
  110.         }
  111.  
  112.         return 0;
  113.     }
  114.     return 1;
  115. }
  116.  
  117. public OnPlayerConnect(playerid)
  118. {
  119.     playerGang[playerid]=0;
  120.     gangInvite[playerid]=0;
  121.     return 1;
  122. }
  123.  
  124. public OnPlayerDisconnect(playerid, reason)
  125. {
  126.     PlayerLeaveGang(playerid);
  127.     return 1;
  128. }
  129.  
  130. public OnPlayerCommandText(playerid, cmdtext[])
  131. {
  132.     new string[256];
  133.     new sendername[MAX_PLAYER_NAME];
  134.     new giveplayer[MAX_PLAYER_NAME];
  135.     new cmd[256];
  136.     new giveplayerid,idx;
  137.  
  138.     cmd = strtok(cmdtext, idx);
  139.  
  140.     if(strcmp(cmd, "/ganghelp", true) == 0) {
  141.       SendClientMessage(playerid, COLOR_YELLOW,     "/gang create [Name]");
  142.       SendClientMessage(playerid, COLOR_YELLOW,     "/gang invite [PlayerID]");
  143.       SendClientMessage(playerid, COLOR_YELLOW,     "/gang join");
  144.       SendClientMessage(playerid, COLOR_YELLOW,     "/gang leave");
  145.       SendClientMessage(playerid, COLOR_YELLOW,     "/ganginfo [GangID]");
  146.       SendClientMessage(playerid, COLOR_YELLOW,     "! [Text] Gangchat with your Gang");
  147.       return 1;
  148.     }
  149.  
  150.  
  151.     //------------------- /gang
  152.  
  153.     if(strcmp(cmd, "/gang", true) == 0) {
  154.         new tmp[256];
  155.         new gangcmd, gangnum;
  156.         tmp = strtok(cmdtext, idx);
  157.  
  158.         if(!strlen(tmp)) {
  159.             SendClientMessage(playerid, 0x83BFBFFF, "Type /ganghelp for gangcommands.");
  160.             return 1;
  161.         }
  162.         giveplayerid = strval(tmp);
  163.  
  164.         if(strcmp(tmp, "create", true)==0)
  165.             gangcmd = 1;
  166.         else if(strcmp(tmp, "invite", true)==0)
  167.             gangcmd = 2;
  168.         else if(strcmp(tmp, "join", true)==0)
  169.             gangcmd = 3;
  170.         else if(strcmp(tmp, "leave", true)==0)
  171.             gangcmd = 4;
  172.  
  173.         tmp = strtok(cmdtext, idx);
  174.         if(gangcmd < 3 && !strlen(tmp)) {
  175.             if(gangcmd==0)
  176.                 SendClientMessage(playerid, 0x83BFBFFF, "Type /ganghelp for gangcommands.");
  177.             else if(gangcmd==1)
  178.                 SendClientMessage(playerid, 0x83BFBFFF, "Type: /gang create [Name]");
  179.             else if(gangcmd==2)
  180.                 SendClientMessage(playerid, 0x83BFBFFF, "Type: /gang invite [PlayerID]");
  181.             return 1;
  182.         }
  183.  
  184.         //Create Gang//
  185.         if(gangcmd==1) {
  186.             if(playerGang[playerid]>0) {
  187.                 SendClientMessage(playerid, 0x83BFBFFF, "You are already in a gang!");
  188.                 return 1;
  189.             }
  190.  
  191.             for(new i = 1; i < MAX_GANGS; i++) {
  192.                 if(gangInfo[i][0]==0) {
  193.                     //name gang
  194.                     format(gangNames[i], MAX_GANG_NAME, "%s", tmp);
  195.                     //Gang exists
  196.                     gangInfo[i][0]=1;
  197.                     //There is one member
  198.                     gangInfo[i][1]=1;
  199.                     //Gang color is player's color
  200.                     gangInfo[i][2]=playerColors[playerid];
  201.  
  202.                     //Player is the first gang member
  203.                     gangMembers[i][0] = playerid;
  204.                     format(string, sizeof(string),"You have create the gang '%s' (id: %d)", gangNames[i], i);
  205.                     SendClientMessage(playerid, 0x83BFBFFF, string);
  206.  
  207.                     new file[128];
  208.                     format(file, sizeof(file), "dRegis/%s.ini", pName(playerid));
  209.                     dini_IntSet(file, "playerGang", gangNames[i]);
  210.  
  211.  
  212.  
  213.  
  214.                     playerGang[playerid]=i;
  215.  
  216.                     return 1;
  217.                 }
  218.             }
  219.  
  220.             return 1;
  221.  
  222.         //Join Gang//
  223.         } else if (gangcmd==3) {
  224.             gangnum = gangInvite[playerid];
  225.  
  226.             if(playerGang[playerid]>0) {
  227.                 SendClientMessage(playerid, 0x83BFBFFF, "You are already in a gang.");
  228.                 return 1;
  229.             }
  230.             if(gangInvite[playerid]==0) {
  231.                 SendClientMessage(playerid, 0x83BFBFFF, "You are not invite in a gang.");
  232.                 return 1;
  233.             }
  234.             if(gangInfo[gangnum][0]==0) {
  235.                 SendClientMessage(playerid, 0x83BFBFFF, "This gang doesnt exist.");
  236.                 return 1;
  237.             }
  238.  
  239.             if(gangInfo[gangnum][1] < MAX_GANG_MEMBERS) {
  240.                 new i = gangInfo[gangnum][1];
  241.  
  242.                 gangInvite[playerid]=0;
  243.  
  244.                 gangMembers[gangnum][i] = playerid;
  245.  
  246.                 GetPlayerName(playerid, sendername, MAX_PLAYER_NAME);
  247.                 for(new j = 0; j < gangInfo[gangnum][1]; j++) {
  248.                     format(string, sizeof(string),"%s joined your gang.", sendername);
  249.                     SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
  250.                 }
  251.  
  252.                 gangInfo[gangnum][1]++;
  253.                 playerGang[playerid] = gangnum;
  254.  
  255.                 SetPlayerColor(playerid,gangInfo[gangnum][2]);
  256.  
  257.                 format(string, sizeof(string),"You join the gang '%s'(id: %d)", gangNames[gangnum], gangnum);
  258.                 SendClientMessage(playerid, 0x83BFBFFF, string);
  259.  
  260.                 return 1;
  261.             }
  262.  
  263.             SendClientMessage(playerid, 0x83BFBFFF, "No members searched");
  264.             return 1;
  265.  
  266.         //Invite to Gang//
  267.         } else if (gangcmd==2) {
  268.             giveplayerid = strval(tmp);
  269.  
  270.             if(playerGang[playerid]==0) {
  271.                 SendClientMessage(playerid, 0x83BFBFFF, "You are not in a gang.");
  272.                 return 1;
  273.             }
  274. //          if(gangMembers[playerGang[playerid]][0]!=playerid) {
  275. //              SendClientMessage(playerid, COLOR_RED, "You need to be the gang leader to send an invite.");
  276. //              return 1;
  277. //          }
  278.  
  279.             if(IsPlayerConnected(giveplayerid)) {
  280.                 GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
  281.                 GetPlayerName(playerid, sendername, sizeof(sendername));
  282.  
  283.                 format(string, sizeof(string),"You invite %s in your gang.", giveplayer);
  284.                 SendClientMessage(playerid, 0x83BFBFFF, string);
  285.                 format(string, sizeof(string),"You get a gang invite from %s in his gang '%s' (id: %d)", sendername, gangNames[playerGang[playerid]],playerGang[playerid]);
  286.                 SendClientMessage(giveplayerid, 0x83BFBFFF, string);
  287.  
  288.                 gangInvite[giveplayerid]=playerGang[playerid];
  289.  
  290.             } else
  291.                 SendClientMessage(playerid, 0x83BFBFFF, "Player not findable!");
  292.  
  293.         //Leave Gang//
  294.         } else if (gangcmd==4) {
  295.             PlayerLeaveGang(playerid);
  296.         }
  297.  
  298.         return 1;
  299.     }
  300.  
  301.     //------------------- /ganginfo
  302.  
  303.     if(strcmp(cmd, "/ganginfo", true) == 0) {
  304.         new tmp[256];
  305.         new gangnum;
  306.         tmp = strtok(cmdtext, idx);
  307.  
  308.         if(!strlen(tmp) && playerGang[playerid]==0) {
  309.             SendClientMessage(playerid, 0x83BFBFFF, "Type: /ganginfo [GangID]");
  310.             return 1;
  311.         } else if (!strlen(tmp))
  312.             gangnum = playerGang[playerid];
  313.         else
  314.             gangnum = strval(tmp);
  315.  
  316.         if(gangInfo[gangnum][0]==0) {
  317.             SendClientMessage(playerid, 0x83BFBFFF, "Player not findable!");
  318.             return 1;
  319.         }
  320.  
  321.         format(string, sizeof(string),"'%s' Gang members (id: %d)", gangNames[gangnum], gangnum);
  322.         SendClientMessage(playerid, 0x83BFBFFF, string);
  323.  
  324.         for(new i = 0; i < gangInfo[gangnum][1]; i++) {
  325.             GetPlayerName(gangMembers[gangnum][i], giveplayer, sizeof(giveplayer));
  326.             format(string, sizeof(string),"%s (%d)", giveplayer, gangMembers[gangnum][i]);
  327.             SendClientMessage(playerid, 0x83BFBFFF, string);
  328.         }
  329.  
  330.         return 1;
  331.     }
  332.  
  333.     //------------------- /gangs
  334.  
  335.     if(strcmp(cmd, "/gangs", true) == 0)
  336.     {
  337.         new x;
  338.  
  339.         SendClientMessage(playerid, 0x83BFBFFF, "Exist gangs:");
  340.         for(new i=0; i < MAX_GANGS; i++) {
  341.             if(gangInfo[i][0]==1) {
  342.                 format(string, sizeof(string), "%s%s(%d) - %d members", string,gangNames[i],i,gangInfo[i][1]);
  343.  
  344.                 x++;
  345.                 if(x > 2) {
  346.                     SendClientMessage(playerid, 0x83BFBFFF, string);
  347.                     x = 0;
  348.                     format(string, sizeof(string), "");
  349.                 } else {
  350.                     format(string, sizeof(string), "%s, ", string);
  351.                 }
  352.             }
  353.         }
  354.  
  355.         if(x <= 2 && x > 0) {
  356.             string[strlen(string)-2] = '.';
  357.             SendClientMessage(playerid, 0x83BFBFFF, string);
  358.         }
  359.  
  360.         return 1;
  361.     }
  362.     return 0;
  363. }
  364.  
  365. stock PlayerName(playerid) {
  366.   new name[255];
  367.   GetPlayerName(playerid, name, 255);
  368.   return name;
  369. }
  370.  
  371. public PlayerLeaveGang(playerid) {
  372.     new string[256];
  373.     new playername[MAX_PLAYER_NAME];
  374.     new gangnum = playerGang[playerid];
  375.  
  376.     if(gangnum > 0) {
  377.         for(new i = 0; i < gangInfo[gangnum][1]; i++) {
  378.             if(gangMembers[gangnum][i]==playerid) {
  379.  
  380.                 //One less gang member
  381.                 gangInfo[gangnum][1]--;
  382.  
  383.                 for(new j = i; j < gangInfo[gangnum][1]; j++) {
  384.                     //Shift gang members
  385.                     gangMembers[gangnum][j]=gangMembers[gangnum][j+1];
  386.                 }
  387.  
  388.                 //Disband gang if no more members
  389.                 if(gangInfo[gangnum][1]<1) {
  390.                     gangInfo[gangnum][0]=0;
  391.                     gangInfo[gangnum][1]=0;
  392.                     gangBank[gangnum]=0;
  393.                 }
  394.  
  395.                 //Notify other members
  396.                 for(new j = 0; j < gangInfo[gangnum][1]; j++) {
  397.                     GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
  398.                     format(string, sizeof(string),"%s left your gang!", playername);
  399.                     SendClientMessage(gangMembers[gangnum][j], COLOR_ORANGE, string);
  400.                 }
  401.  
  402.                 format(string, sizeof(string),"You left the gang '%s'(id: %d)", gangNames[gangnum], gangnum);
  403.                 SendClientMessage(playerid, 0x83BFBFFF, string);
  404.  
  405.                 playerGang[playerid]=0;
  406.  
  407.                 SetPlayerColor(playerid,playerColors[playerid]);
  408.  
  409.                 return;
  410.             }
  411.         }
  412.     } else {
  413.         SendClientMessage(playerid, 0x83BFBFFF, "You arent in a gang.");
  414.         }
  415. }
  416.  
  417. strtok(const string[], &index)
  418. {
  419.     new length = strlen(string);
  420.     while ((index < length) && (string[index] <= ' '))
  421.     {
  422.         index++;
  423.     }
  424.  
  425.     new offset = index;
  426.     new result[20];
  427.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  428.     {
  429.         result[index - offset] = string[index];
  430.         index++;
  431.     }
  432.     result[index - offset] = EOS;
  433.     return result;
  434. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement