[FilterScript] Faction system SQLite [0.3.7]
#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


Messages In This Thread
Faction system SQLite [0.3.7] - by GeoDanny - 21.11.2016, 18:03
Re: Faction system SQLite [0.3.7] - by RyderX - 21.11.2016, 18:28
Re: Faction system SQLite [0.3.7] - by Konstantinos - 21.11.2016, 19:11
Re: Faction system SQLite [0.3.7] - by GeoDanny - 21.11.2016, 19:47
Re: Faction system SQLite [0.3.7] - by Yuri8 - 30.11.2016, 11:57
Respuesta: Faction system SQLite [0.3.7] - by Gles - 30.11.2016, 17:53
Respuesta: Faction system SQLite [0.3.7] - by Eloy - 27.01.2017, 06:24

Forum Jump:


Users browsing this thread: 2 Guest(s)