Help Needed +REP
#1

Can some convert this to sql for me so that it save player hunger with name in a sql table "hunger" of database "wgrp"

Код:
public OnPlayerDisconnect(playerid, reason)
{
 	new file[256],n[MAX_PLAYER_NAME];
    GetPlayerName(playerid,n,MAX_PLAYER_NAME);
    format(file,sizeof(file),"Stats/%s.txt",n);
    PInfo[playerid][Hunger] = floatround(GetProgressBarValue(hungry[playerid]));
    if(dini_Exists(file))
    {
        dini_IntSet(file,"Hunger",floatround(GetProgressBarValue(hungry[playerid])));
        return 1;
    }
	return 1;
}
public OnPlayerSpawn(playerid)
{
    new file[256],n[MAX_PLAYER_NAME];
    GetPlayerName(playerid,n,MAX_PLAYER_NAME);
    format(file,sizeof(file),"Stats/%s.txt",n);
    if(!dini_Exists(file))
    {
        dini_Create(file);
    	dini_IntSet(file,"Hunger",100);
	}
Reply
#2

Are you sure this is what you want? Creating a new table "hunger" means that when you load data from DB to server you will have to join the results from multiple tables. Don't get me wrong, this is not bad when you have a different table for other than player stats, such as houses or vehicles or whatever. Hunger is something related to the player, so it should be a new field in your players table.
Reply
#3

right i can add a field for it but how can i save player's hunger in it
Reply
#4

pawn Код:
format(query, sizeof(query), "UPDATE playersTable SET hungerField = %d WHERE playerID = %d", PInfo[playerid][Hunger], <player database id>);
mysql_tquery(connectionHandle, query, "", "");
//connectionHandle is returned by mysql_connect function
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_connect
Replace "<player database id> with the variable that stores player database ID, like PInfo[playerid][pID] or something.
Reply
#5

Thanks Man +REP
Reply
#6

How do i read the query can you please add mysql in my given code in 1st post.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)