SA-MP Forums Archive
Help Needed +REP - 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: Help Needed +REP (/showthread.php?tid=562009)



Help Needed +REP - hamzajaved780 - 06.02.2015

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);
	}



Re: Help Needed +REP - HazardouS - 06.02.2015

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.


Re: Help Needed +REP - hamzajaved780 - 06.02.2015

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


Re: Help Needed +REP - HazardouS - 06.02.2015

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.


Re: Help Needed +REP - hamzajaved780 - 06.02.2015

Thanks Man +REP


Re: Help Needed +REP - hamzajaved780 - 06.02.2015

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