21.11.2016, 19:11
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";
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.