Problems with saving money. (Y_Ini)
#1

Hello!

So, I have added money feature for the server, so that players could buy weapons for money, not for EXP points, for EXP points they buy classes.

There is such thing, when you made it to evacuation point, you don't recieve 100$, but it does not show in /stats, it is still "Cash: 0" and I opened the user account file, but there is added 100$ and when I connected and spawned, my money instantly increases up to 100,000 and some other weird stuff is happening..

I will provide you the code and please tell if something is wrong:

PHP код:
enum playerinfo
{
    
pSpawned,
    
pPassword[129],
    
pCash,
    
pXP,
    
pKills,
    
pHeads,
    
pDeaths,
    
pRank,
    
pEvac,
    
pAdminLevel,
    
pAdminDuty,
    
pBanned,
    
BannedIP[22],
    
pVipLevel,
    
pHour,
    
pMin,
    
pSec,
    
pMapsPlayed,
    
pCoins,
    
pLogged,
    
pWarnings,
    
pPM,
    
IsPlayerMuted,
    
Killstreak,
    
pHumanClass,
    
pZombieClass,
    
IsPlayerInfected,
    
IsPlayerInfectedTimer,
    
Boxes,
    
BoxesAdvanced,
    
C4,
    
bombs,
    
pVipKickBack,
    
pVipFlash,
    
pVipBoxes,
    
pLadders,
    
pKickBackCoin,
    
pDamageShotgunCoin,
    
pDamageDeagleCoin,
    
pDamageMP5Coin,
    
pDoctorShield,
//    pTerroristBomb,
    
Frozen,
    
Minigun
};
public 
OnPlayerDisconnect(playeridreason)
{
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"data");
    
INI_WriteInt(File,"pCash",GetPlayerMoney(playerid));
    
INI_WriteInt(File,"pXP",pInfo[playerid][pXP]);
    
INI_WriteInt(File,"pKills",pInfo[playerid][pKills]);
    
INI_WriteInt(File,"pDeaths",pInfo[playerid][pDeaths]);
    
INI_WriteInt(File,"pHeads",pInfo[playerid][pHeads]);
    
INI_WriteInt(File,"pRank",pInfo[playerid][pRank]);
    
INI_WriteInt(File,"pEvac",pInfo[playerid][pEvac]);
    
INI_WriteInt(File,"pAdminLevel",pInfo[playerid][pAdminLevel]);
    
INI_WriteInt(File,"pAdminDuty",pInfo[playerid][pAdminDuty]);
    
INI_WriteInt(File,"pVipLevel",pInfo[playerid][pVipLevel]);
    
INI_WriteInt(File,"pHour",pInfo[playerid][pHour]);
    
INI_WriteInt(File,"pMin",pInfo[playerid][pMin]);
    
INI_WriteInt(File,"pSec",pInfo[playerid][pSec]);
    
INI_WriteInt(File,"pMapsPlayed",pInfo[playerid][pMapsPlayed]);
    
INI_WriteInt(File,"pCoins",pInfo[playerid][pCoins]);
    
INI_WriteInt(File,"pBanned",pInfo[playerid][pBanned]);
    
INI_Close(File);
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
new 
INI:File INI_Open(UserPath(playerid));
                
WP_Hash(bufsizeof(buf), inputtext);
                
INI_SetTag(File,"data");
                
INI_WriteString(File,"pPassword"buf);
                
INI_WriteInt(File,"pCash",0);
                
INI_WriteInt(File,"pXP",0);
                
INI_WriteInt(File,"pKills",0);
                
INI_WriteInt(File,"pHeads",0);
                
INI_WriteInt(File,"pDeaths",0);
                
INI_WriteInt(File,"pRank",0);
                
INI_WriteInt(File,"pEvac",0);
                
INI_WriteInt(File,"pAdminLevel",0);
                
INI_WriteInt(File,"pAdminDuty",0);
                
INI_WriteInt(File,"pVipLevel",0);
                
INI_WriteInt(File,"pHour",0);
                
INI_WriteInt(File,"pMin",0);
                
INI_WriteInt(File,"pSec",0);
                
INI_WriteInt(File,"pMapsPlayed",0);
                
INI_WriteInt(File,"pCoins",0);
                
INI_WriteString(File,"pIP",IP);
                
INI_WriteInt(File,"pBanned",0);
                
INI_Close(File); 
stock ResetVars(playerid)
{
    
//pInfo[playerid][pPassword] = 0;
    
pInfo[playerid][pCash] = 0;
    
pInfo[playerid][pXP] = 0;
    
pInfo[playerid][pKills] = 0;
    
pInfo[playerid][pDeaths] = 0;
    
pInfo[playerid][pHeads] = 0;
    
pInfo[playerid][pRank] = 0;
    
pInfo[playerid][pEvac] = 0;
    
pInfo[playerid][pAdminLevel] = 0;
    
pInfo[playerid][pAdminDuty] = 0;
    
pInfo[playerid][pBanned] = 0;
    
pInfo[playerid][pVipLevel] = 0;
    
pInfo[playerid][pHour] = 0;
    
pInfo[playerid][pMin] = 0;
    
pInfo[playerid][pSec] = 0;
    
pInfo[playerid][pMapsPlayed] = 0;
    
pInfo[playerid][pCoins] = 0;
    
pInfo[playerid][pLogged] = 0;
    
pInfo[playerid][pWarnings] = 0;
    
pInfo[playerid][pPM] = 0;
    
pInfo[playerid][IsPlayerMuted] = 0;
    
pInfo[playerid][Killstreak] = 0;
    
pInfo[playerid][pHumanClass] = 0;
    
pInfo[playerid][pZombieClass] = 0;
    
pInfo[playerid][IsPlayerInfected] = 0;
    
pInfo[playerid][Boxes] = 0;
    
pInfo[playerid][BoxesAdvanced] = 0;
    
pInfo[playerid][pVipKickBack] = 0;
    
pInfo[playerid][pVipFlash] = 0;
    
pInfo[playerid][pVipBoxes] = 0;
    
pInfo[playerid][pLadders] = 0;
    
pInfo[playerid][pKickBackCoin] = 0;
    
pInfo[playerid][pDamageShotgunCoin] = 0;
    
pInfo[playerid][pDamageDeagleCoin] = 0;
    
pInfo[playerid][pDamageMP5Coin] = 0;
    
pInfo[playerid][pDoctorShield] = 0;
     
Abilitys[playerid][HighJumpScout] = 0;
     
Abilitys[playerid][HighJumpZombie] = 0;
     
Abilitys[playerid][StomperPushing] = 0;
     
Abilitys[playerid][WitchAttack] = 0;
     
Abilitys[playerid][ScreamerZombieAb] = 0;
     
Abilitys[playerid][InfectionNormal] = 0;
     
Abilitys[playerid][InfectionMutated] = 0;
     
Abilitys[playerid][ShoutCooldown] = 0;
     
Abilitys[playerid][HealCoolDown] = 0;
     
Abilitys[playerid][ScreamerZombieAb2] = 0;
     
Abilitys[playerid][WitchAttack2] = 0;
     
Abilitys[playerid][InfectionFleshEater] = 0;
    
KillTimer(playedtimer[playerid]);
    
CurePlayer(playerid);
    
KillTimer(pInfo[playerid][IsPlayerInfectedTimer]);
    
SetPVarInt(playerid"SPS Messages Sent"0);
    
SetPVarInt(playerid"SPS Muted"0);
    
SetPVarInt(playerid"SPS Spam Warnings"0);
    
//SPS_Reset_PVars();
    
return 1;
stock SaveStats(playerid)
{
     new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"data");
    
INI_WriteInt(File,"pCash",GetPlayerMoney(playerid));
    
INI_WriteInt(File,"pXP",pInfo[playerid][pXP]);
    
INI_WriteInt(File,"pKills",pInfo[playerid][pKills]);
    
INI_WriteInt(File,"pDeaths",pInfo[playerid][pDeaths]);
    
INI_WriteInt(File,"pHeads",pInfo[playerid][pHeads]);
    
INI_WriteInt(File,"pRank",pInfo[playerid][pRank]);
    
INI_WriteInt(File,"pEvac",pInfo[playerid][pEvac]);
    
INI_WriteInt(File,"pAdminLevel",pInfo[playerid][pAdminLevel]);
    
INI_WriteInt(File,"pAdminDuty",pInfo[playerid][pAdminDuty]);
    
INI_WriteInt(File,"pVipLevel",pInfo[playerid][pVipLevel]);
    
INI_WriteInt(File,"pHour",pInfo[playerid][pHour]);
    
INI_WriteInt(File,"pMin",pInfo[playerid][pMin]);
    
INI_WriteInt(File,"pSec",pInfo[playerid][pSec]);
    
INI_WriteInt(File,"pMapsPlayed",pInfo[playerid][pMapsPlayed]);
    
INI_WriteInt(File,"pCoins",pInfo[playerid][pCoins]);
    
INI_WriteInt(File,"pBanned",pInfo[playerid][pBanned]);
    
INI_Close(File);
    return 
1;
}
SetPlayerMoney(playeridcash)
{
    
pInfo[playerid][pCash] += cash;
    
GivePlayerMoney(playeridpInfo[playerid][pCash]);
    return 
1;
}
CMD:stats(playerid)
{
    new 
string[2000];
    new 
Float:kd floatdiv(pInfo[playerid][pKills], pInfo[playerid][pDeaths]);
    new 
Float:wins floatdiv(pInfo[playerid][pMapsPlayed], pInfo[playerid][pEvac]);
    
format(string,sizeof(string),"    Viewing player stats: Yourself    \n\nCash: %i\n{DC143C}Tokens{FFFFFF}: %i\n{DC143C}XP{FFFFFF}: %i\n{DC143C}Kills{FFFFFF}: %i\n{DC143C}Deaths{FFFFFF}: %i\n{DC143C}Headshots{FFFFFF}: %i\n{DC143C}Maps Played{FFFFFF}: %i\n\
    {DC143C}Rank{FFFFFF}: %i\n{DC143C}Evac Points{FFFFFF}: %i\n{DC143C}Admin{FFFFFF}: %s\n{DC143C}Vip Level{FFFFFF}: %i\n\
    {DC143C}Played{FFFFFF}: %d Hours || %d Minutes || %d Seconds\n{DC143C}K:D RATIO{FFFFFF}: %0.2f\n{DC143C}Win RATIO{FFFFFF}: %0.2f"
,
    
pInfo[playerid][pCash],pInfo[playerid][pCoins],pInfo[playerid][pXP],pInfo[playerid][pKills],pInfo[playerid][pDeaths],pInfo[playerid][pHeads],pInfo[playerid][pMapsPlayed],
    
pInfo[playerid][pRank],pInfo[playerid][pEvac],GetAdminName(playerid),pInfo[playerid][pVipLevel],pInfo[playerid][pHour],pInfo[playerid][pMin],pInfo[playerid][pSec],kd,wins);
    
ShowPlayerDialog(playerid,1888,DIALOG_STYLE_MSGBOX,"Viewing Stats!",string,"Close","");
    return 
1;

Reply
#2

I might be wrong, but I dont see any code where you load their stats?
Reply
#3

As said by Twinki, show where you load the cash.

Also show what happens when they reach the "evacuation" point, you're not giving us much to work with.
Reply
#4

Evacuation info:

PHP код:
public OnPlayerEnterCheckpoint(playerid)
{
    if(
team[playerid] == TEAM_HUMAN)
    {
        new 
string[256];
        if(
Map[EvacType] == 1)
        {
            
SetPlayerInterior(playerid,17);
            
SetPlayerPos(playerid,487.3870,-13.7815,1000.6797);
            
format(string,sizeof(string), ""chat""COL_LGREEN"{ffffff} %s{99CCFF} made it to evacuation point and has received {FFD700}1 Token{99CCFF}!",PlayerName(playerid));
            
SendClientMessageToAll(-1,string);
            
DisablePlayerCheckpoint(playerid);
            
CurePlayer(playerid);
            
GivePlayerXP(playerid,10);
            
GivePlayerCash(playerid,100);
            
pInfo[playerid][pEvac]++;
            
pInfo[playerid][pCoins]++;
            
SetPlayerColor(playerid,COLOR_YELLOW);
            
UpdateTokensTextdraw(playerid);
            
SetPlayerScore(playerid,pInfo[playerid][pXP]);
            
SetPlayerCash(playerid,pInfo[playerid][pCash]);
            
UpdateXPTextdraw(playerid);
        }
    }
    return 
1;

Load user stats:

PHP код:
public LoadUser_data(playerid,name[],value[])
{
    
INI_String("pPassword"pInfo[playerid][pPassword], 129);
    
INI_Int("pCash",pInfo[playerid][pCash]);
    
INI_Int("pXP",pInfo[playerid][pXP]);
    
INI_Int("pKills",pInfo[playerid][pKills]);
    
INI_Int("pDeaths",pInfo[playerid][pDeaths]);
    
INI_Int("pHeads",pInfo[playerid][pHeads]);
    
INI_Int("pRank",pInfo[playerid][pRank]);
    
INI_Int("pEvac",pInfo[playerid][pEvac]);
    
INI_Int("pAdminLevel",pInfo[playerid][pAdminLevel]);
    
INI_Int("pAdminDuty",pInfo[playerid][pAdminDuty]);
    
INI_Int("pVipLevel",pInfo[playerid][pVipLevel]);
    
INI_Int("pHour",pInfo[playerid][pHour]);
    
INI_Int("pMin",pInfo[playerid][pMin]);
    
INI_Int("pSec",pInfo[playerid][pSec]);
    
INI_Int("pMapsPlayed",pInfo[playerid][pMapsPlayed]);
    
INI_Int("pCoins",pInfo[playerid][pCoins]);
    
INI_Int("pBanned",pInfo[playerid][pBanned]);
    
printf("Password: %s"pInfo[playerid][pPassword]);
    return 
1;

Reply
#5

Add under the loading at the end of the function;

ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, pInfo[playerid][pCash]);
Reply
#6

Use INI_ReadInt, INI_ReadString and INI_ReadFloat for obtaining data from .ini files. That's what I'm using, and my script loads all of the player's data perfectly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)