25.01.2017, 13:28
Okay Mr Pro scripter i will tell you what exactly is optmisation is.It is not actually reducing no of lines in a script.It how you hacks with compiler and machine.Also overdoing an optmisation is also bad programming do the optmisation where ever necessary and never should it compromise it with readability.
Lets take a tiny portion of your script.
Now this
You are creating 3 variables to hold the player name in 3 different situations thats just fucking stupidness.
if i were you i will do create an global array to hold the player name,if its thats case i will add it in player enum
Also take a look @ here
what the hell? You know what you actually doing ? Your code never going to work even. The code will not allow any player to login if one of the player failed the attempt.Because you are using a static variable whose copy will be created only once in the stack.
Now you can use char arrays instead of plain arrays which will much more memory efficient.
i can go even more and you can get more chilled.
Needless to say 1 star from me.Keep trying.....
Lets take a tiny portion of your script.
Code:
public OnPlayerConnect(playerid) { new query[50], pname[MAX_PLAYERS_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); // gets player name on connect mysql_format(MHandle, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e'", pname); mysql_tquery(MHandle, query, "OnPlayerAccountCheck", "i", playerid); // in this step the server checks if player registered or not using the callback up ^^ return 1; }
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { switch(dialogid) { case Login: { static loginattemp, buf[129], pname[MAX_PLAYERS_NAME]; GetPlayerName(playerid, pname, sizeof(pname)); if(!response) Kick(playerid); if(isnull(PlayerInfo[playerid][Password])) // checks if password correctly loaded else check below :) { SendClientMessage(playerid, -1,"[MYSQL]: Sorry, we have some problems on database right now, Come back later !"); Kick(playerid); print("[MYSQL]: Password Value 'PlayerInfo[playerid][Password]' not correctly loaded! please check OnPlayerAccountCheck callback"); print("[SA-MP Server]: Server shutdown.."); SendRconCommand("exit"); return 1; } WP_Hash(buf, sizeof(buf), inputtext); if(!strcmp(buf, PlayerInfo[playerid][Password], true)) // comparing the passwords (database & entrerd) { new query[70], Cache:GetCache; mysql_format(MHandle, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", pname); GetCache = mysql_query(MHandle, query); // Importing data after beigning sure he is the right user new rows; cache_get_row_count(rows); if(rows == 1) { cache_get_value_name_int(0, "Admin", PlayerInfo[playerid][Admin]); cache_get_value_name_int(0, "Deaths", PlayerInfo[playerid][Deaths]); cache_get_value_name_int(0, "Kills", PlayerInfo[playerid][Kills]); } SendClientMessage(playerid, -1, "You have successfully logged in."); cache_delete(GetCache); } else // if he entred an wrrong password { if(loginattemp == 3) return Kick(playerid); // if he entred the same wrrong password 3 times he got kicked SendClientMessage(playerid, -1, "You have specified an incorrect password!"); ShowPlayerDialog(playerid, Login, DIALOG_STYLE_PASSWORD, "Login", "Welcome Back !\nWe miss you here !\nPlease fill you password here to get stats back!", "Login", "Cancel"); loginattemp++; // adding +1 for every attemp } } case Register: { if(!response) return Kick(playerid); if(strlen(inputtext) < 5) { SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters."); return ShowPlayerDialog(playerid, Register, DIALOG_STYLE_PASSWORD, "Register", "Welcome to our server! \nthis account not register at the database \nPlease fill a password to register your account", "Register", "Cancel"); } new query[287], playername[MAX_PLAYER_NAME], playerip[16], buf[129] ; WP_Hash(buf, sizeof(buf), inputtext); // hashing password using Whirlpool engine GetPlayerName(playerid, playername, sizeof(playername)); GetPlayerIp(playerid, playerip, sizeof(playerip)); mysql_format(MHandle, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`,`Deaths`, `Kills`) VALUES ('%e', '%e', '%e', 0, 0, 0)", playername, buf, playerip); mysql_query(MHandle, query); // here inserting the player account in the database as a registered player } } return 0; }
if i were you i will do create an global array to hold the player name,if its thats case i will add it in player enum
Also take a look @ here
Code:
static loginattemp
Now you can use char arrays instead of plain arrays which will much more memory efficient.
Code:
array_name[size char];
Needless to say 1 star from me.Keep trying.....