Advertisement
JaQQeri

Dynamic organization system

Dec 15th, 2011
4,887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 28.17 KB | None | 0 0
  1. /*
  2. DYNAMIC ORGANIZATIONS FILTERSCRIPT
  3. CODED FROM SCRATCH BY JAKKU
  4. COPYRIGHT (C) 2011 - 2014
  5. RELEASE DATE: 15/12/2011
  6. PLEASE REPORT ALL BUGS (If found) @ SA-MP FORUMS - http://forum.sa-mp.com/showthread.php?t=303864
  7. */
  8.  
  9.  
  10.  
  11. /*
  12. Changelog v.2
  13.  
  14. - CreateOrganizationZone can be used to create coloured "gangzones" for orgs
  15. - IsPlayerInOrgZone(playerid, orgname)
  16. - SendClientMessageToOrg(orgname, color, message)
  17. - Fixed some small bugs, nothing serious
  18. - Added auto-save for player stats and org. leaders (45sec delay)
  19. - Added /decline command for leaders to decline incoming requests
  20.  
  21. Changelog 27.12.2014
  22. - Fixed indentation :)
  23.  
  24. */
  25.  
  26.  
  27. #include <a_samp>
  28. #include <Dini>
  29. #include <sscanf2>
  30. #include <zcmd>
  31.  
  32.  
  33.  
  34. //Color defines
  35. #define COLOR_GREY 0xAFAFAFAA
  36. #define COLOR_WHITE 0xFFFFFFAA
  37. #define COLOR_ORANGE 0xFF9900AA
  38. #define COLOR_YELLOW 0xFFFF00AA
  39. #define COLOR_RED 0xFF0000FF
  40. //
  41.  
  42.  
  43. #define WAGE 150 //Define the wage here
  44. #define MAX_ORGS 10 //Change only if you need more than 10 orgs
  45. #define MAX_ORG_WEAPONS 3 //Max amount of weapons for orgs
  46. #define ORG_NAME_LENGTH 32 //Max name length for organization and it's leader
  47. #define MAX_ORG_VEHICLES 10
  48. #define MAX_ZONES_PER_ORG 10
  49.  
  50. #define SAVE_LEADERS_TO "org_leaders.txt"
  51.  
  52.  
  53.  
  54.  
  55. // Script configuration
  56.  
  57. #define SPAWN_WITH_ORG_SKIN //Comment this line IF YOU DON'T WANT THE PLAYERS SPAWN WITH ORGANIZATION SKIN!
  58. #define ENABLE_HQ_TELE //Comment this line IF YOU WANT TO DISABLE /teletohq
  59.  
  60. //
  61.  
  62.  
  63. forward PayDay();
  64. forward CheckArea();
  65. forward AutoSave();
  66.  
  67.  
  68. new OrgsCount;
  69. new ZoneCount;
  70.  
  71.  
  72. enum Orgs
  73. {
  74. Name[32],
  75. Leader[24],
  76. Skin,
  77. Float:X,
  78. Float:Y,
  79. Float:Z,
  80. Weapons[3],
  81. Ammo[3],
  82. Vehicles[MAX_ORG_VEHICLES],
  83. VehiclesCreated,
  84. Text3D:OrgLabel,
  85. Zones[MAX_ZONES_PER_ORG],
  86. Float:ZoneMinX[MAX_ZONES_PER_ORG],
  87. Float:ZoneMinY[MAX_ZONES_PER_ORG],
  88. Float:ZoneMaxX[MAX_ZONES_PER_ORG],
  89. Float:ZoneMaxY[MAX_ZONES_PER_ORG],
  90. ZoneColor[MAX_ZONES_PER_ORG],
  91. ZonesCreated,
  92. };
  93.  
  94. new Organization[MAX_ORGS][Orgs];
  95.  
  96. new PlayerOrg[MAX_PLAYERS];
  97. new PlayerLeader[MAX_PLAYERS];
  98. new PlayerRank[MAX_PLAYERS][28];
  99. new Requesting[MAX_PLAYERS];
  100. new CollectedWage[MAX_PLAYERS];
  101.  
  102.  
  103. public OnFilterScriptInit()
  104. {
  105.     print("\n--------------------------------------");
  106.     print("==Dynamic organization filterscript by Jakku - initialized!==");
  107.     print("==(C) 2011 - 2012==");
  108.     print("--------------------------------------\n");
  109.  
  110.  
  111.     SetTimer("PayDay",1500000,1); //PayDay every 25 minutes
  112.     SetTimer("CheckArea",1000,1);
  113.     SetTimer("AutoSave",45000,1);
  114.  
  115.     /*
  116.  
  117.     ALWAYS add your organization BELOW the old one, otherwise the IDs will change = leaders mix up ! ! ! ! !
  118.  
  119.     Syntax for CreateOrganization: CreateOrganization(name[32], skin, Float:x,Float:y,Float:z, wp1,a1,wp2,a2,wp3,a3)
  120.  
  121.     Syntax for CreateOrgVehicle: CreateOrgVehicle(orgname[32], modelid, Float:x,Float:y,Float:z,Float:rotation, color1,color2)
  122.  
  123.     Syntax for CreateOrganizationZone: CreateOrganizationZone(orgname[32], Float:minx,Float:miny,Float:maxx,Float:maxy, color)
  124.  
  125.     */
  126.  
  127.     //Create ORGS here:
  128.  
  129.     //
  130.  
  131.     //Create ORG VEHICLES here:
  132.  
  133.     //
  134.  
  135.     //Create ORG ZONES here:
  136.  
  137.     //
  138.  
  139.  
  140.  
  141.     LoadLeaders(); //This MUST BE executed AFTER the organizations are being created!
  142.  
  143.     new pcount = 0;
  144.     for (new playerid = 0;playerid<MAX_PLAYERS;playerid++)
  145.     {
  146.         if (IsPlayerConnected(playerid))
  147.         {
  148.             LoadPlayerOrgInfo(playerid);
  149.             pcount++;
  150.         }
  151.     }
  152.     if (pcount > 0)
  153.     {
  154.         printf("==Dynamic organization filterscript by Jakku reloaded!==");
  155.         printf("==Data loaded for %d connected players==", pcount);
  156.     }
  157.  
  158.     return 1;
  159. }
  160.  
  161.  
  162. public PayDay()
  163. {
  164.     for (new i=0;i<MAX_PLAYERS;i++)
  165.     {
  166.         if (IsPlayerConnected(i))
  167.         {
  168.             if (PlayerOrg[i] != 0)
  169.             {
  170.                 new string[80];
  171.                 format(string, sizeof(string),"You have earned from your org. ($%d)", WAGE);
  172.                 SendClientMessage(i, COLOR_GREY, string);
  173.                 CollectedWage[i]+=WAGE;
  174.                 SavePlayerOrgInfo(i);
  175.             }
  176.         }
  177.     }
  178. }
  179.  
  180. public AutoSave()
  181. {
  182.     for (new i=0;i<MAX_PLAYERS;i++)
  183.     {
  184.         if (IsPlayerConnected(i))
  185.         {
  186.             SavePlayerOrgInfo(i);
  187.         }
  188.     }
  189.  
  190.     SaveLeaders();
  191. }
  192.  
  193. public CheckArea()
  194. {
  195.     for (new i=0;i<MAX_PLAYERS;i++)
  196.     {
  197.         if (IsPlayerConnected(i))
  198.         {
  199.             new count,name[32];
  200.             for (new c=1;c<OrgsCount+1;c++)
  201.             {
  202.                 if (DoesOrgExist(GetOrgName(c)))
  203.                 {
  204.                     for (new a=1;a<Organization[c][ZonesCreated]+1;a++)
  205.                     {
  206.                         if (IsPlayerInArea(i, Organization[c][ZoneMinX][a],Organization[c][ZoneMinY][a],Organization[c][ZoneMaxX][a],Organization[c][ZoneMaxY][a]))
  207.                         {
  208.                             count++;
  209.                             name = GetOrgName(c);
  210.                         }
  211.                     }
  212.                 }
  213.             }
  214.  
  215.             if (count != 0)
  216.             {
  217.                 if (GetPVarInt(i, "IsInOrgZone") == 0)
  218.                 {
  219.                     new string[120];
  220.                     if (PlayerOrg[i] == GetOrgID(name))
  221.                     {
  222.                         format(string,sizeof(string),"Welcome to your organization's zone!");
  223.                     }
  224.                     else
  225.                     {
  226.                         format(string,sizeof(string),"You are now in {5CB3FF}%s's{FFFFFF} zone!", name);
  227.                     }
  228.                     SendClientMessage(i, COLOR_WHITE, string);
  229.                     SetPVarInt(i, "IsInOrgZone", 1);
  230.                     return 1;
  231.                 }
  232.             }
  233.             else
  234.             {
  235.                 SetPVarInt(i, "IsInOrgZone", 0);
  236.             }
  237.         }
  238.     }
  239.     return 1;
  240. }
  241.  
  242.  
  243.  
  244. public OnFilterScriptExit()
  245. {
  246.     print("Thank you for using Jakku's Dynamic organizations- filterscript");
  247.     print("(C) 2011 - 2012");
  248.  
  249.     for (new i=1;i<OrgsCount+1;i++)
  250.     {
  251.         for (new a=0;a<MAX_ORG_VEHICLES;a++)
  252.         {
  253.             if (IsVehicleConnected(Organization[i][Vehicles][a]))
  254.             {
  255.                 DestroyVehicle(Organization[i][Vehicles][a]);
  256.             }
  257.         }
  258.         Delete3DTextLabel(Organization[i][OrgLabel]);
  259.     }
  260.  
  261.     for (new playerid = 0;playerid<MAX_PLAYERS;playerid++)
  262.     {
  263.         if (IsPlayerConnected(playerid))
  264.         {
  265.             SavePlayerOrgInfo(playerid);
  266.         }
  267.     }
  268.  
  269.     SaveLeaders();
  270.     return 1;
  271. }
  272.  
  273.  
  274. public OnPlayerConnect(playerid)
  275. {
  276.     PlayerOrg[playerid] = 0; //Resetting player org
  277.     PlayerLeader[playerid] = 0; //Resetting player org leader status
  278.     Requesting[playerid] = 0;
  279.     CollectedWage[playerid] = 0;
  280.     PlayerRank[playerid] = "None";
  281.  
  282.     if(!dini_Exists(PlayerPath(playerid))) //Creating file (check stock PlayerPath(playerid) )
  283.     {
  284.         SendClientMessage(playerid, COLOR_ORANGE,"As this is your first visit here, we decided to tell you that this server is using Dynamic organization- script by Jakku");
  285.         dini_Create(PlayerPath(playerid));
  286.     }
  287.     else
  288.     {
  289.         LoadPlayerOrgInfo(playerid);
  290.     }
  291.     return 1;
  292. }
  293.  
  294. public OnPlayerDisconnect(playerid, reason)
  295. {
  296.     SavePlayerOrgInfo(playerid);
  297.     return 1;
  298. }
  299.  
  300. public OnPlayerSpawn(playerid)
  301. {
  302.     if (PlayerOrg[playerid] != 0)
  303.     {
  304.         if (GetPVarInt(playerid, "Dead") == 0)
  305.         {
  306.             new string[160];
  307.             new leader[4];
  308.             if (IsLeader(playerid)) leader = "Yes";
  309.             else leader = "No";
  310.             format(string,sizeof(string),"Organization: {5CB3FF}%s {FFFFFF}|| Leader: {5CB3FF}%s {FFFFFF}|| Rank: {5CB3FF}%s", GetOrgName(PlayerOrg[playerid]), leader, PlayerRank[playerid]);
  311.             SendClientMessage(playerid, COLOR_WHITE, string);
  312.             GiveOrgFeatures(playerid);
  313.         }
  314.     }
  315.     SetPVarInt(playerid, "Dead", 0);
  316.  
  317.     for (new i=1;i<OrgsCount+1;i++)
  318.     {
  319.         for (new a=1;a<Organization[i][ZonesCreated]+1;a++)
  320.         {
  321.             GangZoneShowForPlayer(playerid, Organization[i][Zones][a], Organization[i][ZoneColor][a]);
  322.         }
  323.     }
  324.  
  325.     return 1;
  326. }
  327.  
  328. public OnPlayerDeath(playerid, killerid, reason)
  329. {
  330.     SetPVarInt(playerid, "Dead", 1);
  331. }
  332.  
  333.  
  334. public OnPlayerCommandText(playerid, cmdtext[])
  335. {
  336.     return 0;
  337. }
  338.  
  339.  
  340.  
  341. public OnPlayerEnterCheckpoint(playerid)
  342. {
  343.     return 1;
  344. }
  345.  
  346.  
  347.  
  348. public OnPlayerPickUpPickup(playerid, pickupid)
  349. {
  350.     return 1;
  351. }
  352.  
  353.  
  354. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  355. {
  356.     if (dialogid == 755)
  357.     {
  358.         if (response)
  359.         {
  360.             new string[120];
  361.             format(string,sizeof(string),"You have resigned from %s", Organization[PlayerOrg[playerid]][Name]);
  362.             SendClientMessage(playerid, COLOR_YELLOW, string);
  363.             format(string,sizeof(string),"**%s has resigned from %s", PlayerName(playerid), Organization[PlayerOrg[playerid]][Name]);
  364.             SendClientMessageToAllEx(playerid, COLOR_GREY, string);
  365.  
  366.             if (IsLeader(playerid))
  367.             {
  368.                 new none[24];
  369.                 format(none,sizeof(none),"None");
  370.                 Organization[PlayerOrg[playerid]][Leader] = none;
  371.             }
  372.             ResetPlayerOrg(playerid);
  373.             SavePlayerOrgInfo(playerid);
  374.         }
  375.         else
  376.         {
  377.             SendClientMessage(playerid, COLOR_YELLOW, "Resignation cancelled");
  378.         }
  379.     }
  380.  
  381.     if (dialogid == 756 && response)
  382.     {
  383.         switch (listitem)
  384.         {
  385.             case 0:
  386.             {
  387.                 for (new i=1;i<OrgsCount+1;i++)
  388.                 {
  389.                     if (IsPlayerInRangeOfPoint(playerid, 3.0, Organization[i][X], Organization[i][Y],Organization[i][Z]))
  390.                     {
  391.                         new string[140];
  392.                         format(string,sizeof(string),"{5CB3FF}Organization: {FFFFFF}%s\n{5CB3FF}Leader: {FFFFFF}%s", GetOrgName(i), Organization[i][Leader]);
  393.                         ShowPlayerDialog(playerid, 757, DIALOG_STYLE_MSGBOX, "Organization",string,"Close","");
  394.                         return 1;
  395.                     }
  396.                 }
  397.  
  398.             }
  399.  
  400.             case 1:
  401.             {
  402.                 if (CollectedWage[playerid] <= 0) return SendClientMessage(playerid, COLOR_RED, "You don't have any wage earned yet!");
  403.                 new string[80];
  404.                 format(string,sizeof(string),"You have collected $%d", CollectedWage[playerid]);
  405.                 SendClientMessage(playerid, COLOR_YELLOW, string);
  406.                 GivePlayerMoney(playerid, CollectedWage[playerid]);
  407.                 CollectedWage[playerid] = 0;
  408.                 SavePlayerOrgInfo(playerid);
  409.             }
  410.  
  411.         }
  412.  
  413.     }
  414.     return 1;
  415. }
  416.  
  417. public OnPlayerStateChange(playerid,newstate,oldstate)
  418. {
  419.     if (newstate == PLAYER_STATE_DRIVER)
  420.     {
  421.         for (new i=1;i<OrgsCount+1;i++)
  422.         {
  423.            for (new a=0;a<MAX_ORG_VEHICLES;a++)
  424.            {
  425.                 new vehicleid = GetPlayerVehicleID(playerid);
  426.                 if (IsVehicleConnected(vehicleid))
  427.                 {
  428.                     if (vehicleid == Organization[i][Vehicles][a] && PlayerOrg[playerid] != i)
  429.                     {
  430.                         if (DoesOrgExist(GetOrgName(i)))
  431.                         {
  432.                             new string[100];
  433.                             format(string,sizeof(string),"This vehicle belongs to %s. You are not authorized to use it", GetOrgName(i));
  434.                             SendClientMessage(playerid, COLOR_RED, string);
  435.                             RemovePlayerFromVehicle(playerid);
  436.                         }
  437.                     }
  438.                 }
  439.             }
  440.         }
  441.     }
  442.     return 1;
  443. }
  444.  
  445. stock PlayerName(playerid)
  446. {
  447.     new playername[24];
  448.     GetPlayerName(playerid, playername, 24);
  449.     return playername;
  450. }
  451.  
  452.  
  453. stock CreateOrganization(name[32], skin, Float:x,Float:y,Float:z, wp1 = 0,a1 = 0,wp2 = 0,a2 = 0,wp3 = 0,a3 = 0)
  454. {
  455.     OrgsCount++;
  456.     if (OrgsCount >= MAX_ORGS) return printf("You have exceeded the MAX_ORGS- define! Aborted");
  457.     new id = OrgsCount;
  458.     Organization[id][Name] = name;
  459.     Organization[id][Skin] = skin;
  460.     Organization[id][X] = x;
  461.     Organization[id][Y] = y;
  462.     Organization[id][Z] = z;
  463.     Organization[id][Weapons][0] = wp1;
  464.     Organization[id][Ammo][0] = a1;
  465.     Organization[id][Weapons][1] = wp2;
  466.     Organization[id][Ammo][1] = a2;
  467.     Organization[id][Weapons][2] = wp3;
  468.     Organization[id][Ammo][2] = a3;
  469.     printf("Organization created: ID: %d || Name: %s",id, name);
  470.     new string[100];
  471.     format(string,sizeof(string),"{5CB3FF}HQ:{FFFFFF} %s\nType {5CB3FF}/org{FFFFFF} for more information!",name);
  472.     Organization[id][OrgLabel] = Create3DTextLabel(string, 0x008080FF, x, y, z, 25.0, 0);
  473.     return 1;
  474. }
  475.  
  476. stock PlayerPath(playerid)
  477. {
  478.     new path[45];
  479.     format(path, sizeof(path),"Orginfo_%s.ini", PlayerName(playerid));
  480.     return path;
  481. }
  482.  
  483. stock SaveLeaders()
  484. {
  485.     new part[40];
  486.     if (!dini_Exists(SAVE_LEADERS_TO))
  487.     {
  488.         dini_Create(SAVE_LEADERS_TO);
  489.     }
  490.  
  491.     for (new i=1;i<OrgsCount+1;i++)
  492.     {
  493.         format(part,sizeof(part),"%d", i);
  494.         dini_Set(SAVE_LEADERS_TO,part,Organization[i][Leader]);
  495.     }
  496. }
  497.  
  498. stock LoadLeaders()
  499. {
  500.     new part[24];
  501.     new part2[40];
  502.  
  503.     if (!dini_Exists(SAVE_LEADERS_TO))
  504.     {
  505.         for (new i=1;i<OrgsCount+1;i++)
  506.         {
  507.             dini_Create(SAVE_LEADERS_TO);
  508.             format(part,sizeof(part),"None");
  509.             Organization[i][Leader] = part;
  510.             SaveLeaders();
  511.         }
  512.         return 1;
  513.     }
  514.  
  515.     for (new i=1;i<OrgsCount+1;i++)
  516.     {
  517.         format(part2,sizeof(part2),"%d", i);
  518.         format(part,sizeof(part),dini_Get(SAVE_LEADERS_TO,part2));
  519.  
  520.         if (strcmp(part," ", false) == 0)
  521.         {
  522.             part = "None";
  523.         }
  524.  
  525.         Organization[i][Leader] = part;
  526.     }
  527.     return 1;
  528. }
  529.  
  530. stock SavePlayerOrgInfo(playerid)
  531. {
  532.     if (!dini_Exists(PlayerPath(playerid)))
  533.     {
  534.         dini_Create(PlayerPath(playerid));
  535.     }
  536.     dini_Set(PlayerPath(playerid),"Org",Organization[PlayerOrg[playerid]][Name]);
  537.     dini_Set(PlayerPath(playerid),"Rank",PlayerRank[playerid]);
  538.     dini_IntSet(PlayerPath(playerid),"CollectedWage",CollectedWage[playerid]);
  539. }
  540.  
  541. stock LoadPlayerOrgInfo(playerid)
  542. {
  543.     new string[45];
  544.     format(string,sizeof(string),"%s",dini_Get(PlayerPath(playerid),"Org"));
  545.     PlayerOrg[playerid] = GetOrgID(string);
  546.     new string2[28];
  547.     format(string2,sizeof(string2),"%s",dini_Get(PlayerPath(playerid),"Rank"));
  548.     PlayerRank[playerid] = string2;
  549.     CollectedWage[playerid] = dini_Int(PlayerPath(playerid), "CollectedWage");
  550.  
  551.     if (strcmp(Organization[PlayerOrg[playerid]][Leader], PlayerName(playerid),true) == 0 && PlayerOrg[playerid] != 0)
  552.     {
  553.         PlayerLeader[playerid] = 1;
  554.     }
  555. }
  556.  
  557. stock GiveOrgFeatures(playerid)
  558. {
  559.     new org = PlayerOrg[playerid];
  560.     if (!org) return 1;
  561.     GivePlayerWeapon(playerid, Organization[org][Weapons][0],Organization[org][Ammo][0]);
  562.     GivePlayerWeapon(playerid, Organization[org][Weapons][1],Organization[org][Ammo][1]);
  563.     GivePlayerWeapon(playerid, Organization[org][Weapons][2],Organization[org][Ammo][2]);
  564.     #if defined SPAWN_WITH_ORG_SKIN
  565.     SetPlayerSkin(playerid, Organization[org][Skin]);
  566.     #endif
  567.     return 1;
  568. }
  569.  
  570. stock GetOrgName(orgid)
  571. {
  572.     new name[32];
  573.     format(name,sizeof(name),"%s",Organization[orgid][Name]);
  574.     if (orgid == 0) format(name,sizeof(name),"None");
  575.     return name;
  576. }
  577.  
  578.  
  579.  
  580.  
  581. stock SendClientMessageToAllEx(exception, clr, const message[])
  582. {
  583.     for(new i; i<MAX_PLAYERS; i++)
  584.     {
  585.         if(IsPlayerConnected(i))
  586.         {
  587.             if(i != exception)
  588.             {
  589.                 SendClientMessage(i, clr, message);
  590.             }
  591.         }
  592.     }
  593. }
  594.  
  595. stock ResetPlayerOrg(playerid)
  596. {
  597.     if (PlayerOrg[playerid] == 0) return 1;
  598.     printf("%s has been removed from %s", PlayerName(playerid), GetOrgName(PlayerOrg[playerid]));
  599.     SetPlayerSkin(playerid, 0);
  600.     ResetPlayerWeapons(playerid);
  601.     PlayerOrg[playerid] = 0;
  602.     Requesting[playerid] = 0;
  603.     PlayerLeader[playerid] = 0;
  604.     return 1;
  605. }
  606.  
  607.  
  608. CMD:resign(playerid)
  609. {
  610.     if (PlayerOrg[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "You are not a member of an organization");
  611.     ShowPlayerDialog(playerid, 755, DIALOG_STYLE_MSGBOX, "{FFFFFF}Are you sure you want to resign?","{FFFFFF}Please {00FF00}confirm {FFFFFF}your resignation request","Resign","Cancel");
  612.     return 1;
  613. }
  614.  
  615.  
  616. CMD:ochat(playerid, params[])
  617. {
  618.     if (PlayerOrg[playerid] == 0) return SendClientMessage(playerid, COLOR_RED,"You are not a member of an organization");
  619.     new text[100];
  620.     if (sscanf(params, "s[100]", text)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /ochat [message]");
  621.     new org = PlayerOrg[playerid];
  622.     new string[128];
  623.     format(string,sizeof(string),"{5CB3FF}(Org Chat) {FFFFFF}(%s): %s", PlayerName(playerid), text);
  624.     SendClientMessageToOrg(GetOrgName(org), COLOR_WHITE, string);
  625.     return 1;
  626. }
  627.  
  628. CMD:teletohq(playerid)
  629. {
  630.     #if defined ENABLE_HQ_TELE
  631.     if (PlayerOrg[playerid] == 0) return SendClientMessage(playerid, COLOR_RED,"You are not a member of an organization");
  632.  
  633.     if (IsPlayerInRangeOfPoint(playerid, 10.0,Organization[PlayerOrg[playerid]][X],Organization[PlayerOrg[playerid]][Y],Organization[PlayerOrg[playerid]][Z]))
  634.     {
  635.     SendClientMessage(playerid, COLOR_RED,"You are already close to your HQ!");
  636.     return 1;
  637.     }
  638.  
  639.     SetPlayerPos(playerid, Organization[PlayerOrg[playerid]][X],Organization[PlayerOrg[playerid]][Y],Organization[PlayerOrg[playerid]][Z]);
  640.     SendClientMessage(playerid, COLOR_YELLOW,"You have teleported to your HQ");
  641.  
  642.     #else
  643.     SendClientMessage(playerid, COLOR_RED,"This feature has been disabled");
  644.     #endif
  645.  
  646.     return 1;
  647. }
  648.  
  649.  
  650. CMD:ovrespawn(playerid)
  651. {
  652.     if (!IsLeader(playerid)) return SendClientMessage(playerid, COLOR_RED,"You are not the leader of an organization!");
  653.     new org = PlayerOrg[playerid];
  654.     if (Organization[org][VehiclesCreated] <= 0) return SendClientMessage(playerid, COLOR_RED,"There are no vehicles created for your org!");
  655.     SendClientMessage(playerid, COLOR_YELLOW,"You have respawned your org. vehicles!");
  656.  
  657.     for (new i=0;i<MAX_ORG_VEHICLES;i++)
  658.     {
  659.         if (IsVehicleConnected(Organization[org][Vehicles][i]))
  660.         {
  661.             SetVehicleToRespawn(Organization[org][Vehicles][i]);
  662.         }
  663.     }
  664.     return 1;
  665. }
  666.  
  667. CMD:org(playerid)
  668. {
  669.     for (new i=1;i<OrgsCount+1;i++)
  670.     {
  671.         if (IsPlayerInRangeOfPoint(playerid, 3.0, Organization[i][X],Organization[i][Y],Organization[i][Z]))
  672.         {
  673.             new string[35];
  674.             new string2[80];
  675.             format(string, sizeof(string),"%s", GetOrgName(i));
  676.             format(string2, sizeof(string2),"Information");
  677.             if (PlayerOrg[playerid] == i) format(string2, sizeof(string2),"Information\nCollect Wage");
  678.             ShowPlayerDialog(playerid, 756, DIALOG_STYLE_LIST, string,string2,"Ok","Cancel");
  679.             return 1;
  680.         }
  681.     }
  682.     SendClientMessage(playerid, COLOR_RED,"You are not close enough to an organization!");
  683.     return 1;
  684. }
  685.  
  686. CMD:setmember(playerid, params[])
  687. {
  688.     if (!IsLeader(playerid)) return SendClientMessage(playerid,COLOR_RED,"You are not the leader of an organization");
  689.     new ID;
  690.     if (sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /setmember [playerid]");
  691.     if (!IsPlayerConnected(ID) || ID == playerid) return 1;
  692.     new org = PlayerOrg[playerid];
  693.     if (PlayerOrg[ID]) return SendClientMessage(playerid, COLOR_RED,"That player already belongs to an organization");
  694.     if (Requesting[ID] != org) return SendClientMessage(playerid, COLOR_RED,"That player is not requesting to join your organization!");
  695.     new string[120];
  696.     format(string,sizeof(string),"%s has set you as a member of %s", PlayerName(playerid), GetOrgName(org));
  697.     SendClientMessage(ID, COLOR_YELLOW, string);
  698.     format(string,sizeof(string),"You have set %s a member of %s", PlayerName(ID), GetOrgName(org));
  699.     SendClientMessage(playerid, COLOR_YELLOW, string);
  700.     PlayerOrg[ID] = org;
  701.     GiveOrgFeatures(ID);
  702.     Requesting[ID] = 0;
  703.     return 1;
  704. }
  705.  
  706. CMD:setleader(playerid, params[])
  707. {
  708.     if (!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,COLOR_RED,"You must be logged into RCON to use this command!");
  709.     new ID,orgid;
  710.     if (sscanf(params, "ud", ID,orgid)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /setleader [playerid] [orgid]");
  711.     if (!IsPlayerConnected(ID)) return 1;
  712.     if (PlayerOrg[ID]) return SendClientMessage(playerid, COLOR_RED,"That player already belongs to an organization");
  713.     if (orgid < 1 || orgid > OrgsCount) return SendClientMessage(playerid, COLOR_RED,"Invalid org. ID!");
  714.     new string[140];
  715.     format(string,sizeof(string),"An admin %s has set you as the leader of %s", PlayerName(playerid), GetOrgName(orgid));
  716.     SendClientMessage(ID, COLOR_YELLOW, string);
  717.     format(string,sizeof(string),"You have set %s the leader of %s", PlayerName(ID), GetOrgName(orgid));
  718.     SendClientMessage(playerid, COLOR_YELLOW, string);
  719.     PlayerOrg[ID] = orgid;
  720.     PlayerLeader[ID] = 1;
  721.     Organization[orgid][Leader] = PlayerName(ID);
  722.     SaveLeaders();
  723.     SavePlayerOrgInfo(ID);
  724.     GiveOrgFeatures(ID);
  725.     return 1;
  726. }
  727.  
  728.  
  729. CMD:setrank(playerid, params[])
  730. {
  731.     if (!IsLeader(playerid)) return SendClientMessage(playerid,COLOR_RED,"You are not the leader of an organization");
  732.     new ID, rank[28];
  733.     if (sscanf(params, "us[28]", ID, rank)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /setrank [playerid] [rank]");
  734.     if (strlen(rank) > 28) return SendClientMessage(playerid, COLOR_RED,"The maximum rank length is 28 characters!");
  735.     if (!IsPlayerConnected(ID)) return 1;
  736.     new org = PlayerOrg[playerid];
  737.     if (PlayerOrg[ID] != org) return SendClientMessage(playerid, COLOR_RED,"That player does not belong to your organization");
  738.     new string[120];
  739.     format(string,sizeof(string),"Your leader %s has given you a rank: '%s'", PlayerName(playerid), rank);
  740.     SendClientMessage(ID, COLOR_YELLOW, string);
  741.     format(string,sizeof(string),"You have given a rank to %s (%s)", PlayerName(ID), rank);
  742.     SendClientMessage(playerid, COLOR_YELLOW, string);
  743.     PlayerRank[ID] = rank;
  744.     SavePlayerOrgInfo(ID);
  745.     return 1;
  746. }
  747.  
  748. CMD:kickmember(playerid, params[])
  749. {
  750.     if (!IsLeader(playerid)) return SendClientMessage(playerid,COLOR_RED,"You are not the leader of an organization");
  751.     new ID;
  752.     if (sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /kickmember [playerid]");
  753.     if (!IsPlayerConnected(ID) || ID == playerid) return 1;
  754.     new org = PlayerOrg[playerid];
  755.     if (PlayerOrg[ID] != org) return SendClientMessage(playerid, COLOR_RED,"That player does not belong to your organization");
  756.     new string[130];
  757.     format(string,sizeof(string),"%s has kicked you from %s", PlayerName(playerid), GetOrgName(org));
  758.     SendClientMessage(ID, COLOR_YELLOW, string);
  759.     format(string,sizeof(string),"You have kicked %s from %s", PlayerName(ID), GetOrgName(org));
  760.     SendClientMessage(playerid, COLOR_YELLOW, string);
  761.     ResetPlayerOrg(ID);
  762.     return 1;
  763. }
  764.  
  765. CMD:request(playerid, params[])
  766. {
  767.     if (PlayerOrg[playerid] > 0) return SendClientMessage(playerid, COLOR_RED,"You already belong to an organization!");
  768.     if (Requesting[playerid] > 0) return SendClientMessage(playerid, COLOR_RED,"You are already requesting to join an organization!");
  769.     new ID;
  770.     if (sscanf(params, "d", ID)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /request [org id]");
  771.     if (ID < 1 || ID > OrgsCount) return SendClientMessage(playerid,COLOR_RED,"Invalid organization ID! Type /orglist for a complete list");
  772.     if (!IsLeaderOnline(ID)) return SendClientMessage(playerid,COLOR_RED,"The leader of this organization is currently offline!");
  773.     new string[120];
  774.     format(string,sizeof(string),"%s is requesting to join the %s", PlayerName(playerid), GetOrgName(ID));
  775.     SendClientMessageToAllEx(playerid, COLOR_GREY, string);
  776.     format(string,sizeof(string),"Your request to %s has been sent", GetOrgName(ID));
  777.     SendClientMessage(playerid, COLOR_YELLOW, string);
  778.     Requesting[playerid] = ID;
  779.     return 1;
  780. }
  781.  
  782. CMD:decline(playerid, params[])
  783. {
  784.     if (!IsLeader(playerid)) return SendClientMessage(playerid,COLOR_RED,"You are not the leader of an organization");
  785.     new ID;
  786.     if (sscanf(params, "u", ID)) return SendClientMessage(playerid,COLOR_WHITE,"Usage: /decline [playerid]");
  787.     if (!IsPlayerConnected(ID) || ID == playerid) return 1;
  788.     new org = PlayerOrg[playerid];
  789.     if (Requesting[ID] != org) return SendClientMessage(playerid, COLOR_RED,"That player is not requesting to join your organization!");
  790.     new string[120];
  791.     format(string,sizeof(string),"Your request to %s has been declined by %s", GetOrgName(org), PlayerName(playerid));
  792.     SendClientMessage(ID, COLOR_GREY, string);
  793.     format(string,sizeof(string),"You have successfully declined %s's request", PlayerName(ID));
  794.     SendClientMessage(playerid, COLOR_YELLOW, string);
  795.     Requesting[ID] = 0;
  796.     return 1;
  797. }
  798.  
  799. CMD:orglist(playerid)
  800. {
  801.     new string[90];
  802.     if (OrgsCount == 0) return SendClientMessage(playerid, COLOR_RED,"Sorry, there are no organizations created at the moment!");
  803.     SendClientMessage(playerid, COLOR_WHITE, "Current organizations:");
  804.  
  805.     for (new i=1;i<OrgsCount+1;i++)
  806.     {
  807.         format(string,sizeof(string),"ID: %d || Name: %s || Leader: %s", i, GetOrgName(i), Organization[i][Leader]);
  808.         SendClientMessage(playerid, COLOR_YELLOW, string);
  809.     }
  810.     return 1;
  811. }
  812.  
  813. CMD:members(playerid)
  814. {
  815.     if (!IsLeader(playerid)) return SendClientMessage(playerid, COLOR_RED,"You're not the leader of an organization");
  816.     new string[60];
  817.     new count = 0;
  818.     SendClientMessage(playerid, COLOR_YELLOW,"Employees online");
  819.     for (new i=0;i<MAX_PLAYERS;i++)
  820.     {
  821.         if (IsPlayerConnected(i))
  822.         {
  823.             if (PlayerOrg[i] == PlayerOrg[playerid] && i != playerid)
  824.             {
  825.                 format(string,sizeof(string),"%s - %s", PlayerName(i), PlayerRank[i]);
  826.                 SendClientMessage(playerid, COLOR_WHITE, string);
  827.                 count++;
  828.             }
  829.         }
  830.     }
  831.  
  832.     if (count == 0)
  833.     {
  834.         SendClientMessage(playerid, COLOR_YELLOW,"None of your employees are online");
  835.     }
  836.     else
  837.     {
  838.         format(string,sizeof(string),"%d member(s) online", count);
  839.         SendClientMessage(playerid, COLOR_WHITE, string);
  840.     }
  841.     return 1;
  842. }
  843.  
  844. CMD:myorg(playerid, params[])
  845. {
  846.     if (PlayerOrg[playerid] == 0) return SendClientMessage(playerid, COLOR_RED,"You are not a member of an organization");
  847.     new string[140];
  848.     format(string,sizeof(string),"{5CB3FF}Organization: {FFFFFF}%s\n{5CB3FF}Leader: {FFFFFF}%s", GetOrgName(PlayerOrg[playerid]), Organization[PlayerOrg[playerid]][Leader]);
  849.     ShowPlayerDialog(playerid, 757, DIALOG_STYLE_MSGBOX, "My organization", string, "Ok", "");
  850.     return 1;
  851. }
  852.  
  853. CMD:orghelp(playerid)
  854. {
  855.     SendClientMessage(playerid, COLOR_YELLOW, "Dynamic Organizations by Jakku");
  856.     SendClientMessage(playerid, COLOR_WHITE, "/orglist || /myorg || /request || /resign || /org || /ochat");
  857.     if (IsPlayerAdmin(playerid)) SendClientMessage(playerid, COLOR_WHITE,"RCON- Admin commands: /setleader");
  858.     if (IsLeader(playerid)) SendClientMessage(playerid, COLOR_WHITE,"Leader commands: /setmember || /kickmember || /setrank || /members || /ovrespawn || /decline");
  859.     return 1;
  860. }
  861.  
  862. stock GetOrgID(name[])
  863. {
  864.     if (strlen(name) <= 0) return 0;
  865.     for (new i=1;i<OrgsCount+1;i++)
  866.     {
  867.         if (strcmp(name,Organization[i][Name],true) == 0) return i;
  868.     }
  869.     return 0;
  870. }
  871.  
  872.  
  873. stock CreateOrgVehicle(org[32], model, Float:x,Float:y,Float:z,Float:rot, clr1,clr2)
  874. {
  875.     if (!DoesOrgExist(org)) return printf("You are attempting to create org. vehicles for an org. which does not exist!");
  876.     new orgid = GetOrgID(org);
  877.     new freeslot = Organization[orgid][VehiclesCreated];
  878.     if (freeslot >= MAX_ORG_VEHICLES) return printf("Error: %s cannot handle more vehicles! Aborted", org);
  879.  
  880.     Organization[orgid][Vehicles][freeslot] = CreateVehicle(model, x,y,z,rot,clr1,clr2,900);
  881.     printf("Added org. vehicle: %d to slot %d for %s",model,freeslot+1, org);
  882.     Organization[orgid][VehiclesCreated]++;
  883.     return 1;
  884. }
  885.  
  886.  
  887. stock IsLeaderOnline(org)
  888. {
  889.     for (new i = 0; i < MAX_PLAYERS; i++)
  890.     {
  891.         if (IsPlayerConnected(i))
  892.         {
  893.             if (PlayerOrg[i] == org && PlayerLeader[i] == 1) return true;
  894.         }
  895.  
  896.     }
  897.     return false;
  898. }
  899.  
  900. stock IsLeader(playerid)
  901. {
  902.     if (PlayerOrg[playerid] != 0 && PlayerLeader[playerid] == 1) return 1;
  903.     return 0;
  904. }
  905.  
  906. stock IsVehicleConnected(vehicleid)
  907. {
  908.     new Float:x1,Float:y1,Float:z1;
  909.     GetVehiclePos(vehicleid,x1,y1,z1);
  910.     if(x1==0.0 && y1==0.0 && z1==0.0)
  911.     {
  912.         return 0;
  913.     }
  914.     return 1;
  915. }
  916.  
  917. stock DoesOrgExist(orgname[32])
  918. {
  919.     for (new i=1;i<OrgsCount+1;i++)
  920.     {
  921.         if (strcmp(Organization[i][Name], orgname, true) == 0) return 1;
  922.     }
  923.     return 0;
  924. }
  925.  
  926. stock CreateOrganizationZone(orgname[32], Float:minx,Float:miny,Float:maxx,Float:maxy, color)
  927. {
  928.     if (!DoesOrgExist(orgname)) return printf("Error: You are attempting to create a gangzone for '%s' which does not exist", orgname);
  929.  
  930.     new orgid = GetOrgID(orgname);
  931.     Organization[orgid][ZonesCreated]++;
  932.     if (Organization[orgid][ZonesCreated] >= MAX_ZONES_PER_ORG) return printf("Error: You are attempting to create more than %d zones for %s", MAX_ZONES_PER_ORG, orgname);
  933.     new id = Organization[orgid][ZonesCreated];
  934.     Organization[orgid][ZoneMinX][id] = minx;
  935.     Organization[orgid][ZoneMinY][id] = miny;
  936.     Organization[orgid][ZoneMaxX][id] = maxx;
  937.     Organization[orgid][ZoneMaxY][id] = maxy;
  938.     Organization[orgid][ZoneColor][id] = hexToDec(color);
  939.     Organization[orgid][Zones][id] = GangZoneCreate(minx, miny, maxx, maxy);
  940.     ZoneCount++;
  941.     return ZoneCount;
  942. }
  943.  
  944.  
  945. stock hexToDec(hex) { new out[11]; format(out, 11, "%i", hex); return strval(out); }
  946.  
  947.  
  948. stock IsPlayerInArea(playerid, Float:MinX, Float:MinY, Float:MaxX, Float:MaxY)
  949. {
  950.     new Float:AX, Float:AY, Float:AZ;
  951.     GetPlayerPos(playerid, AX, AY, AZ);
  952.     if (AX > MinX && AX < MaxX && AY > MinY && AY < MaxY) return true;
  953.     else return false;
  954. }
  955.  
  956.  
  957. stock IsPlayerInOrgZone(playerid, orgname[32])
  958. {
  959.     new orgid = GetOrgID(orgname);
  960.     if (DoesOrgExist(orgname))
  961.     {
  962.         for (new i=1;i<ZoneCount+1;i++)
  963.         {
  964.             if (Organization[orgid][ZoneMinX][i] != 0.0)
  965.             {
  966.                 if (IsPlayerInArea(playerid, Organization[orgid][ZoneMinX][i],Organization[orgid][ZoneMinY][i],Organization[orgid][ZoneMaxX][i],Organization[orgid][ZoneMaxY][i]))
  967.                 {
  968.                     return 1;
  969.                 }
  970.             }
  971.         }
  972.     }
  973.     return 0;
  974. }
  975.  
  976. stock SendClientMessageToOrg(orgname[32], clr, msg[])
  977. {
  978.     if (!DoesOrgExist(orgname)) return 0;
  979.  
  980.     for (new a=0;a<MAX_PLAYERS;a++)
  981.     {
  982.         if (IsPlayerConnected(a))
  983.         {
  984.             if (PlayerOrg[a] == GetOrgID(orgname))
  985.             {
  986.                 SendClientMessage(a, clr, msg);
  987.             }
  988.         }
  989.     }
  990.     return 1;
  991. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement