20.02.2011, 15:14
Okay so this MYSQL thing is so complicated.
So, looking at this "mountain" of codes, i really can't figure out how to add 1 more field(i did in the MYSQL table), so much coding..
And don't get me wrong, i don't want someone to just paste me the right code, i want to learn how to do it.So can someone please point me the right steps in doing it ?
Thanks.
pawn Code:
public OnPlayerConnect
ResetPVars(playerid);
InitConnection(playerid);
public OnPlayerDisconnect
SavePInfo(playerid);
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case REGISTER:
{
if(!response)
{
format(Msg, sizeof(Msg), ""#CBLUE"Player: "#CORANGE"%s(%d) "#CBLUE"has been kicked - Reason: Not registering!", pName(playerid), playerid);
SendClientMessageToAll(COLOR_GREY, Msg);
Kick(playerid);
}
else
{
if(!strlen(inputtext)) DialogInput(playerid, REGISTER, ""#CCADET"Account Registration", ""CYELLOW"You must enter a password below to continue!", "Register", "Leave");
new
Query[100],
EscPass[30],
EscName[MAX_PLAYER_NAME];
mysql_real_escape_string(pName(playerid), EscName);
mysql_real_escape_string(inputtext, EscPass);
format(Query, sizeof(Query), "INSERT INTO `playerinfo` (`user`, `password`) VALUES ('%s', '%s')", EscName, EscPass);
mysql_query(Query);
// Player has registered
SendClientMessage(playerid, COLOR_CADETBLUE, "You are now registered!");
GivePlayerMoney(playerid, 5000);
SetPVarInt(playerid, "LoggedIN", 1); // I use this for cross script
}
}
case LOGIN:
{
if(!response)
{
format(Msg, sizeof(Msg), ""#CBLUE"Player: "#CORANGE"%s(%d) "#CBLUE"has been kicked - Reason: Not loggin in!", pName(playerid), playerid);
SendClientMessageToAll(COLOR_GREY, Msg);
Kick(playerid);
}
else
{
if(!strlen(inputtext)) DialogInput(playerid, LOGIN, ""#CCADET"Account Login", ""#CYELLOW"You must enter a password below to continue!", "Login", "Leave");
new
EscPass[38],
Query[128];
mysql_real_escape_string(inputtext, EscPass);
format(Query, sizeof(Query), "SELECT * FROM `playerinfo` WHERE `user` = '%s' AND `password` = '%s'", pName(playerid), EscPass);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() > 0)
{
LoadPlayerInfo(playerid);
SetPVarInt(playerid, "LoggedIN", 1);
// Player Has logged in
SendClientMessage(playerid, LIGHTBLUE2, "SERVER: Welcome, You successfully logged in."),
SendClientMessage(playerid, orange, "Enjoy your stay here, press left shift to spawn.");
}
else
{
SendClientMessage(playerid, COLOR_RED, "You have entered an incorrect password, try again!");
DialogInput(playerid, LOGIN, ""#CCADET"Account Login", ""#CYELLOW"You have 3 chances to enter a correct password..", "Login", "Leave");
}
}
}
}
return 1;
}
stock LoadPlayerInfo(iPlayer)
{
new
Query[700];
if(mysql_fetch_row(Query))
{
sscanf(Query, "e<p<|>s[24]s[35]ddddfffd>", PVar[iPlayer]); // Remember to update this if you add more info...
mysql_free_result();
}
return 1;
}
stock ResetPVars(playerid)
{
PVar[playerid][pLevel] = 0;
PVar[playerid][pKills] = 0;
PVar[playerid][pDeaths] = 0;
PVar[playerid][pMoney] = 0;
PVar[playerid][pLastX] = 0.0;
PVar[playerid][pLastY] = 0.0;
PVar[playerid][pLastZ] = 0.0;
PVar[playerid][pInt] = 0;
}
stock InitConnection(playerid)
{
new
Query[90],
EscName[MAX_PLAYER_NAME];
mysql_real_escape_string(pName(playerid), EscName);
format(Query, sizeof(Query), "SELECT * FROM `playerinfo` WHERE `user` = '%s'", EscName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
format(Msg, sizeof(Msg), ""#CYELLOW"Welcome Back: "#CORANGE"%s(%d)\n"#CYELLOW"Please enter your password below to log onto your account..:", pName(playerid), playerid);
DialogInput(playerid, LOGIN, ""#CCADET"Account Login", Msg, "Login", "Leave");
}
else
{
format(Msg, sizeof(Msg), ""#CYELLOW"Hello: "#CORANGE"%s(%d)\n"#CYELLOW"This account is not registered! Enter a password below to continue..:", pName(playerid), playerid);
DialogInput(playerid, REGISTER, ""#CCADET"Account Registration", Msg, "Register", "Leave");
}
mysql_free_result();
}
stock SavePInfo(playerid)
{
if(GetPVarInt(playerid, "LoggedIN") == 1)
{
new Query[600];
format(Query, sizeof(Query), "UPDATE `playerinfo` SET `kills` = %d, `deaths` = %d, `money` = %d, `Level` = %d, `Last Pos X` = %f, `Last Pos Y` = %f, `Last Pos Z` = %f, `Interior` = %d WHERE `user` = '%s'", // Also remember to update this...
PVar[playerid][pKills],
PVar[playerid][pDeaths],
GetPlayerMoney(playerid),
PVar[playerid][pLevel],
PVar[playerid][pLastX],
PVar[playerid][pLastY],
PVar[playerid][pLastZ],
GetPlayerInterior(playerid),
pName(playerid));
mysql_query(Query);
mysql_free_result();
return 1;
}
else return 0;
}
And don't get me wrong, i don't want someone to just paste me the right code, i want to learn how to do it.So can someone please point me the right steps in doing it ?
Thanks.