Also, hier sind meine mysql und Save-/Loadstock's
stock Connect_To_Database()
{
mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
if(mysql_ping() == 1)
{
print("<-| [MYSQL] Verbindung zur Datenbank wurde erfolgreich hergestellt!");
return true;
}
else
{
print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
print("<-| [MYSQL] Es wird erneut versucht eine Verbindung zur Datenbank herzustellen!");
mysql_connect(SQL_HOST, SQL_USER, SQL_DATA, SQL_PASS);
if(mysql_ping() == 1)
{
print("<-| [MYSQL] Es konnte im 2 Versuch eine Verbindung hergestellt werden!");
return true;
}
else
{
print("<-| [MYSQL] Es konnte keine Verbindung zur Datenbank hergestellt werden!");
print("<-| [MYSQL] Der Server wird nun beendet!");
SendRconCommand("exit");
return true;
}
}
}
stock mysql_CheckAccount(playerid)
{
new Query[128],Name[MAX_PLAYER_NAME],count;
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
mysql_real_escape_string(Name, Name);
format(Query, sizeof(Query), "SELECT * FROM `accounts` WHERE `Name` = '%s'", Name);
mysql_query(Query);
mysql_store_result();
count = mysql_num_rows();
mysql_free_result();
return count;
}
stock CreateAccount(playerid, pass[])
{
new query[256],Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, MAX_PLAYER_NAME);
mysql_real_escape_string(Name,Name);
mysql_real_escape_string(pass,pass);
format(query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Passwort`) VALUES ('%s', '%s')", Name, pass);
mysql_query(query);
return true;
}
stock mysql_ReturnPasswort(Name[])
{
new query[130], Get[130];
mysql_real_escape_string(Name, Name);
format(query, 128, "SELECT `passwort` FROM `accounts` WHERE `Name` = '%s'", Name);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(Get);
mysql_free_result();
return Get;
}
stock mysql_GetString(Table[], Field[], Where[], Is[])
{
new query[128], Get[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(Get);
mysql_free_result();
return Get;
}
stock mysql_GetInt(Table[], Field[], Where[], Is[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
new sqlint = mysql_fetch_int();
mysql_free_result();
return sqlint;
}
stock Float:mysql_GetFloat(Table[], Field[], Where[], Is[])
{
new query[128], Float:sqlfloat;
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Is, Is);
format(query, 128, "SELECT `%s` FROM `%s` WHERE `%s` = '%s'", Field, Table, Where, Is);
mysql_query(query);
mysql_store_result();
mysql_fetch_float(sqlfloat);
mysql_free_result();
return sqlfloat;
}
stock mysql_SetInt(Table[], Field[], To, Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%d' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
stock mysql_SetString(Table[], Field[], To[], Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(To, To);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%s' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
stock mysql_SetFloat(Table[], Field[], Float:To, Where[], Where2[])
{
new query[128];
mysql_real_escape_string(Table, Table);
mysql_real_escape_string(Field, Field);
mysql_real_escape_string(Where, Where);
mysql_real_escape_string(Where2, Where2);
format(query, 128, "UPDATE `%s` SET `%s` = '%f' WHERE `%s` = '%s'", Table, Field, To, Where, Where2);
mysql_query(query);
return true;
}
stock SavePlayer(playerid)
{
if(IsPlayerConnected(playerid) && !IsPlayerNPC(playerid))
{
if(GetPVarInt(playerid,"Eingeloggt") == 1)
{
GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
mysql_SetInt("accounts","Level",GetPlayerScore(playerid),"Name",PlayerInfo[playerid][pName]);
mysql_SetInt("accounts","Geld",GetPlayerMoney(playerid),"Name",PlayerInfo[playerid][pName]);
mysql_SetInt("accounts","Adminlevel",PlayerInfo[playerid][pAdmin],"Name",PlayerInfo[playerid][pName]);
mysql_SetInt("accounts","Supporter",PlayerInfo[playerid][pSup],"Name",PlayerInfo[playerid][pName]);
mysql_SetInt("accounts","Member",PlayerInfo[playerid][pMember],"Name",PlayerInfo[playerid][pName]);
mysql_SetInt("accounts","Leader",PlayerInfo[playerid][pLeader],"Name",PlayerInfo[playerid][pName]);
mysql_SetInt("accounts","Skin",PlayerInfo[playerid][pSkin],"Name",PlayerInfo[playerid][pName]);
print("Spieler erfolgreich gespeichert!");
}
}
}
stock LoadPlayer(playerid)
{
if(IsPlayerConnected(playerid) && !IsPlayerNPC(playerid))
{
if(GetPVarInt(playerid,"Eingeloggt") == 1)
{
GetPlayerName(playerid, PlayerInfo[playerid][pName], MAX_PLAYER_NAME);
GivePlayerMoney(playerid,mysql_GetInt("accounts", "Geld", "Name", PlayerInfo[playerid][pName]));
SetPlayerScore(playerid, mysql_GetInt("accounts", "Level", "Name", PlayerInfo[playerid][pName]));
PlayerInfo[playerid][pAdmin] = mysql_GetInt("accounts", "AdminLevel", "Name", PlayerInfo[playerid][pName]);
PlayerInfo[playerid][pSup] = mysql_GetInt("accounts","Supporter","Name",PlayerInfo[playerid][pName]);
PlayerInfo[playerid][pMember] = mysql_GetInt("accounts","Member","Name",PlayerInfo[playerid][pName]);
PlayerInfo[playerid][pLeader] = mysql_GetInt("accounts","Leader","Name",PlayerInfo[playerid][pName]);
PlayerInfo[playerid][pSkin] = mysql_GetInt("accounts", "Skin", "Name", PlayerInfo[playerid][pName]);
print("Spieler erfolgreich geladen!");
}
}
return 1;
}