MySQL help
#1

How would I save a players score? I'm not sure on where to add it?

pawn Код:
mysql_fetch_field_row(szReturn, "Score", connectionHandle);
            playerVariables[extraid][pScore] = strval(szReturn);
Reply
#2

If you're using MySQL you should do something like that:
pawn Код:
new
    playername[MAX_PLAYER_NAME],
    fquery[128];
GetPlayerName(playerid, playername, sizeof(playername));
format(fquery, sizeof(fquery), "UPDATE `users` SET `score` = '%d' WHERE `username` = '%s'", GetPlayerScore(playerid), playername);
mysql_query(fquery);
Reply
#3

If you take a look at this script, it demonstrates loading and saving. You're welcome to rip the code straight from the script if you want to.
Reply
#4

Thanks calgon but that is what I already am using..

The code I said above, would that save the score already?

EDIT: I copied some other stuff inside the script for the saving and loading but I think you gotta use GetPlayerScore?
Reply
#5

If you're using that now, then you can just edit the query in the saveAccount function to:

pawn Код:
format(szQuery, sizeof(szQuery), "UPDATE players SET Health = '%f', Armour = '%f', PosX = '%f', PosY = '%f', PosZ = '%f', PosR = '%f'", playerVariables[playerid][pHealth], playerVariables[playerid][pArmour], playerVariables[playerid][pPos][0], playerVariables[playerid][pPos][1], playerVariables[playerid][pPos][2], playerVariables[playerid][pPos][3]);
    format(szQuery, sizeof(szQuery), "%s, Interior = %d, Skin = %d, Score = %d WHERE ID = %d", szQuery, playerVariables[playerid][pInterior], playerVariables[playerid][pSkin], GetPlayerScore(playerid), playerVariables[playerid][pDBID]);
As you can see, 'score' is at the bottom just before the 'WHERE' clause. Score will now save by using GetPlayerScore().

You might want to use SetPlayerScore() to set the score once it's loaded though, like this:

pawn Код:
mysql_fetch_field_row(szReturn, "Score", connectionHandle);
playerVariables[extraid][pScore] = strval(szReturn);
SetPlayerScore(extraid, playerVariables[extraid][pScore]);
Otherwise, the code for loading should work - but you need to add the field to the table in MySQL, see this or many other guides on the web for how to do that.

You can post in the release thread for the script in the future if you have any more questions similar to this. I'm a lot more likely to answer them faster.
Reply
#6

Thanks cos in the saving function I used playerVariables (I dunno why) but thanks for helping me out.
Reply
#7

That's the best thing to do normally, but considering that you're only going to use the score in the saving function, you might as well just use the function and forget about the player variable.

You shouldn't do that for money though, considering this.
Reply
#8

Alright, thanks.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)