Advertisement
Private200

[SCRIPT] Dynamic Faction System [SQL]

May 4th, 2016
1,174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 26.20 KB | None | 0 0
  1. #include <a_samp>
  2. #include <easydb2>
  3. #include <zcmd>
  4. #include <sscanf2>
  5. #include <dialogs>
  6. #include <streamer>
  7.  
  8. /*======== Database structure ========
  9.  
  10. Main table - factions
  11.  
  12. Table name: Factions
  13. Table structure:
  14. 1. Faction name - String
  15. 2. Faction type - integer
  16. 3. Faction locker coordinations - Split in X/Y/Z coords - Float
  17. 4. Creation date
  18. 5. Faction members limit
  19.  
  20. ======== End Of Database structure ========*/
  21.  
  22. /*======== Database components ========*/
  23.  
  24. new FactionTable;
  25. new PlayerTable;
  26.  
  27. /*======== Other components ========*/
  28.  
  29. // Global string for skins
  30.  
  31. new sString[1000];
  32.  
  33. // SKIN & WEAPON CONFIGURATIONS
  34.  
  35. enum FactionWeapons {
  36.     wid,
  37.     weaponid,
  38.     wammo,
  39.     wep_name[36]
  40. }
  41.  
  42. enum FactionSkins {
  43.     sid,
  44.     skinID,
  45.     skinName[36],
  46.     skinGender[10]
  47. }
  48.  
  49. new LawSkins[][FactionSkins] =
  50. {
  51.     {0, 284, "LSPD", "Male"},
  52.     {1, 285, "LSPD", "Male"}
  53. };
  54.  
  55. new FireSkins[][FactionSkins] =
  56. {
  57.     {0, 274, "Fire", "Male"},
  58.     {1, 308, "Fire", "Female"}
  59. };
  60.  
  61. new GovSkins[][FactionSkins] =
  62. {
  63.     {0, 165, "Gov", "Male"},
  64.     {1, 211, "Gov", "Female"}
  65. };
  66.  
  67. new LawWeaps[][FactionWeapons] =
  68. {
  69.     {0, 3, 1, "Nightstick"},
  70.     {1, 24, 100, "Desert Eagle"},
  71.     {2, 25, 100, "Shotgun"},
  72.     {3, 29, 200, "MP5"},
  73.     {4, 31, 300, "M4"},
  74.     {5, 34, 50, "Sniper"}
  75. };
  76.  
  77. new FireWeaps[][FactionWeapons] =
  78. {
  79.     {0, 3, 1, "Nightstick"},
  80.     {1, 42, 100, "Fire Extinguisher"},
  81.     {2, 43, 100, "Camera"}
  82. };
  83.  
  84. new GovWeaps[][FactionWeapons] =
  85. {
  86.     {0, 3, 1, "Nightstick"},
  87.     {1, 24, 100, "Desert Eagle"}
  88. };
  89.  
  90. // FACTION TYPE CONFIGURATION
  91.  
  92. #define LAW 1
  93. #define FIRE 2
  94. #define GOV 3
  95.  
  96. // DEBUG_MODE ACTIVATION - COMMENT IF YOU DO NOT WANT DEBUGGING
  97.  
  98. #define DEBUG_MODE
  99.  
  100. #define MAX_FACTIONS 10
  101. #define FACTION_RANKS 10
  102. #define MAX_FACTION_RANK_NAME 36
  103.  
  104. enum FactionComponents
  105. {
  106.     fID,
  107.     dbID,
  108.     fName[36],
  109.     fType,
  110.     Float:fX,
  111.     Float:fY,
  112.     Float:fZ,
  113.     date[36],
  114.     fMembers,
  115.     Text3D:fLabel,
  116.     fLimit
  117. }
  118.  
  119. new FactionInfo[MAX_FACTIONS][FactionComponents];
  120. new FactionRanks[MAX_FACTIONS][FACTION_RANKS][MAX_FACTION_RANK_NAME];
  121.  
  122. enum PlayerInformation
  123. {
  124.     pID,
  125.     pName[MAX_PLAYER_NAME],
  126.     pFaction,
  127.     pRank
  128. }
  129.  
  130. new PlayerInfo[MAX_PLAYERS][PlayerInformation];
  131.  
  132. /*======== Functions ========*/
  133.  
  134. stock WeaponToModel(wepid)
  135. {
  136.      switch(wepid)
  137.      {
  138.          case 1: return 331;
  139.          case 2: return 333;
  140.          case 3: return 334;
  141.          case 4: return 335;
  142.          case 5: return 336;
  143.          case 6: return 337;
  144.          case 7: return 338;
  145.          case 8: return 339;
  146.          case 9: return 341;
  147.          case 10: return 321;
  148.          case 11: return 322;
  149.          case 12: return 323;
  150.          case 13: return 324;
  151.          case 14: return 325;
  152.          case 15: return 326;
  153.          case 16: return 342;
  154.          case 17: return 343;
  155.          case 18: return 344;
  156.          case 22: return 346;
  157.          case 23: return 347;
  158.          case 24: return 348;
  159.          case 25: return 349;
  160.          case 26: return 350;
  161.          case 27: return 351;
  162.          case 28: return 352;
  163.          case 29: return 353;
  164.          case 30: return 355;
  165.          case 31: return 356;
  166.          case 32: return 372;
  167.          case 33: return 357;
  168.          case 34: return 358;
  169.          case 35: return 359;
  170.          case 36: return 360;
  171.          case 37: return 361;
  172.          case 38: return 362;
  173.          case 39: return 363;
  174.          case 40: return 364;
  175.          case 41: return 365;
  176.          case 42: return 366;
  177.          case 43: return 367;
  178.          case 44: return 368;
  179.          case 45: return 369;
  180.          case 46: return 371;
  181.      }
  182.      return 0;
  183. }
  184.  
  185. stock ReturnFactionSkin(playerid)
  186. {
  187.     new facID = PlayerInfo[playerid][pFaction];
  188.     new _temp[100];
  189.  
  190.     if(FactionInfo[facID][fType] == LAW)
  191.     {
  192.         sString = "";
  193.         for(new i; i < sizeof LawSkins; i ++)
  194.         {
  195.  
  196.             format(_temp, sizeof _temp, "%d\n%s (%s)\n", LawSkins[i][skinID], LawSkins[i][skinName], LawSkins[i][skinGender]);
  197.             strcat(sString, _temp, sizeof sString);
  198.         }
  199.     }
  200.     else if(FactionInfo[facID][fType] == FIRE)
  201.     {
  202.         sString = "";
  203.         for(new i; i < sizeof LawSkins; i ++)
  204.         {
  205.             format(_temp, sizeof _temp, "%d\n%s (%s)\n", FireSkins[i][skinID], FireSkins[i][skinName], FireSkins[i][skinGender]);
  206.             strcat(sString, _temp, sizeof sString);
  207.         }
  208.     }
  209.     else if(FactionInfo[facID][fType] == GOV)
  210.     {
  211.         sString = "";
  212.         for(new i; i < sizeof LawSkins; i ++)
  213.         {
  214.             format(_temp, sizeof _temp, "%d\n%s (%s)\n", GovSkins[i][skinID], GovSkins[i][skinName], GovSkins[i][skinGender]);
  215.             strcat(sString, _temp, sizeof sString);
  216.         }
  217.     }
  218.     return sString;
  219. }
  220.  
  221. stock ReturnFactionWeapons(playerid)
  222. {
  223.     new facID = PlayerInfo[playerid][pFaction];
  224.     new _temp[100];
  225.  
  226.     if(FactionInfo[facID][fType] == LAW)
  227.     {
  228.         sString = "";
  229.         for(new i; i < sizeof LawWeaps; i ++)
  230.         {
  231.  
  232.             format(_temp, sizeof _temp, "%d\n%s (Ammo: %d)\n", WeaponToModel(LawWeaps[i][weaponid]), LawWeaps[i][wep_name], LawWeaps[i][wammo]);
  233.             strcat(sString, _temp, sizeof sString);
  234.         }
  235.     }
  236.     else if(FactionInfo[facID][fType] == FIRE)
  237.     {
  238.         sString = "";
  239.         for(new i; i < sizeof FireWeaps; i ++)
  240.         {
  241.             format(_temp, sizeof _temp, "%d\n%s (%s)\n", WeaponToModel(FireWeaps[i][weaponid]), FireWeaps[i][wep_name], FireWeaps[i][wammo]);
  242.             strcat(sString, _temp, sizeof sString);
  243.         }
  244.     }
  245.     else if(FactionInfo[facID][fType] == GOV)
  246.     {
  247.         sString = "";
  248.         for(new i; i < sizeof GovWeaps; i ++)
  249.         {
  250.             format(_temp, sizeof _temp, "%d\n%s (%s)\n", WeaponToModel(GovWeaps[i][weaponid]), GovWeaps[i][wep_name], GovWeaps[i][wammo]);
  251.             strcat(sString, _temp, sizeof sString);
  252.         }
  253.     }
  254.     return sString;
  255. }
  256. /*
  257. stock ReturnGovSkins()
  258. {
  259.     sString = "";
  260.     for(new i; i < sizeof LawSkins; i ++)
  261.     {
  262.         new _temp[100];
  263.         format(_temp, sizeof _temp, "%d\n%s (%s)\n", GovSkins[i][skinID], GovSkins[i][skinName], GovSkins[i][skinGender]);
  264.         strcat(sString, _temp, sizeof sString);
  265.     }
  266.     return sString;
  267. }
  268.  
  269. stock ReturnFireSkins()
  270. {
  271.     sString = "";
  272.     for(new i; i < sizeof LawSkins; i ++)
  273.     {
  274.         new _temp[100];
  275.         format(_temp, sizeof _temp, "%d\n%s (%s)\n", FireSkins[i][skinID], FireSkins[i][skinName], FireSkins[i][skinGender]);
  276.         strcat(sString, _temp, sizeof sString);
  277.     }
  278.     return sString;
  279. }
  280.  
  281. stock ReturnLawSkins()
  282. {
  283.     sString = "";
  284.     for(new i; i < sizeof LawSkins; i ++)
  285.     {
  286.         new _temp[100];
  287.         format(_temp, sizeof _temp, "%d\n%s (%s)\n", LawSkins[i][skinID], LawSkins[i][skinName], LawSkins[i][skinGender]);
  288.         strcat(sString, _temp, sizeof sString);
  289.     }
  290.     return sString;
  291. }
  292. */
  293. stock GiveFactionSkin(playerid, skinid)
  294. {
  295.     new facID = PlayerInfo[playerid][pFaction];
  296.     if(FactionInfo[facID][fType] == LAW)
  297.     {
  298.         SetPlayerSkin(playerid, LawSkins[skinid][skinID]);
  299.     }
  300.     else if(FactionInfo[facID][fType] == FIRE)
  301.     {
  302.         SetPlayerSkin(playerid, FireSkins[skinid][skinID]);
  303.     }
  304.     else if(FactionInfo[facID][fType] == GOV)
  305.     {
  306.         SetPlayerSkin(playerid, GovSkins[skinid][skinID]);
  307.     }
  308.     return 1;
  309. }
  310.  
  311. stock GiveFactionWeapon(playerid, wepid)
  312. {
  313.     new facID = PlayerInfo[playerid][pFaction];
  314.     if(FactionInfo[facID][fType] == LAW)
  315.     {
  316.         GivePlayerWeapon(playerid, LawWeaps[wepid][weaponid], LawWeaps[wepid][wammo]);
  317.     }
  318.     else if(FactionInfo[facID][fType] == FIRE)
  319.     {
  320.         GivePlayerWeapon(playerid, FireWeaps[wepid][weaponid], FireWeaps[wepid][wammo]);
  321.     }
  322.     else if(FactionInfo[facID][fType] == GOV)
  323.     {
  324.         GivePlayerWeapon(playerid, GovWeaps[wepid][weaponid], GovWeaps[wepid][wammo]);
  325.     }
  326.     return 1;
  327. }
  328.  
  329. stock ReturnDBID(facid)
  330. {
  331.     if(IsValidFactionID(facid)) return FactionInfo[facid][dbID];
  332.     return 0;
  333. }
  334.  
  335. stock ReturnFactionID(dbid)
  336. {
  337.     for(new i; i < MAX_FACTIONS; i ++)
  338.     {
  339.         if(FactionInfo[i][dbID] == dbid)
  340.         {
  341.             return i;
  342.         }
  343.     }
  344.     return 0;
  345. }
  346.  
  347. stock GetRankName(factionid, rank)
  348. {
  349.     new _rname[36];
  350.     if(IsValidFactionID(factionid))
  351.     {
  352.         if(rank < FACTION_RANKS)
  353.         {
  354.             format(_rname, sizeof _rname, FactionRanks[factionid][rank]);
  355.         }
  356.     }
  357.     return _rname;
  358. }
  359.  
  360. stock IsPlayerInAFaction(playerid)
  361. {
  362.     if(PlayerInfo[playerid][pFaction] != -1)
  363.     {
  364.         return 1;
  365.     }
  366.     else return 0;
  367. }
  368.  
  369. stock IsValidFactionID(id)
  370. {
  371.     if(FactionInfo[id][dbID] != 0)
  372.     {
  373.         return 1;
  374.     }
  375.     else return 0;
  376. }
  377.  
  378. stock CheckFactionsDB()
  379. {
  380.     // Assigning our table the ID for further usage
  381.  
  382.     FactionTable = DB::VerifyTable("Factions", "id");
  383.  
  384.     // Checking if table data exists (Factions table)
  385.  
  386.     DB::VerifyColumn(FactionTable, "FactionName", DB::TYPE_STRING, "N/A");
  387.     DB::VerifyColumn(FactionTable, "fType", DB::TYPE_STRING, "0");
  388.     DB::VerifyColumn(FactionTable, "LockerX", DB::TYPE_FLOAT, 0);
  389.     DB::VerifyColumn(FactionTable, "LockerY", DB::TYPE_FLOAT, 0);
  390.     DB::VerifyColumn(FactionTable, "LockerZ", DB::TYPE_FLOAT, 0);
  391.     DB::VerifyColumn(FactionTable, "CreationDate", DB::TYPE_STRING, "");
  392.     DB::VerifyColumn(FactionTable, "FactionLimit", DB::TYPE_STRING, "10");
  393.     DB::VerifyColumn(FactionTable, "FactionMembers", DB::TYPE_STRING, "0");
  394.     DB::VerifyColumn(FactionTable, "Reference", DB::TYPE_STRING, "Reference");
  395.  
  396.     new string[35], _loopcount = 0;
  397.  
  398.     for( new i ; i < FACTION_RANKS; i ++)
  399.     {
  400.         format(string, sizeof string, "FactionRank%d", _loopcount);
  401.         DB::VerifyColumn(FactionTable, string, DB::TYPE_STRING, "");
  402.         _loopcount++;
  403.     }
  404.     return 1;
  405. }
  406.  
  407. stock CheckPlayersDB()
  408. {
  409.     PlayerTable = DB::VerifyTable("Players", "id");
  410.  
  411.     DB::VerifyColumn(PlayerTable, "PlayerName", DB::TYPE_STRING, "null");
  412.     DB::VerifyColumn(PlayerTable, "FactionID", DB::TYPE_STRING, "-1");
  413.     DB::VerifyColumn(PlayerTable, "PlayerRank", DB::TYPE_STRING, "-1");
  414.     return 1;
  415. }
  416.  
  417. stock ResetPlayerVariables(playerid)
  418. {
  419.     PlayerInfo[playerid][pID] = -1;
  420.     format(PlayerInfo[playerid][pName], MAX_PLAYER_NAME, "");
  421.     PlayerInfo[playerid][pFaction] = -1;
  422.     PlayerInfo[playerid][pRank] = -1;
  423.     return 1;
  424. }
  425.  
  426. stock SavePlayer(playerid)
  427. {
  428.     DB::MultiSet(PlayerTable, PlayerInfo[playerid][pID], "sii",
  429.     "PlayerName", PlayerInfo[playerid][pName],
  430.     "FactionID", FactionInfo[PlayerInfo[playerid][pFaction]][dbID],
  431.     "PlayerRank", PlayerInfo[playerid][pRank]);
  432.     return 1;
  433. }
  434.  
  435. stock CreatePlayer(playerid)
  436. {
  437.     new playername[MAX_PLAYER_NAME];
  438.     GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
  439.  
  440.     DB::CreateRow(PlayerTable, "PlayerName", playername);
  441.  
  442.     new pid = DB::RetrieveKey(PlayerTable, _, _, "PlayerName", playername);
  443.  
  444.     DB::SetIntEntry(PlayerTable, pid, "FactionID", 0);
  445.     DB::SetIntEntry(PlayerTable, pid, "PlayerRank", -1);
  446.  
  447.     #if defined DEBUG_MODE
  448.         printf("[PLAYER CREATION] %s with ID %d", playername, pid);
  449.     #endif
  450.     return 1;
  451. }
  452.  
  453. stock CheckPlayer(playerid)
  454. {
  455.     new playername[MAX_PLAYER_NAME];
  456.     GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
  457.  
  458.     new id = DB::RetrieveKey(PlayerTable, _, _, "PlayerName", playername);
  459.  
  460.     if(id != DB::INVALID_KEY) LoadPlayer(playerid);
  461.     else CreatePlayer(playerid);
  462.     return 1;
  463. }
  464.  
  465. stock LoadPlayer(playerid)
  466. {
  467.     new playername[MAX_PLAYER_NAME];
  468.     GetPlayerName(playerid, playername, MAX_PLAYER_NAME);
  469.  
  470.     new id = DB::RetrieveKey(PlayerTable, _, _, "PlayerName", playername);
  471.  
  472.     DB::MultiGet(PlayerTable, id, "isii",
  473.     "id", PlayerInfo[playerid][pID],
  474.     "PlayerName", PlayerInfo[playerid][pName],
  475.     "FactionID", PlayerInfo[playerid][pFaction],
  476.     "PlayerRank", PlayerInfo[playerid][pRank]);
  477.  
  478.     PlayerInfo[playerid][pFaction] = ReturnFactionID(PlayerInfo[playerid][pFaction]);
  479.  
  480.     #if defined DEBUG_MODE
  481.         printf("[PLAYER LOADED] %s with Faction ID [%d] and Player Rank [%d]", PlayerInfo[playerid][pName], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pRank]);
  482.     #endif
  483.     return 1;
  484. }
  485.  
  486. stock ReturnLastKey()
  487. {
  488.     return DB::GetRowsPoolSize(FactionTable);
  489. }
  490.  
  491. stock GetAvailableRankID(factionid)
  492. {
  493.     for(new i; i < FACTION_RANKS; i++)
  494.     {
  495.         if(isnull(FactionRanks[factionid][i]))
  496.         {
  497.             return i;
  498.         }
  499.     }
  500.     return 0;
  501. }
  502.  
  503. stock GetAvailableFactionID()
  504. {
  505.     new id;
  506.     for(new i; i < MAX_FACTIONS; i++)
  507.     {
  508.         if(FactionInfo[i][dbID] == 0)
  509.         {
  510.             id = i;
  511.             break;
  512.         }
  513.     }
  514.     return id;
  515. }
  516.  
  517. stock UnloadFactions()
  518. {
  519.     new count;
  520.  
  521.     for(new i=0; i < MAX_FACTIONS;i ++)
  522.     {
  523.         if(FactionInfo[i][dbID] != 0)
  524.         {
  525.             count++;
  526.             FactionInfo[i][dbID] = 0;
  527.             DestroyDynamic3DTextLabel(FactionInfo[i][fLabel]);
  528.         }
  529.     }
  530.     printf("%d factions cleared!", count);
  531.     return 1;
  532. }
  533.  
  534. stock LoadFactions()
  535. {
  536.     new FactionDBID[MAX_FACTIONS], string[45];
  537.     new factionID, fcount;
  538.  
  539.     UnloadFactions();
  540.  
  541.     DB::RetrieveKey(FactionTable, FactionDBID, _, "Reference", "Reference");
  542.  
  543.     for(new i=0; i < MAX_FACTIONS; i++)
  544.     {
  545.         if(FactionDBID[i] != DB::INVALID_KEY)
  546.         {
  547.             new franks = 0;
  548.  
  549.             factionID = GetAvailableFactionID();
  550.  
  551.             fcount++;
  552.  
  553.             FactionInfo[factionID][fID] = factionID;
  554.             FactionInfo[factionID][dbID] = DB::GetIntEntry(FactionTable, FactionDBID[i], "id");
  555.             FactionInfo[factionID][fLimit] = DB::GetIntEntry(FactionTable, FactionDBID[i], "FactionLimit");
  556.             FactionInfo[factionID][fX] = DB::GetFloatEntry(FactionTable, FactionDBID[i], "LockerX");
  557.             FactionInfo[factionID][fY] = DB::GetFloatEntry(FactionTable, FactionDBID[i], "LockerY");
  558.             FactionInfo[factionID][fZ] = DB::GetFloatEntry(FactionTable, FactionDBID[i], "LockerZ");
  559.  
  560.             FactionInfo[factionID][fType] = DB::GetIntEntry(FactionTable, FactionDBID[i], "fType");
  561.  
  562.             FactionInfo[factionID][fMembers] = DB::GetIntEntry(FactionTable, FactionDBID[i], "FactionMembers");
  563.  
  564.             DB::GetStringEntry(FactionTable, FactionDBID[i], "FactionName", FactionInfo[factionID][fName], 36);
  565.             DB::GetStringEntry(FactionTable, FactionDBID[i], "CreationDate", FactionInfo[factionID][date], 36);
  566.  
  567.             for(new y; y < FACTION_RANKS; y++)
  568.             {
  569.                 format(string, sizeof string, "FactionRank%d", franks);
  570.                 DB::GetStringEntry(FactionTable, FactionDBID[i], string, FactionRanks[factionID][y], MAX_FACTION_RANK_NAME);
  571.  
  572.                 #if defined DEBUG_MODE
  573.                     printf("Faction rank loaded: %s under slot %d", FactionRanks[factionID][y], franks);
  574.                 #endif
  575.                 franks++;
  576.             }
  577.             #if defined DEBUG_MODE
  578.                 printf("__________________________________________________________");
  579.                 printf("[FACTION LOADED] %s has been created under in-game id of %d and DB ID of %d", FactionInfo[factionID][fName], factionID, FactionInfo[factionID][dbID]);
  580.             #endif
  581.  
  582.             format(string, sizeof string, "[%s lockers]", FactionInfo[factionID][fName]);
  583.             FactionInfo[factionID][fLabel] = CreateDynamic3DTextLabel(string, -1, FactionInfo[factionID][fX], FactionInfo[factionID][fY], FactionInfo[factionID][fZ], 30, INVALID_PLAYER_ID, INVALID_VEHICLE_ID);
  584.         }
  585.     }
  586.     printf("__________________________________________________________");
  587.     printf("[FACTION LOAD] A total of %d faction/s has been loaded!", fcount);
  588.     return 1;
  589. }
  590.  
  591. stock SaveFaction(facid)
  592. {
  593.     new _temp, _stemp[40], string[45];
  594.     new dbid = FactionInfo[facid][dbID];
  595.  
  596.     DestroyDynamic3DTextLabel(FactionInfo[facid][fLabel]);
  597.    
  598.     DB::MultiSet(FactionTable, dbid, "sifffsi",
  599.     "FactionName", FactionInfo[facid][fName],
  600.     "fType", FactionInfo[facid][fType],
  601.     "LockerX", FactionInfo[facid][fX],
  602.     "LockerY", FactionInfo[facid][fY],
  603.     "LockerZ", FactionInfo[facid][fZ],
  604.     "CreationDate", FactionInfo[facid][date],
  605.     "FactionMembers", FactionInfo[facid][fMembers]);
  606.  
  607.     for(new i; i < FACTION_RANKS;i++)
  608.     {
  609.         format(_stemp, sizeof _stemp, "FactionRank%d", _temp);
  610.         DB::SetStringEntry(FactionTable, dbid, _stemp, FactionRanks[facid][i]);
  611.  
  612.         _temp++;
  613.     }
  614.    
  615.     format(string, sizeof string, "[%s lockers]", FactionInfo[facid][fName]);
  616.     FactionInfo[facid][fLabel] = CreateDynamic3DTextLabel(string, -1, FactionInfo[facid][fX], FactionInfo[facid][fY], FactionInfo[facid][fZ], 30, INVALID_PLAYER_ID, INVALID_VEHICLE_ID);
  617.    
  618.     return 1;
  619. }
  620.  
  621. stock CreateFaction(fname[], Float:PlayerPosX, Float:PlayerPosY, Float:PlayerPosZ, ftype)
  622. {
  623.     DB::CreateRow(FactionTable, "FactionName", fname);
  624.  
  625.     new year, month, day;
  626.  
  627.     getdate(year, month, day);
  628.  
  629.     new fcID = GetAvailableFactionID();
  630.  
  631.     FactionInfo[fcID][dbID] = ReturnLastKey();
  632.     FactionInfo[fcID][fID] = fcID;
  633.  
  634.     FactionInfo[fcID][fType] = ftype;
  635.     FactionInfo[fcID][fX] = PlayerPosX;
  636.     FactionInfo[fcID][fY] = PlayerPosY;
  637.     FactionInfo[fcID][fZ] = PlayerPosZ;
  638.  
  639.     new cdate[30];
  640.     format(cdate, sizeof cdate, "%02d/%02d/%d", day, month, year);
  641.  
  642.     DB::SetLastIntEntry(FactionTable, "fType", ftype, "Reference");
  643.     DB::SetLastFloatEntry(FactionTable, "LockerX", PlayerPosX, "Reference");
  644.     DB::SetLastFloatEntry(FactionTable, "LockerY", PlayerPosY, "Reference");
  645.     DB::SetLastFloatEntry(FactionTable, "LockerZ", PlayerPosZ, "Reference");
  646.     DB::SetLastStringEntry(FactionTable, "CreationDate", cdate, "Reference");
  647.  
  648.     LoadFactions();
  649.  
  650.     #if defined DEBUG_MODE
  651.         printf("[FACTION CREATION] %s has been created today (%s). [IG ID: %d | SQL ID: %d]", fname, cdate, fcID, FactionInfo[fcID][dbID]);
  652.     #endif
  653.     return 1;
  654. }
  655.  
  656. /*======== Commands ========*/
  657.  
  658. CMD:factions(playerid, params[])
  659. {
  660.     new fString[2000], _temp[200];
  661.  
  662.     for(new i; i < MAX_FACTIONS ; i++)
  663.     {
  664.         if(IsValidFactionID(i))
  665.         {
  666.             format(_temp, sizeof _temp, "[%s]\t%s [%d/%d]\n", FactionInfo[i][date], FactionInfo[i][fName], FactionInfo[i][fMembers], FactionInfo[i][fLimit]);
  667.             strcat(fString, _temp, sizeof fString);
  668.         }
  669.     }
  670.     ShowPlayerDialog(playerid, 3252, DIALOG_STYLE_LIST, "Factions", fString, "Okay", "Close");
  671.     return 1;
  672. }
  673.  
  674. CMD:reloadfacs(playerid, params[])
  675. {
  676.     if(IsPlayerAdmin(playerid))
  677.     {
  678.         LoadFactions();
  679.     }
  680.     return 1;
  681. }
  682.  
  683. CMD:setfacranks(playerid, params[])
  684. {
  685.     new frank, rname[MAX_FACTION_RANK_NAME];
  686.  
  687.     if(IsValidFactionID(PlayerInfo[playerid][pFaction]) && PlayerInfo[playerid][pRank] == FACTION_RANKS - 1)
  688.     {
  689.         if(sscanf(params, "ds[36]", frank, rname)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX] {FFFFFF}/setfacranks [rankid] [rank name]");
  690.         if(frank < FACTION_RANKS)
  691.         {
  692.             format(FactionRanks[PlayerInfo[playerid][pFaction]][frank], sizeof rname, rname);
  693.         }
  694.         SaveFaction(PlayerInfo[playerid][pFaction]);
  695.     }
  696.     return 1;
  697. }
  698.  
  699. CMD:savefactions(playerid, params[])
  700. {
  701.     if(IsPlayerAdmin(playerid))
  702.     {
  703.         for(new i; i < MAX_FACTIONS ; i ++)
  704.         {
  705.             if(IsValidFactionID(i))
  706.             {
  707.                 SaveFaction(i);
  708.             }
  709.         }
  710.     }
  711.     return 1;
  712. }
  713.  
  714. CMD:lockers(playerid, params[])
  715. {
  716.     new input[20], facID = PlayerInfo[playerid][pFaction];
  717.  
  718.     if(IsValidFactionID(facID) && IsPlayerInAFaction(playerid))
  719.     {
  720.         if(IsPlayerInRangeOfPoint(playerid, 2, FactionInfo[facID][fX], FactionInfo[facID][fY], FactionInfo[facID][fZ]))
  721.         {
  722.             if(sscanf(params, "s[20]", input)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX] {FFFFFF}/lockers [weapons / clothes / heal]");
  723.  
  724.             if(!strcmp(input, "clothes", true))
  725.             {
  726.                 ShowPlayerDialog(playerid, 7777, DIALOG_STYLE_PREVMODEL_LIST, "Clothes menu", ReturnFactionSkin(playerid), "Wear", "Close");
  727.             }
  728.             else if(!strcmp(input, "heal", true))
  729.             {
  730.                 SetPlayerHealth(playerid, 100);
  731.                 SetPlayerArmour(playerid, 100);
  732.             }
  733.             else if(!strcmp(input, "weapons", true))
  734.             {
  735.                 ShowPlayerDialog(playerid, 7778, DIALOG_STYLE_PREVMODEL_LIST, "Weapons menu", ReturnFactionWeapons(playerid), "Wear", "Close");
  736.             }
  737.             else SendClientMessage(playerid, -1, "{FF0000}Invalid parameter. Please put a valid option!");
  738.         }
  739.         else SendClientMessage(playerid, -1, "{FF0000}You are not in range of your faction locker.");
  740.     }
  741.     else SendClientMessage(playerid, -1, "{FF0000}You are not in a valid faction.");
  742.     return 1;
  743. }
  744.  
  745. CMD:fkick(playerid, params[])
  746. {
  747.     if(PlayerInfo[playerid][pRank] == FACTION_RANKS - 1 && IsValidFactionID(PlayerInfo[playerid][pFaction]) && IsPlayerInAFaction(playerid))
  748.     {
  749.         new targetid;
  750.  
  751.         if(sscanf(params, "d", targetid)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX]: {FFFFFF}/fkick [targetid]");
  752.  
  753.         if(IsPlayerConnected(targetid) && PlayerInfo[targetid][pFaction] == PlayerInfo[playerid][pFaction])
  754.         {
  755.             PlayerInfo[targetid][pRank] = -1;
  756.             PlayerInfo[targetid][pFaction] = -1;
  757.             FactionInfo[PlayerInfo[playerid][pFaction]][fMembers]--;
  758.             SendClientMessage(playerid, -1, "{B3B3B3}* You have been kicked from your faction.");
  759.             SaveFaction(PlayerInfo[playerid][pFaction]);
  760.         }
  761.         else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Player is not connected or is not in the same faction as you!");
  762.     }
  763.     else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}You are not in a valid faction!");
  764.  
  765.     return 1;
  766. }
  767.  
  768. CMD:finvite(playerid, params[])
  769. {
  770.     new string[128];
  771.  
  772.     if(PlayerInfo[playerid][pRank] == FACTION_RANKS - 1 && IsValidFactionID(PlayerInfo[playerid][pFaction]) && IsPlayerInAFaction(playerid))
  773.     {
  774.         new targetid;
  775.         if(sscanf(params, "d", targetid)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX]: {FFFFFF}/finvite [targetid]");
  776.  
  777.         if(IsPlayerConnected(targetid) && PlayerInfo[targetid][pFaction] != -1)
  778.         {
  779.             new facID = PlayerInfo[playerid][pFaction];
  780.  
  781.             if(FactionInfo[facID][fMembers] < FactionInfo[facID][fLimit])
  782.             {
  783.                 PlayerInfo[targetid][pRank] = 0;
  784.                 PlayerInfo[targetid][pFaction] = facID;
  785.                 FactionInfo[facID][fMembers]++;
  786.                 format(string, sizeof string, "{B3B3B3}* You have been invited to %s. Current rank: %s", FactionInfo[facID][fName], GetRankName(facID, 0));
  787.                 SendClientMessage(playerid, -1, string);
  788.                 SaveFaction(facID);
  789.             }
  790.             else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Players limit exceed!");
  791.         }
  792.         else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Player is not connected or is already in a faction!");
  793.     }
  794.     else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}You are not in a valid faction!");
  795.  
  796.     return 1;
  797. }
  798.  
  799. CMD:updateflockers(playerid, params[])
  800. {
  801.     if(IsPlayerAdmin(playerid))
  802.     {
  803.         new factionid;
  804.  
  805.         if(sscanf(params, "d", factionid)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX]: {FFFFFF}/updateflockers [factionid]");
  806.  
  807.         if(IsValidFactionID(factionid))
  808.         {
  809.             new Float:CPos[3];
  810.            
  811.             GetPlayerPos(playerid, CPos[0], CPos[1], CPos[2]);
  812.            
  813.             FactionInfo[factionid][fX] = CPos[0];
  814.             FactionInfo[factionid][fY] = CPos[1];
  815.             FactionInfo[factionid][fZ] = CPos[2];
  816.            
  817.             SendClientMessage(playerid, -1, "{B3B3B3}* Faction lockers have been updated and changed to your current location.");
  818.  
  819.             SaveFaction(factionid);
  820.         }
  821.         else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Invalid faction ID");
  822.     }
  823.     return 1;
  824. }
  825.  
  826. CMD:setflimit(playerid, params[])
  827. {
  828.     if(IsPlayerAdmin(playerid))
  829.     {
  830.         new factionid, limit, string[128];
  831.  
  832.         if(sscanf(params, "dd", factionid, limit)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX]: {FFFFFF}/setflimit [factionid] [limit]");
  833.  
  834.         if(IsValidFactionID(factionid))
  835.         {
  836.             FactionInfo[factionid][fLimit] = limit;
  837.            
  838.             format(string, sizeof string, "{B3B3B3}* You have been changed %s's faction slot limit to %d.", FactionInfo[factionid][fName], limit);
  839.             SendClientMessage(playerid, -1, string);
  840.  
  841.             SaveFaction(factionid);
  842.         }
  843.         else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Invalid faction ID");
  844.     }
  845.     return 1;
  846. }
  847.  
  848. CMD:setfaction(playerid, params[])
  849. {
  850.     if(IsPlayerAdmin(playerid))
  851.     {
  852.         new targetid, factionid, rank, string[128];
  853.  
  854.         if(sscanf(params, "ddd", targetid, factionid, rank)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX]: {FFFFFF}/setfaction [targetid] [factionid] [rank]");
  855.  
  856.         if(IsValidFactionID(factionid) && rank < FACTION_RANKS)
  857.         {
  858.             if(FactionInfo[factionid][fMembers] < FactionInfo[factionid][fLimit])
  859.             {
  860.                 if(PlayerInfo[targetid][pFaction] != -1) FactionInfo[PlayerInfo[playerid][pFaction]][fMembers]--;
  861.                
  862.                 PlayerInfo[targetid][pRank] = rank;
  863.                 PlayerInfo[targetid][pFaction] = factionid;
  864.                 FactionInfo[factionid][fMembers]++;
  865.                 format(string, sizeof string, "{B3B3B3}* You have been invited to %s. Current rank: %s", FactionInfo[factionid][fName], GetRankName(factionid, rank));
  866.                 SendClientMessage(playerid, -1, string);
  867.                 SaveFaction(factionid);
  868.             }
  869.             else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Players limit exceed!");
  870.         }
  871.         else SendClientMessage(playerid, -1, "{FF0000}[ERROR] {FFFFFF}Invalid faction ID");
  872.     }
  873.     return 1;
  874. }
  875.  
  876. CMD:setrank(playerid, params[])
  877. {
  878.     new targetid, rank, string[128];
  879.  
  880.     if(PlayerInfo[playerid][pRank] == FACTION_RANKS-1)
  881.     {
  882.         if(sscanf(params, "dd", targetid, rank)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX]: {FFFFFF}/setfaction [targetid] [rank]");
  883.  
  884.         if(PlayerInfo[playerid][pFaction] == PlayerInfo[targetid][pFaction])
  885.         {
  886.             PlayerInfo[targetid][pRank] = rank;
  887.             format(string, sizeof string, "{B3B3B3}* You have had your rank changed to: %s", GetRankName(PlayerInfo[playerid][pFaction], rank));
  888.             SendClientMessage(playerid, -1, string);
  889.         }
  890.     }
  891.     return 1;
  892. }
  893.  
  894. CMD:createfaction(playerid, params[])
  895. {
  896.     if(IsPlayerAdmin(playerid))
  897.     {
  898.         new fname[36], type, Float:PlayerPos[3];
  899.  
  900.         if(sscanf(params, "ds[36]", type, fname)) return SendClientMessage(playerid, -1, "{FF0000}[SYNTAX]: {FFFFFF}/createfaction [type] [faction name]");
  901.  
  902.         GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
  903.  
  904.         CreateFaction(fname, PlayerPos[0], PlayerPos[1], PlayerPos[2], type);
  905.     }
  906.     else SendClientMessage(playerid, -1, "{FF0000}You do not have access to this command.");
  907.     return 1;
  908. }
  909.  
  910. public OnFilterScriptInit()
  911. {
  912.     // Loading the database
  913.  
  914.     DB::Open("Factions.db");
  915.  
  916.     CheckFactionsDB();
  917.     CheckPlayersDB();
  918.  
  919.     LoadFactions();
  920.     print("• Dynamic Faction FilterScript status: LOADED •");
  921.     print("• _______ CREATOR: ____Private200____________ •");
  922.     print("• ________PLEASE_DO_NOT_REMOVE_CREDITS_______ •");
  923.     return 1;
  924. }
  925.  
  926. public OnFilterScriptExit()
  927. {
  928.     print("• Dynamic Faction FilterScript status: UNLOADED •");
  929.  
  930.     for(new i; i < MAX_PLAYERS; i ++)
  931.     {
  932.         if(IsPlayerConnected(i))
  933.         {
  934.             SavePlayer(i);
  935.             ResetPlayerVariables(i);
  936.         }
  937.     }
  938.  
  939.     return 1;
  940. }
  941.  
  942. public OnPlayerConnect(playerid)
  943. {
  944.     ResetPlayerVariables(playerid);
  945.     CheckPlayer(playerid);
  946.     return 1;
  947. }
  948.  
  949. public OnPlayerDisconnect(playerid)
  950. {
  951.     SavePlayer(playerid);
  952.     ResetPlayerVariables(playerid);
  953.     return 1;
  954. }
  955.  
  956. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  957. {
  958.     if(dialogid == 7777)
  959.     {
  960.         if(response)
  961.         {
  962.             GiveFactionSkin(playerid, listitem);
  963.         }
  964.         return 1;
  965.     }
  966.     if(dialogid == 7778)
  967.     {
  968.         if(response)
  969.         {
  970.             GiveFactionWeapon(playerid, listitem);
  971.         }
  972.         return 1;
  973.     }
  974.     return 1;
  975. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement