Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------------------------------------------------------------------
- //=== Include ==================================================================
- //------------------------------------------------------------------------------
- #include <a_samp>
- #include <Pawn.CMD>
- #include <sscanf2>
- //------------------------------------------------------------------------------
- //=== Enum =====================================================================
- //------------------------------------------------------------------------------
- enum fInfo
- {
- FactionMember, FactionLeader, FactionRank,
- FactionPunish, FactionWarn, FactionPoints
- };
- //------------------------------------------------------------------------------
- //=== New ======================================================================
- //------------------------------------------------------------------------------
- new FactionInfo[MAX_PLAYERS][fInfo];
- new DB:Database;
- new String[1024], Query[256], Field[128];
- new Factiune[35], RankFactiune[15];
- new userid, rank, factionid;
- new DBResult:facResult;
- //------------------------------------------------------------------------------
- //=== Init/Exit ================================================================
- //------------------------------------------------------------------------------
- public OnGameModeInit()
- {
- Database = db_open("Database.db");
- strcat(String, "CREATE TABLE IF NOT EXISTS Factions(");
- strcat(String, "Name VARCHAR(24),");
- strcat(String, "Member INTEGER DEFAULT 0 NOT NULL,");
- strcat(String, "Leader INTEGER DEFAULT 0 NOT NULL,");
- strcat(String, "Rank INTEGER DEFAULT 0 NOT NULL,");
- strcat(String, "Punish INTEGER DEFAULT 0 NOT NULL,");
- strcat(String, "Warn INTEGER DEFAULT 0 NOT NULL,");
- strcat(String, "Points INTEGER DEFAULT 0 NOT NULL)");
- db_query(Database, String);
- return (true);
- }
- //------------------------------------------------------------------------------
- public OnGameModeExit()
- {
- db_close(Database);
- return (true);
- }
- main(){}
- //------------------------------------------------------------------------------
- //=== Connect/Disconnect =======================================================
- //------------------------------------------------------------------------------
- public OnPlayerConnect(playerid)
- {
- format(Query, sizeof(Query), "SELECT * FROM Factions WHERE Name = '%q'", DB_Escape(PlayerName(playerid)));
- facResult = db_query(Database, Query);
- if(db_num_rows(facResult))
- {
- db_get_field_assoc(facResult, "Member", Field, 128);
- FactionInfo[playerid][FactionMember] = strval(Field);
- db_get_field_assoc(facResult, "Leader", Field, 128);
- FactionInfo[playerid][FactionLeader] = strval(Field);
- db_get_field_assoc(facResult, "Rank", Field, 128);
- FactionInfo[playerid][FactionRank] = strval(Field);
- db_get_field_assoc(facResult, "Punish", Field, 128);
- FactionInfo[playerid][FactionPunish] = strval(Field);
- db_get_field_assoc(facResult, "Warn", Field, 128);
- FactionInfo[playerid][FactionWarn] = strval(Field);
- db_get_field_assoc(facResult, "Points", Field, 128);
- FactionInfo[playerid][FactionPoints] = strval(Field);
- }
- else
- {
- format(Query, sizeof(Query), "INSERT INTO Factions (Name) VALUES ('%q')", DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, Query));
- FactionInfo[playerid][FactionMember] = 0; FactionInfo[playerid][FactionLeader] = 0;
- FactionInfo[playerid][FactionRank] = 0; FactionInfo[playerid][FactionPoints] = 0;
- FactionInfo[playerid][FactionPunish] = 0; FactionInfo[playerid][FactionWarn] = 0;
- }
- db_free_result(facResult);
- return (true);
- }
- //------------------------------------------------------------------------------
- public OnPlayerDisconnect(playerid, reason)
- {
- SavePlayerFaction(playerid);
- return (true);
- }
- //------------------------------------------------------------------------------
- //=== Spawn ====================================================================
- //------------------------------------------------------------------------------
- public OnPlayerSpawn(playerid)
- {
- if(FactionInfo[playerid][FactionMember] == 1 || FactionInfo[playerid][FactionLeader] == 1)
- {
- GivePlayerWeapon(playerid, 24, 64);
- GivePlayerWeapon(playerid, 3, 1);
- SetPlayerArmour(playerid, 100);
- /*--------------------------------------------------------------------*/
- SetPlayerColor(playerid, 0x2641FEAA);
- SetPlayerSkin(playerid, 280);
- SendClientMessage(playerid, -1, "{ffff00}Info: {ffffff}You are a member from LSPD.");
- /*--------------------------------------------------------------------*/
- SetPlayerInterior(playerid, 6);
- SetPlayerPos(playerid, 246.3295, 66.5572, 1003.6406);
- SetPlayerFacingAngle(playerid, 0);
- return (true);
- }
- if(FactionInfo[playerid][FactionMember] == 2 || FactionInfo[playerid][FactionLeader] == 2)
- {
- GivePlayerWeapon(playerid, 23, 64);
- /*--------------------------------------------------------------------*/
- SetPlayerColor(playerid, 0xFF6347AA);
- SetPlayerSkin(playerid, 274);
- SendClientMessage(playerid, -1, "{ffff00}Info: {ffffff}You are a member from Paramedics.");
- /*--------------------------------------------------------------------*/
- SetPlayerInterior(playerid, 0);
- SetPlayerPos(playerid, 1607.1846, 1818.9738, 10.8203);
- SetPlayerFacingAngle(playerid, 0);
- return (true);
- }
- if(FactionInfo[playerid][FactionMember] == 3 || FactionInfo[playerid][FactionLeader] == 3)
- {
- GivePlayerWeapon(playerid, 24, 64);
- GivePlayerWeapon(playerid, 31, 64);
- /*--------------------------------------------------------------------*/
- SetPlayerColor(playerid, 0x1E519DAA);
- SetPlayerSkin(playerid, 287);
- SendClientMessage(playerid, -1, "{ffff00}Info: {ffffff}You are a member from National Guard.");
- /*--------------------------------------------------------------------*/
- SetPlayerInterior(playerid, 0);
- SetPlayerPos(playerid, 246.6305, 1860.1299, 14.0840);
- SetPlayerFacingAngle(playerid, 0);
- return (true);
- }
- if(FactionInfo[playerid][FactionMember] == 4 || FactionInfo[playerid][FactionLeader] == 4)
- {
- GivePlayerWeapon(playerid, 24, 64);
- GivePlayerWeapon(playerid, 31, 64);
- /*--------------------------------------------------------------------*/
- SetPlayerColor(playerid, 0x2641FEAA);
- SetPlayerSkin(playerid, 286);
- SendClientMessage(playerid, -1, "{ffff00}Info: {ffffff}You are a member from FBI.");
- /*--------------------------------------------------------------------*/
- SetPlayerInterior(playerid, 10);
- SetPlayerPos(playerid, 246.375991, 109.245994, 1003.218750);
- SetPlayerFacingAngle(playerid, 90);
- return (true);
- }
- else if(FactionInfo[playerid][FactionMember] == 0 || FactionInfo[playerid][FactionLeader] == 0)
- {
- SetPlayerPos(playerid, 2306.8252, -1675.4340, 13.9221);
- SetPlayerFacingAngle(playerid, 0);
- SetPlayerSkin(playerid, 217);
- SetPlayerColor(playerid, 0xFFFFFFFF);
- }
- return (true);
- }
- //------------------------------------------------------------------------------
- //=== Commands =================================================================
- //------------------------------------------------------------------------------
- cmd:stats(playerid, params[])
- {
- SavePlayerFaction(playerid);
- if(IsPlayerConnected(playerid))
- {
- if(FactionInfo[playerid][FactionMember] == 1) Factiune = "Los Santos Police Department";
- else if(FactionInfo[playerid][FactionMember] == 0) Factiune = "Civil";
- if(FactionInfo[playerid][FactionMember] == 2) Factiune = "Paramedics";
- else if(FactionInfo[playerid][FactionMember] == 0) Factiune = "Civil";
- if(FactionInfo[playerid][FactionMember] == 3) Factiune = "National Guard";
- else if(FactionInfo[playerid][FactionMember] == 0) Factiune = "Civil";
- if(FactionInfo[playerid][FactionMember] == 4) Factiune = "Federal Bureau of Investigations";
- else if(FactionInfo[playerid][FactionMember] == 0) Factiune = "Civil";
- /*--------------------------------------------------------------------*/
- if(FactionInfo[playerid][FactionRank] == 1) RankFactiune = "New Member";
- else if(FactionInfo[playerid][FactionRank] == 0) RankFactiune = "None";
- if(FactionInfo[playerid][FactionRank] == 2) RankFactiune = "Member";
- else if(FactionInfo[playerid][FactionRank] == 0) RankFactiune = "None";
- if(FactionInfo[playerid][FactionRank] == 3) RankFactiune = "Senior Member";
- else if(FactionInfo[playerid][FactionRank] == 0) RankFactiune = "None";
- if(FactionInfo[playerid][FactionRank] == 4) RankFactiune = "Advisor";
- else if(FactionInfo[playerid][FactionRank] == 0) RankFactiune = "None";
- if(FactionInfo[playerid][FactionRank] == 5) RankFactiune = "Co-Leader";
- else if(FactionInfo[playerid][FactionRank] == 0) RankFactiune = "None";
- if(FactionInfo[playerid][FactionRank] == 6) RankFactiune = "Leader";
- else if(FactionInfo[playerid][FactionRank] == 0) RankFactiune = "None";
- }
- SendClientMessage(playerid, -1, "-----------------------------------------------------------------------");
- format(String, sizeof(String), "%q | Punish: %i | Warn: %i | Points: %i", PlayerName(playerid), FactionInfo[playerid][FactionPunish], FactionInfo[playerid][FactionWarn], FactionInfo[playerid][FactionPoints]);
- SendClientMessage(playerid, -1, String);
- format(String, sizeof(String), "Faction: %q | Rank: %q", Factiune, RankFactiune);
- SendClientMessage(playerid, -1, String);
- SendClientMessage(playerid, -1, "-----------------------------------------------------------------------");
- return (true);
- }
- //------------------------------------------------------------------------------
- cmd:fhelp(playerid, params[])
- {
- SendClientMessage(playerid, -1, "Commands: /finvite | /fkick | /frankup | /setleader");
- return (true);
- }
- //------------------------------------------------------------------------------
- cmd:finvite(playerid, params[])
- {
- if(!FactionInfo[playerid][FactionLeader]) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}You are not leader of this faction!");
- if(sscanf(params, "u", userid)) return SendClientMessage(playerid, -1, "{ffff00}Usage: {ffffff}/finvite <name|playerid>");
- if(playerid == userid) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}You can't invite yourself!");
- if(FactionInfo[userid][FactionMember] != 0 || FactionInfo[userid][FactionLeader] != 0) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}This player is a member of another faction!");
- /*------------------------------------------------------------------------*/
- FactionInfo[userid][FactionMember] = FactionInfo[playerid][FactionLeader];
- FactionInfo[userid][FactionRank] = 1;
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "{00ffff}AdmBot: {ffffff}%q invited you in his faction.", PlayerName(playerid));
- SendClientMessage(userid, -1, String);
- format(String, sizeof(String), "{00ff00}Succes: {ffffff}You invited %q to join in your faction.", PlayerName(userid));
- SendClientMessage(playerid, -1, String);
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "UPDATE Factions SET Member = '%i', Rank = '%i' WHERE Name = '%q'", FactionInfo[userid][FactionMember], FactionInfo[userid][FactionRank], DB_Escape(PlayerName(userid)));
- db_free_result(db_query(Database, String));
- return (true);
- }
- //------------------------------------------------------------------------------
- cmd:fkick(playerid, params[])
- {
- if(!FactionInfo[playerid][FactionLeader]) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}You are not leader of this faction!");
- if(sscanf(params, "u", userid)) return SendClientMessage(playerid, -1, "{ffff00}Usage: {ffffff}/fkick <name|playerid>");
- if(playerid == userid) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}You can't dismiss yourself!");
- if(FactionInfo[userid][FactionMember] != FactionInfo[playerid][FactionLeader]) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}This player is a member of another faction!");
- /*------------------------------------------------------------------------*/
- FactionInfo[userid][FactionMember] = 0;
- FactionInfo[userid][FactionRank] = 0;
- FactionInfo[userid][FactionPunish] = 40;
- FactionInfo[playerid][FactionPoints] = 0;
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "{00ffff}AdmBot: {ffffff}You were kicked out from this faction by %q.", PlayerName(playerid));
- SendClientMessage(userid, -1, String);
- format(String, sizeof(String), "{00ff00}Succes: {ffffff}You kicked out %q from your faction.", PlayerName(userid));
- SendClientMessage(playerid, -1, String);
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "UPDATE Factions SET Member = '%i', Rank = '%i', Punish = '%i', Points = '%i' WHERE Name = '%q'", FactionInfo[playerid][FactionMember], FactionInfo[playerid][FactionRank], FactionInfo[playerid][FactionPunish], FactionInfo[playerid][FactionPoints], DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, String));
- return (true);
- }
- //------------------------------------------------------------------------------
- cmd:frankup(playerid, params[])
- {
- if(!FactionInfo[playerid][FactionLeader]) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}You are not leader of this faction!");
- if(sscanf(params, "ui", userid, rank)) return SendClientMessage(playerid, -1, "{ffff00}Usage: {ffffff}/frankup <name|playerid> <rank>");
- else if(rank < 1 || rank > 6) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}The rank can only be 1 or 6.");
- if(FactionInfo[userid][FactionMember] != FactionInfo[playerid][FactionLeader]) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}This player is a member of another faction!");
- /*------------------------------------------------------------------------*/
- FactionInfo[userid][FactionRank] = rank;
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "{00ffff}AdmBot: {ffffff}%q has made you rank %i.", PlayerName(playerid), rank);
- SendClientMessage(userid, -1, String);
- format(String, sizeof(String), "{00ff00}Succes: {ffffff}You have made %q rank %i.", PlayerName(userid), rank);
- SendClientMessage(playerid, -1, String);
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "UPDATE Factions SET Rank = '%i' WHERE Name = '%q'", FactionInfo[userid][FactionRank], DB_Escape(PlayerName(userid)));
- db_free_result(db_query(Database, String));
- return (true);
- }
- //------------------------------------------------------------------------------
- cmd:setleader(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}You are not a admin!");
- if(sscanf(params, "ui", userid, factionid)) return SendClientMessage(playerid, -1, "{ffff00}Usage: {ffffff}/setleader <name|playerid> <faction>");
- else if(factionid < 1 || factionid > 20) return SendClientMessage(playerid, -1, "{ff0000}Error: {ffffff}The faction can only be 1 or 20.");
- /*------------------------------------------------------------------------*/
- FactionInfo[userid][FactionLeader] = factionid;
- FactionInfo[userid][FactionMember] = factionid;
- FactionInfo[userid][FactionRank] = 6;
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "{00ffff}AdmBot: {ffffff}%q has made you leader for a faction.", PlayerName(playerid));
- SendClientMessage(userid, -1, String);
- format(String, sizeof(String), "{00ff00}Succes: {ffffff}You have made %q leader for a faction.", PlayerName(userid));
- SendClientMessage(playerid, -1, String);
- /*------------------------------------------------------------------------*/
- format(String, sizeof(String), "UPDATE Factions SET Leader = '%i', Member = '%i', Rank = '%i' WHERE Name = '%q'", FactionInfo[userid][FactionLeader], FactionInfo[userid][FactionMember], FactionInfo[userid][FactionRank], DB_Escape(PlayerName(userid)));
- db_free_result(db_query(Database, String));
- return (true);
- }
- //------------------------------------------------------------------------------
- //=== Stock ====================================================================
- //------------------------------------------------------------------------------
- stock SavePlayerFaction(playerid)
- {
- if(IsPlayerConnected(playerid))
- {
- format(Query, sizeof(Query), "UPDATE Factions SET Member = '%i' WHERE Name = '%q'", FactionInfo[playerid][FactionMember], DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, Query));
- format(Query, sizeof(Query), "UPDATE Factions SET Leader = '%i' WHERE Name = '%q'", FactionInfo[playerid][FactionLeader], DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, Query));
- format(Query, sizeof(Query), "UPDATE Factions SET Rank = '%i' WHERE Name = '%q'", FactionInfo[playerid][FactionRank], DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, Query));
- format(Query, sizeof(Query), "UPDATE Factions SET Punish = '%i' WHERE Name = '%q'", FactionInfo[playerid][FactionPunish], DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, Query));
- format(Query, sizeof(Query), "UPDATE Factions SET Warn = '%i' WHERE Name = '%q'", FactionInfo[playerid][FactionWarn], DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, Query));
- format(Query, sizeof(Query), "UPDATE Factions SET Points = '%i' WHERE Name = '%q'", FactionInfo[playerid][FactionPoints], DB_Escape(PlayerName(playerid)));
- db_free_result(db_query(Database, Query));
- }
- }
- //------------------------------------------------------------------------------
- stock PlayerName(playerid)
- {
- new pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
- return (pName);
- }
- //------------------------------------------------------------------------------
- stock DB_Escape(text[])
- {
- new ret[80*2], ch, i, j;
- while((ch = text[i++]) && j < sizeof(ret))
- {
- if(ch == '\'')
- {
- if(j < sizeof(ret) - 2)
- {
- ret[j++] = '\'';
- ret[j++] = '\'';
- }
- }
- else if(j < sizeof(ret))
- {
- ret[j++] = ch;
- }
- else
- {
- j++;
- }
- }
- ret[sizeof(ret) - 1] = '\0';
- return (ret);
- }
- //------------------------------------------------------------------------------
- //=== End of Script ============================================================
- //------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment