[FilterScript] Faction system SQLite [0.3.7]
#1

Faction system SQLite [0.3.7]
Introduction:
Hi all! This is my first public Filterscript. Is a simple faction system for a RPG server.
Hence, this script will use a SQLite database, so all details are saved in (Database.db).
I want to improve this system, if I have time.

Features:
1. Fully working saving and loading system.
2. SQLite saving system. (I know more wanted is mysql...)
3. Than 3 commands for faction leader, for moment.
4. Than 1 command for administrator.

Initial Release v1.0:
1. You can invite a player in your faction or kick a player from your faction.
2. You can set Punish points for a player which left the faction.
3. When a member carry out the mission will receive an activity point.
4. With a chosen number of activity points, you can set him a rank.

For future version:
• I want to add more commands for faction leader.
• I want to make a faction cars with restriction.
• I want to make more commands for faction members.
• I want to add the Activity system.
• I want to make more, someday...

Bugs:
» I have found no bugs at the moment, if there is please leave a comment so I can fix it.

Commands:
» /finvite - You can invite a player in your faction.
» /fkick - You can kick a player from your faction.
» /frankup - You can set a rank for a player from your faction.
» /setleader - [rcon] You can make a leader for a faction.

Screenshots:
» Faction commands: http://imgur.com/2lS52Ru
» Set Leader: http://imgur.com/v1WgGWD
» Set Rank: http://imgur.com/d2J7KHH
» Database: http://imgur.com/S26HrpV

Download:
• Solidfiles: https://www.solidfiles.com/v/4AnmmD8Zd8dRA [v1.0]
• Pastebin: http://pastebin.com/GCrFhuc6 [v1.0]
• MediaFire: http://www.mediafire.com/file/lggxwr...2/Factions.pwn [v1.0]
Reply
#2

Cool Keep it up, if it's this Your First FilterScript So it's Very Cool Good job REP+!
Reply
#3

If you get the time to update the script, I want to point few things out:
  • Avoid global strings if you can. Creating the table for example doesn't need to be stored anywhere (as long as the table is not very big) you can do:
    pawn Код:
    db_query(Database,  "CREATE TABLE IF NOT EXISTS Factions(" \
                            "Name VARCHAR(24)," \
                            "Member INTEGER DEFAULT 0 NOT NULL," \
                            "Leader INTEGER DEFAULT 0 NOT NULL," \
                            "Rank INTEGER DEFAULT 0 NOT NULL," \
                            "Punish INTEGER DEFAULT 0 NOT NULL," \
                            "Warn INTEGER DEFAULT 0 NOT NULL," \
                            "Points INTEGER DEFAULT 0 NOT NULL)");
  • Set Name as UNIQUE key.
  • %q specifier escapes the string so DB_Escape is no longer needed.
  • We've got new functions as well such db_get_field_assoc_int so we won't have to store as string and use strval to convert it.
  • Don't use IsPlayerConnected in commands.
  • In this part, you check if it is equal to 0 many times:
    pawn Код:
    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";
    A switch statement is also recommended:
    pawn Код:
    switch (FactionInfo[playerid][FactionMember])
    {
        case 0: Factiune = "Civil";
        case 1: Factiune = "Los Santos Police Department";
        case 2: Factiune = "Paramedics";
        case 3: Factiune = "National Guard";
        case 4: Factiune = "Federal Bureau of Investigations";
    }
    /*--------------------------------------------------------------------*/
    switch (FactionInfo[playerid][FactionRank])
    {
        case 0: RankFactiune = "None";
        case 1: RankFactiune = "New Member";
        case 2: RankFactiune = "Member";
        case 3: RankFactiune = "Senior Member";
        case 4: RankFactiune = "Advisor";
        case 5: RankFactiune = "Co-Leader";
        case 6: RankFactiune = "Leader";
    }
  • You don't need to escape everything even in client messages. You can simply use %s specifier for such cases.
  • You don't need to free the result if you execute UPDATE, DELETE or INSERT (without auto increment) queries.
  • In SavePlayerFaction function, you send 6 queries when you know that some of those values haven't changed. Since you update them directly when some of them change, you can skip them.
Sorry if the post is too long, the script is good!
Reply
#4

Quote:
Originally Posted by RyderX
Посмотреть сообщение
Cool Keep it up, if it's this Your First FilterScript So it's Very Cool Good job REP+!
Thank you!

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
If you get the time to update the script, I want to point few things out:
  • Avoid global strings if you can. Creating the table for example doesn't need to be stored anywhere (as long as the table is not very big) you can do:
    pawn Код:
    db_query(Database,  "CREATE TABLE IF NOT EXISTS Factions(" \
                            "Name VARCHAR(24)," \
                            "Member INTEGER DEFAULT 0 NOT NULL," \
                            "Leader INTEGER DEFAULT 0 NOT NULL," \
                            "Rank INTEGER DEFAULT 0 NOT NULL," \
                            "Punish INTEGER DEFAULT 0 NOT NULL," \
                            "Warn INTEGER DEFAULT 0 NOT NULL," \
                            "Points INTEGER DEFAULT 0 NOT NULL)");
  • Set Name as UNIQUE key.
  • %q specifier escapes the string so DB_Escape is no longer needed.
  • We've got new functions as well such db_get_field_assoc_int so we won't have to store as string and use strval to convert it.
  • Don't use IsPlayerConnected in commands.
  • In this part, you check if it is equal to 0 many times:
    pawn Код:
    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";
    A switch statement is also recommended:
    pawn Код:
    switch (FactionInfo[playerid][FactionMember])
    {
        case 0: Factiune = "Civil";
        case 1: Factiune = "Los Santos Police Department";
        case 2: Factiune = "Paramedics";
        case 3: Factiune = "National Guard";
        case 4: Factiune = "Federal Bureau of Investigations";
    }
    /*--------------------------------------------------------------------*/
    switch (FactionInfo[playerid][FactionRank])
    {
        case 0: RankFactiune = "None";
        case 1: RankFactiune = "New Member";
        case 2: RankFactiune = "Member";
        case 3: RankFactiune = "Senior Member";
        case 4: RankFactiune = "Advisor";
        case 5: RankFactiune = "Co-Leader";
        case 6: RankFactiune = "Leader";
    }
  • You don't need to escape everything even in client messages. You can simply use %s specifier for such cases.
  • You don't need to free the result if you execute UPDATE, DELETE or INSERT (without auto increment) queries.
  • In SavePlayerFaction function, you send 6 queries when you know that some of those values haven't changed. Since you update them directly when some of them change, you can skip them.
Sorry if the post is too long, the script is good!
Thank you! In next version I will fix everything.
Reply
#5

Salut vecine, La Mulți Ani de 1Dec., ai +1
Reply
#6

Nice Job men!
Reply
#7

and if want differents ranks name in factions 1 and differents in faction 2 how make?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)