SA-MP Forums Archive
Cash and score bug? - 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: Cash and score bug? (/showthread.php?tid=457271)



Cash and score bug? - ThaCrypte - 10.08.2013

I have a few problems with my TDM, i use Y_Ini

First problem: When you kill a player, it should add score, it does on /stats but not on tab.

Player cash doesn't seem to save.
Onplayerconnect:
pawn Код:
if(fexist(UserPath(playerid)))
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COLOR_WHITE"Login",""COLOR_WHITE"Type your password below to login.","Login","Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COLOR_WHITE"Registering...",""COLOR_WHITE"Type your password below to register a new account.","Register","Quit");
    }
Loaduser:
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Score",PlayerInfo[playerid][pScores]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    return 1;
}

onplayerdisconnect:
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid));
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Score",GetPlayerScore(playerid));
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Close(File);
    return 1;
}
And when you login:
pawn Код:
case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    SetPlayerScore(playerid, PlayerInfo[playerid][pScores]);
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COLOR_WHITE"Login",""COLOR_RED"You have entered an incorrect password.\n"COLOR_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
It's a TDM server. with different classes.


Re: Cash and score bug? - Macluawn - 10.08.2013

Some functions may not work in onplayerdisconnect.
Use SetPlayerScore to set score.


Re: Cash and score bug? - zaider - 10.08.2013

pawn Код:
//OnPlayerDeath
SetPlayerScore(killerid, GetPlayerScore(killerid)+1);
About the money, sounds weird, because I have similar settings to you on my current project, and it works just fine. Maybe you haven't set write rights on your FTP server.


Re: Cash and score bug? - ThaCrypte - 10.08.2013

pawn Код:
PlayerInfo[killerid][pScores]++;
    GivePlayerMoney(playerid, -100);
    GivePlayerMoney(killerid, 500);
I have this @onplayerdeath.


Re: Cash and score bug? - zaider - 10.08.2013

Add
pawn Код:
PlayerInfo[killerid][pKills]++; // Assuming you're registering kills & deaths
PlayerInfo[playerid][Deaths]++; // Assuming you' registering kills & deaths
PlayerInfo[killerid][pScores]++; // Add 1 to playerscore
SendClientMessage(killerid, COLOR_YELLOW,"You have received $500 for taking out another player!"); // optional money info message to killer
SendClientMessage(playerid, COLOR_YELLOW,"You have lost $100 for dying."); // optional money info msg to target
SetPlayerScore(killerid, GetPlayerScore(killerid)+1); // Set player score +1 on TAB
SendDeathMessage(killerid,playerid,reason); // Show kill on kill list