PDA

View Full Version : Cash and score bug?


ThaCrypte
10/08/2013, 10:52 PM
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:

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:

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:

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:

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.

Macluawn
10/08/2013, 10:56 PM
Some functions may not work in onplayerdisconnect (http://wiki.sa-mp.com/wiki/OnPlayerDisconnect).
Use SetPlayerScore (http://wiki.sa-mp.com/wiki/SetPlayerScore)to set score.

zaider
10/08/2013, 11:04 PM
//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.

ThaCrypte
10/08/2013, 11:23 PM
PlayerInfo[killerid][pScores]++;
GivePlayerMoney(playerid, -100);
GivePlayerMoney(killerid, 500);

I have this @onplayerdeath.

zaider
10/08/2013, 11:29 PM
Add

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