my sql help - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: my sql help (
/showthread.php?tid=298619)
my sql help -
manchestera - 21.11.2011
Ok i have a problem where everytime a player logs on it resets it therestats but i can fix this but i need to know how to load the saved info from the database but im not sure how to any help would be great.
Код:
public OnPlayerConnect(playerid)
{
new
lStr[70];
format(lStr, sizeof(lStr), ""#CBLUE"Player: "#CDGREEN"%s(%d) "#CBLUE"has joined the server!", pName(playerid), playerid);
SendClientMessageToAll(-1, lStr);
ResetPVars(playerid);
InitConnection(playerid);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
new
dStr[70];
format(dStr, sizeof(dStr), ""#CBLUE"Player: "#CDGREEN"%s(%d) "#CBLUE"has left the server!", pName(playerid), playerid);
SendClientMessageToAll(-1, dStr);
GetPlayerPos(playerid, PVar[playerid][pLastX], PVar[playerid][pLastY], PVar[playerid][pLastZ]);
SavePInfo(playerid);
return 1;
}
This is how the players info is saved think u might need this.
Код:
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, `score` = %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),
PVar[playerid][pScore],
pName(playerid));
mysql_query(Query);
mysql_free_result();
return 1;
}
else return 0;
}
Many thanks.
Re: my sql help -
JaTochNietDan - 21.11.2011
What have you tried so far to select the information from the database? Can you show us?
I suggest you go and have a look at some tutorials in the
Scripting Tutorials section, such as this tutorial:
https://sampforum.blast.hk/showthread.php?tid=159785
In short, you need to learn how to make use of the SELECT syntax in SQL and then use mysql_fetch_row to store the result in a string, then split the result. Alternatively if you can use mysql_fetch_row_field to select column data and store it individually.
Re: my sql help -
manchestera - 22.11.2011
Thanksalot i will have ago with this tut and see if i get any where