loadplayer
#1

How can i convert LoadPlayer(playerid) to mysql?
See the code below

pawn Код:
LoadPlayer(playerid){
    new playername[MAX_PLAYER_NAME],file[256];
    GetPlayerName(playerid, playername, sizeof(playername));
    format(file,256,"/ladmin/users/%s.sav",udb_encode(playername));
    if(udb_Exists(PlayerName2(playerid))) {
        PlayerInfo[playerid][name] = playername;
        PlayerInfo[playerid][pcash] = (dUserINT(PlayerName2(playerid)).("Money"));
        PlayerInfo[playerid][bank] = (dUserINT(PlayerName2(playerid)).("Bank"));
        PlayerInfo[playerid][bowner] = (dUserINT(PlayerName2(playerid)).("bowner"));
        PlayerInfo[playerid][bowned] = (dUserINT(PlayerName2(playerid)).("bowned"));
        PlayerInfo[playerid][weed] = (dUserINT(PlayerName2(playerid)).("weed"));
        PlayerInfo[playerid][condoms] = (dUserINT(PlayerName2(playerid)).("Condoms"));
        PlayerInfo[playerid][inalcatraz] = (dUserINT(PlayerName2(playerid)).("inalcatraz"));
I just wanted to know whether it is 'UPDATE' 'SELECT' or "INSERT INTO" ?
Which one of these when loading something?
Reply
#2

its SELECT

if you use R7 of mysql (by blueg) , load like this

pawn Код:
mysql_function_query(dbHandle, "SELECT * FROM `YOUR_TABLE_NAME` WHERE name = '%s'", true, "LoadPlayer", "s", Playername...);
pawn Код:
forward LoadPlayer(name[]);
public LoadPlayer(name[])
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(!rows)
    {
        //The account doesnt exist
    }
    else
    {
        //The account exist , use cache_get_field_content  to load
    }
}
Reply
#3

But i'm using LoadPlayer as stock
Reply
#4

what version of mysql are you using
Reply
#5

R6
4char
Reply
#6

This is just an example how to use this
pawn Код:
stock LoadPlayer(playerid) {
    new query[300], pname[24], savingstring[20];
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT weed FROM YOUR_TABLE_NAME WHERE user = '%s'", pname);
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(savingstring, "weed"); PlayerInfo[playerid][weed] = strval(savingstring);
    }
    mysql_free_result();
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)