I got a problem with saving files like a password and money. I have for the player a save file but now i wanna make a save file for the playerbank. I did the same thing as with the player saving file. The player file works but the bank file not. It is almost the same but do not work.
Код:
#define BankFile "ServerData/Bank/%s.ini"
#define PlayerFile "ServerData/Players/%s.ini"
Dialog_BankRegister(playerid, response, inputtext[])
{
switch (response) // Check which button was clicked
{
case 1: // Player clicked "Register"
{
// Check if the player entered a password
if(strlen(inputtext)>0)
{
// Store the password //THIS IS MY BROBLEM inputtext = 9876. he makes is 9 on create and save.
format(BankData[playerid][BankPassword], 50, "%s", inputtext);
---------------------------------------------------------------------------------------
BankFile_Create(playerid);//goto function
SendClientMessage(playerid, geel, "Rekening gemaakt en klaar voor gebruik."); // Send a message to the client Account created and ready for use
BankData[playerid][BankMoney] = 0;
format(BankStringA, sizeof(BankStringA), " U heeft op de bank: %i ", BankData[playerid][BankMoney]);//You have on youre Account:
ShowPlayerDialog(playerid, DialogBank, DIALOG_STYLE_LIST, BankStringA, TXT_DialogBankList, TXT_DialogButtonOke, TXT_DialogButtonCancel);
return 1;
}
else // Ask the player to enter a proper password
{
ShowPlayerDialog(playerid, DialogBankRegister, DIALOG_STYLE_INPUT, "Welcome", "Voer goed wachtwoord in om te registreren:", "Register", "Cancel");//Enter good password to register
}
}
case 0: // Player clicked "Cancel"
{
return 1;
}
}
return 1;
}
// This function will create the player-datafile for the given player (only used when a new player joins the server)
BankFile_Create(playerid)
{
new file[100], File:PFile, Name[24], LineForFile[100];
GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's account
PFile = fopen(file, io_write); // Open the playerfile for writing
format(LineForFile, 100, "Password %s\r\n", BankData[playerid][BankPassword]);// Construct the line: "Bank <BankPassword>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Money %i\r\n", 0); // Construct the line: "Money <bankmoney>"
fwrite(PFile, LineForFile); // And save it to the file
fclose(PFile); // Close the file
return 1;
}
// This function will load the player's datafile (used when a player connects to the server)
BankFile_Load(playerid)
{
// Setup local variables
new file[100], File:PFile, Name[24], LineFromFile[100], ParameterName[50], ParameterValue[50];
GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's account
// Check if the player's datafile exists
if (fexist(file))
{
PFile = fopen(file, io_read); // Open the playerfile for reading
fread(PFile, LineFromFile); // Read the first line of the file
// Keep reading until the end of the file is found (no more data)
while (strlen(LineFromFile) > 0)
{
StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
// Store the proper value in the proper place
if (strcmp(ParameterName, "Password", false) == 0) // If the parametername is correct ("Password")
format(BankData[playerid][BankPassword], 50, ParameterValue); // Store the password
if (strcmp(ParameterName, "Money", false) == 0) // If the parametername is correct ("Money")
BankData[playerid][BankMoney] = strval(ParameterValue);
fread(PFile, LineFromFile); // Read the next line of the file
}
fclose(PFile); // Close the file
return 1; // Return if the file was read correctly
}
else
return 0; // Return 0 if the file couldn't be read (doesn't exist)
}
// This function will save all player-data (used when the player disconnects from the server)
BankFile_Save(playerid)
{
new file[100], File:PFile, Name[24], LineForFile[100];
GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
format(file, sizeof(file), BankFile, Name); // Construct the complete filename for this player's account
PFile = fopen(file, io_write); // Open the playerfile for writing
format(LineForFile, 100, "Password %s\r\n", BankData[playerid][BankPassword]); // Construct the line: "Password <Bankpassword>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Money %i\r\n", BankData[playerid][BankMoney]); // Construct the line: "Money <Bankmoney>"
fwrite(PFile, LineForFile); // And save it to the file
fclose(PFile); // Close the file
return 1;
}
// This function will create the player-datafile for the given player (only used when a new player joins the server)
PlayerFile_Create(playerid)
{
new file[100], File:PFile, Name[24], LineForFile[100];
GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account
PFile = fopen(file, io_write); // Open the playerfile for writing
format(LineForFile, 100, "Password %s\r\n", APlayerData[playerid][PlayerPassword]);
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Sex %s\r\n", APlayerData[playerid][Sex]); // Construct the line: "Sex <Sex>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Level %i\r\n", 0); // Construct the line: "Level <PlayerLevel>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "XPLevel %i\r\n", APlayerData[playerid][XPLevel]); // Construct the line: "Level <XPLevel>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Money %i\r\n", 0); // Construct the line: "Money <playermoney>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Score %i\r\n", 0); // Construct the line: "Score <playerscore>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "BromLicense %i\r\n", 0); // Construct the line: "BromLicense <playerBromlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "AutoLicense %i\r\n", 0); // Construct the line: "AutoLicense <playerAutolicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "MotorLicense %i\r\n", 0); // Construct the line: "MotorLicense <playerMotorlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "BusLicense %i\r\n", 0); // Construct the line: "BusLicense <playerbuslicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "TruckerLicense %i\r\n", 0); // Construct the line: "TruckerLicense <playertruckerlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "TruckerALicense %i\r\n", 0); // Construct the line: "TruckerALicense <playertruckerAlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "TreinLicense %i\r\n", 0); // Construct the line: "MotorLicense <playerMotorlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Wanted %i\r\n", 0); // Construct the line: "Wanted <wantedlevel>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Bans %i\r\n", 0); // Construct the line: "Bans <NumberOfBans>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "BanTime %i\r\n", 0); // Construct the line: "BanTime <TimeToUnban>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Logins %i\r\n", 0);
fwrite(PFile, LineForFile); // And save it to the file
fclose(PFile); // Close the file
return 1;
}
// This function will load the player's datafile (used when a player connects to the server)
PlayerFile_Load(playerid)
{
// Setup local variables
new file[100], File:PFile, Name[24], LineFromFile[100], ParameterName[50], ParameterValue[50];
GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account
// Check if the player's datafile exists
if (fexist(file))
{
PFile = fopen(file, io_read); // Open the playerfile for reading
fread(PFile, LineFromFile); // Read the first line of the file
// Keep reading until the end of the file is found (no more data)
while (strlen(LineFromFile) > 0)
{
StripNewLine(LineFromFile); // Strip any newline characters from the LineFromFile
sscanf(LineFromFile, "s[50]s[50]", ParameterName, ParameterValue); // Extract parametername and parametervalue
// Store the proper value in the proper place
if (strcmp(ParameterName, "Password", false) == 0) // If the parametername is correct ("Password")
format(APlayerData[playerid][PlayerPassword], 50, ParameterValue); // Store the password
if (strcmp(ParameterName, "Sex", false) == 0) // If the parametername is correct ("Sex")
format(APlayerData[playerid][Sex], 50, ParameterValue); // Store the Sex
if (strcmp(ParameterName, "Level", false) == 0) // If the parametername is correct ("playerLevel")
APlayerData[playerid][PlayerLevel] = strval(ParameterValue); // Store the adminlevel
if (strcmp(ParameterName, "XPLevel", false) == 0) // If the parametername is correct ("playerLevel")
RewardPlayer(playerid, 0, 0, strval(ParameterValue)); // Store the XPLevel
if (strcmp(ParameterName, "Money", false) == 0) // If the parametername is correct ("Money")
RewardPlayer(playerid, strval(ParameterValue), 0, 0); // Store the money
if (strcmp(ParameterName, "Score", false) == 0) // If the parametername is correct ("Score")
RewardPlayer(playerid, 0, strval(ParameterValue), 0); // Store the score
if (strcmp(ParameterName, "BromLicense", false) == 0) // If the parametername is correct ("BromLicense")
APlayerData[playerid][BromLicense] = strval(ParameterValue); // Store the BromLicense
if (strcmp(ParameterName, "AutoLicense", false) == 0) // If the parametername is correct ("AutoLicense")
APlayerData[playerid][AutoLicense] = strval(ParameterValue); // Store the AutoLicense
if (strcmp(ParameterName, "MotorLicense", false) == 0) // If the parametername is correct ("MotorLicense")
APlayerData[playerid][MotorLicense] = strval(ParameterValue); // Store the MotorLicense
if (strcmp(ParameterName, "BusLicense", false) == 0) // If the parametername is correct ("BusLicense")
APlayerData[playerid][BusLicense] = strval(ParameterValue); // Store the BusLicense
if (strcmp(ParameterName, "TruckerLicense", false) == 0) // If the parametername is correct ("TruckerLicense")
APlayerData[playerid][TruckerLicense] = strval(ParameterValue); // Store the TruckerLicense
if (strcmp(ParameterName, "TruckerALicense", false) == 0) // If the parametername is correct ("TruckerALicense")
APlayerData[playerid][TruckerALicense] = strval(ParameterValue); // Store the TruckerALicense
if (strcmp(ParameterName, "TreinLicense", false) == 0) // If the parametername is correct ("TreinLicense")
APlayerData[playerid][TreinLicense] = strval(ParameterValue); // Store the TreinLicense
if (strcmp(ParameterName, "Wanted", false) == 0) // If the parametername is correct ("Wanted")
SetPlayerWantedLevel(playerid, strval(ParameterValue)); // Set the wanted-status
if (strcmp(ParameterName, "Bans", false) == 0) // If the parametername is correct ("Bans")
APlayerData[playerid][Bans] = strval(ParameterValue); // Store the bans
if (strcmp(ParameterName, "BanTime", false) == 0) // If the parametername is correct ("BanTime")
APlayerData[playerid][BanTime] = strval(ParameterValue); // Store the bantime
if (strcmp(ParameterName, "Logins", false) == 0) // If the parametername is correct ("Logins")
APlayerData[playerid][Logins] = strval(ParameterValue); // Store the Logins
fread(PFile, LineFromFile); // Read the next line of the file
}
fclose(PFile); // Close the file
return 1; // Return if the file was read correctly
}
else
return 0; // Return 0 if the file couldn't be read (doesn't exist)
}
// This function will save all player-data (used when the player disconnects from the server)
PlayerFile_Save(playerid)
{
new file[100], File:PFile, Name[24], LineForFile[100];
GetPlayerName(playerid, Name, sizeof(Name)); // Get the playername
format(file, sizeof(file), PlayerFile, Name); // Construct the complete filename for this player's account
PFile = fopen(file, io_write); // Open the playerfile for writing
format(LineForFile, 100, "Password %s\r\n", APlayerData[playerid][PlayerPassword]); // Construct the line: "Password <playerpassword>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Sex %s\r\n", APlayerData[playerid][Sex]); // Construct the line: "Sex <Sex>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Level %i\r\n", APlayerData[playerid][PlayerLevel]); // Construct the line: "Level <PlayerLevel>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "XPLevel %i\r\n", APlayerData[playerid][XPLevel]); // Construct the line: "Level <XPLevel>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Money %i\r\n", APlayerData[playerid][PlayerMoney]); // Construct the line: "Money <playermoney>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Score %i\r\n", APlayerData[playerid][PlayerScore]); // Construct the line: "Score <playerscore>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "BromLicense %i\r\n", APlayerData[playerid][BromLicense]); // Construct the line: "BromLicense <playerBromlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "AutoLicense %i\r\n", APlayerData[playerid][AutoLicense]); // Construct the line: "AutoLicense <playerAutolicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "MotorLicense %i\r\n", APlayerData[playerid][MotorLicense]); // Construct the line: "MotorLicense <playerMotorlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "BusLicense %i\r\n", APlayerData[playerid][BusLicense]); // Construct the line: "BusLicense <playerbuslicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "TruckerLicense %i\r\n", APlayerData[playerid][TruckerLicense]); // Construct the line: "TruckerLicense <playertruckerlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "TruckerALicense %i\r\n", APlayerData[playerid][TruckerALicense]); // Construct the line: "TruckerALicense <playertruckerAlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "TreinLicense %i\r\n", APlayerData[playerid][TreinLicense]); // Construct the line: "TreinLicense <playertreinlicense>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Wanted %i\r\n", GetPlayerWantedLevel(playerid)); // Construct the line: "Wanted <wantedlevel>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Bans %i\r\n", APlayerData[playerid][Bans]); // Construct the line: "Bans <NumberOfBans>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "BanTime %i\r\n", APlayerData[playerid][BanTime]); // Construct the line: "BanTime <TimeToUnban>"
fwrite(PFile, LineForFile); // And save it to the file
format(LineForFile, 100, "Logins %i\r\n", APlayerData[playerid][Logins]); // Construct the line: "Logins"
fwrite(PFile, LineForFile); // And save it to the file
fclose(PFile); // Close the file
return 1;
}
The problem is that i put in the password 9876 different then the inlog code for the player to login to the server 1234.