03.11.2015, 06:21
- How can this work if you don\'t specify the type of field your are going to make in the database\'s table:
pawn Code:stock LoadDatabase()
{
new query[350];
database = db_open(USER_DATABASE_PATH);
format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS `%s` (`%s`, `%s`, `%s`, `%s`, `%s`)",
TABLE_USERS,
USER_NAME,
USER_PASSWORD,
USER_SCORE,
USER_CASH,
USER_ADMIN_LEVEL);
db_query(database, query);
} - You realize that format is very much slower than strcat. So why using format here if you can do that with strcat.
This:
pawn Code:new string[256];
format(string, sizeof(string), "{FFFFFF}Welcome, {FF0000}%s{FFFFFF}!
", PlayerName(playerid));
strcat(string, "You must register to play here.");
Can be:
pawn Code:strcat(string, "{FFFFFF}Welcome, {FF0000}");
strcat(string, PlayerName(playerid));
strcat(string, "{FFFFFF}!
");
strcat(string, "You must register to play here."); - If you are using latest SAMP version i.e. SAMP 0.3.7 R2-1, then you can directly get int and float fields without declaring arrays ad using strval/floatstr.
This
pawn Code:db_get_field_assoc(result, USER_CASH, field, sizeof(field));
SetPlayerMoney(playerid, strval(field));
Can be:
pawn Code:SetPlayerMoney(playerid, db_get_field_assoc_int(return, USER_CASH)); - Also making your own DB_Escape isn\'t require, you can directly do that by the new specifier "%q" in format.
- And, you should always free the result when not required anymore, using db_free_result. You haven\'t done that at some parts of your script.
- No PRIMARY KEY, your queries check the rows according to username and password which is very very slow than checking for Row ids.