~URGENT~ Score saving is not working Rep++
#1

Okay for the past 3 WEEKS i've been trieing to fix this but i just can't!
I dont know what to do it just won't save


pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(PInfo[playerid][Logged] == 1)
    {
        PInfo[playerid][Logged] = 0;
        new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME], file[64];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "** %s has left United Kingdom TDM", name);
        SendClientMessageToAll(-1, string);
        format(file, sizeof file, "Admin/%s.ini", name);

        INI_Open(file);
        INI_WriteInt("Level", PInfo[playerid][Level]);
        INI_WriteInt("Score", GetPlayerScore(playerid));
        INI_WriteInt("Money",GetPlayerMoney(playerid));
        INI_Save();
        INI_Close();
    }
    return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,-1,"Welcome to United Kingdom TDM! Dont forget to check /updates ! ");
    new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "** %s has joined United Kingdom TDM", name);
    SendClientMessageToAll(-1, string);

    new file[64],PlayerName[25];//Creating a variable where we can store the file path, and the variable to store the player's name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);//Storing the players name in the PlayerName variable.
    format(file,sizeof file,"Admin/%s.ini",PlayerName);//Storing the file path with the players name.
    if(!fexist(file))//Checking if the file exists
    {//Here goes the stuff you want to do if the user is not registered.
        SendClientMessage(playerid,-4,"You are not registered! Please use /register <password>");
    }
    else
    {//Here goes the stuff you want to do if the user is registered.
        SendClientMessage(playerid,-4,"You are registered! Use /login <password>");
    }
    return 1;
}
pawn Код:
CMD:register(playerid,params[])
{
    if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,-4,"You are already logged in!");
    new password[23];
    if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid,-1,"USAGE: /register <password>");
    new file[64],PlayerName[24];
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    if(fexist(file)) return SendClientMessage(playerid,-4,"Somehow you're already registered!");
    INI_Open(file);
    INI_WriteString("Password",password);
    INI_WriteInt("Level",PInfo[playerid][Level]);
    INI_WriteInt("Score",0);
    INI_WriteInt("Money",2000);
    INI_Save();
    INI_Close();
    SendClientMessage(playerid,-1,"You have successfully registered!");
    PInfo[playerid][Logged] = 1;
    return 1;
}

CMD:login(playerid,params[])
{
    if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,-4,"You are already logged in!");//Checking if the player is logged in, if he is, it won't allow him to login
    new password[23],password2[23];//Creating a variable to store the password, and another one to store the password from the user's file.
    if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid,-1,"USAGE: /login <password>");//Here we're checking if the player inputs any password, if not, it will return to him a message saying the proper usage.
    new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    if(!fexist(file)) return SendClientMessage(playerid,-4,"Please use /register");//Checking if the player is  not registered, again....
    INI_Open(file);//Opening the file with SII include
    INI_ReadString(password2,"Password");
    if(strcmp(password,password2) != 0) return SendClientMessage(playerid,-4,"Wrong password!"),INI_Close();//Checking if he inputted the correct password, if not, retrieve him a message and closing the file;
    PInfo[playerid][Level] = INI_ReadInt("Level");//Setting the admin level variable, to the one thats in his file.
    PInfo[playerid][Score] = INI_ReadInt("Score"); // Setting the score of player
    PInfo[playerid][Score] = INI_ReadInt("Money"); // Setting the score of player
    INI_Close();//"Closing the file", that means that we're not using it anymore :P
    SetPlayerScore(playerid, PInfo[playerid][Score]);
    SendClientMessage(playerid,-1,"You have been successfully logged in!");
    PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
    return 1;
}
pawn Код:
enum PlayerInfo
{
    Logged,
    Level,
    Score,
    Money,
}
pawn Код:
#define PATH "/Admin/%s.ini"
pawn Код:
public UserDataLoad_data(playerid,name[],value[]) {
    INI_Int("Money",PInfo[playerid][Money]);
    INI_Int("Score",PInfo[playerid][Score]);
    INI_Int("Level",PInfo[playerid][Level]);
    return 1;
}
I'm USING SII! https://sampforum.blast.hk/showthread.php?tid=58458
Reply
#2

pawn Код:
PInfo[playerid][Score] = INI_ReadInt("Money"); // Setting the score of player
Fail - Saving score instead of money
pawn Код:
public UserDataLoad_data(playerid,name[],value[]) {
    INI_Int("Money",PInfo[playerid][Money]);
    INI_Int("Score",PInfo[playerid][Score]);
    INI_Int("Level",PInfo[playerid][Level]);
    return 1;
}
Fail - SII doesn't uses INI_Int .. its for y_ini

As per viewing your codes.. i can't see PInfo[playerid][Score] is getting the score.
So
Try to create a var like mine
pawn Код:
stock SavePlayer(playerid)
{
   new file[256];
   new scores = GetPlayerScore(playerid);
   new money = GetPlayerMoney(playerid);
   format(file, sizeof(file),"AVC/Users/%s.ini",PlayerName2(playerid));
   INI_Open(file);
   INI_WriteInt("Scores",scores);
   INI_WriteInt("Level",PlayerInfo[playerid][pLevel]);
   INI_WriteInt("Helper",PlayerInfo[playerid][pHelper]);
   INI_WriteInt("Money",money);
   INI_WriteInt("Kills",PlayerInfo[playerid][pKills]);
   INI_WriteInt("Deaths",PlayerInfo[playerid][pDeaths]);
   SendClientMessage(playerid, LIGHTGREEN,"Stats Saved.");
   return 1;
}
Take help from my code it will help you.
Reply
#3

Can you please fix it in my codes?
Reply
#4

Try this on OnPlayerDisconnect
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(PInfo[playerid][Logged] == 1)
    {
        PInfo[playerid][Logged] = 0;
        new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME], file[64];
        GetPlayerName(playerid, name, sizeof(name));
        format(string, sizeof(string), "** %s has left United Kingdom TDM", name);
        SendClientMessageToAll(-1, string);
        format(file, sizeof file, "Admin/%s.ini", name);
        new scores = GetPlayerScore(playerid), //Created extra var to check it.
        new money = GetPlayerMoney(playerid);
        INI_Open(file);
        INI_WriteInt("Level", PInfo[playerid][Level]);
        INI_WriteInt("Score", scores);
        INI_WriteInt("Money",money);
        INI_Save();
        INI_Close();
    }
    return 1;
}
Fixed your small mistake
pawn Код:
CMD:login(playerid,params[])
{
    if(PInfo[playerid][Logged] == 1) return SendClientMessage(playerid,-4,"You are already logged in!");//Checking if the player is logged in, if he is, it won't allow him to login
    new password[23],password2[23];//Creating a variable to store the password, and another one to store the password from the user's file.
    if(sscanf(params,"s[23]",password)) return SendClientMessage(playerid,-1,"USAGE: /login <password>");//Here we're checking if the player inputs any password, if not, it will return to him a message saying the proper usage.
    new file[64],PlayerName[24];//Creating a variable to store the file path, and a variable to store the players name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);
    format(file,sizeof file,"Admin/%s.ini",PlayerName);
    if(!fexist(file)) return SendClientMessage(playerid,-4,"Please use /register");//Checking if the player is  not registered, again....
    INI_Open(file);//Opening the file with SII include
    INI_ReadString(password2,"Password");
    if(strcmp(password,password2) != 0) return SendClientMessage(playerid,-4,"Wrong password!"),INI_Close();//Checking if he inputted the correct password, if not, retrieve him a message and closing the file;
    PInfo[playerid][Level] = INI_ReadInt("Level");//Setting the admin level variable, to the one thats in his file.
    PInfo[playerid][Score] = INI_ReadInt("Score"); // Setting the score of player
    PInfo[playerid][Money] = INI_ReadInt("Money"); // Setting the score of player
    INI_Close();//"Closing the file", that means that we're not using it anymore :P
    SetPlayerScore(playerid, PInfo[playerid][Score]);
    SendClientMessage(playerid,-1,"You have been successfully logged in!");
    PInfo[playerid][Logged] = 1;//Setting the logged in variable to 1
    return 1;
}
Make sure.. there is Money in your enumerator.
Try it ..it must work.

by chance it doesn't worked please have a look at this tutorial : https://sampforum.blast.hk/showthread.php?tid=267808
I learned SII from there..
Reply
#5

pawn Код:
C:\Users\Bichan\Desktop\UKTDM\gamemodes\UKTDM.pwn(358) : error 001: expected token: "-identifier-", but found "new"
C:\Users\Bichan\Desktop\UKTDM\gamemodes\UKTDM.pwn(362) : error 017: undefined symbol "money"
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase

2 Errors.


pawn Код:
new money = GetPlayerMoney(playerid);
and

pawn Код:
INI_WriteInt("Money",money);
Reply
#6

Wops.s. sorry for the mistake.. remove "new" from the money

Ex:
pawn Код:
new scores = GetPlayerScore(playerid), //Created extra var to check it.
money = GetPlayerMoney(playerid);
Reply
#7

Quote:
Originally Posted by Jarnu
Посмотреть сообщение
Wops.s. sorry for the mistake.. remove "new" from the money

Ex:
pawn Код:
new scores = GetPlayerScore(playerid), //Created extra var to check it.
money = GetPlayerMoney(playerid);
Seriously you're the best score saving works as far as i know!
But one little problem, in the register CMD

It automaticly sets the player admin level to 7 can you check the register cmd please for me for any errors.

EDIT: And the money saving doesn't work "WHen i put 2000 in the .ini file and i login it still shows 0 money"
Reply
#8

For your admin level use following under OnPlayerConnect
pawn Код:
PlayerInfo[playerid][Level] = 0; //Or whatever you use for defining admin level
EDIT: got it.. use following in your Register command
pawn Код:
SetPlayerCash(playerid, PlayerInfo[playerid][Money]);
Reply
#9

How do i add it... since its very big

pawn Код:
public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,-1,"Welcome to United Kingdom TDM! Dont forget to check /updates ! ");
    new name[MAX_PLAYER_NAME], string[24+MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    format(string, sizeof(string), "** %s has joined United Kingdom TDM", name);
    SendClientMessageToAll(-1, string);

    new file[64],PlayerName[25];//Creating a variable where we can store the file path, and the variable to store the player's name.
    GetPlayerName(playerid,PlayerName,sizeof PlayerName);//Storing the players name in the PlayerName variable.
    format(file,sizeof file,"Admin/%s.ini",PlayerName);//Storing the file path with the players name.
    if(!fexist(file))//Checking if the file exists
    {//Here goes the stuff you want to do if the user is not registered.
        SendClientMessage(playerid,-4,"You are not registered! Please use /register <password>");
    }
    else
    {//Here goes the stuff you want to do if the user is registered.
        SendClientMessage(playerid,-4,"You are registered! Use /login <password>");
    }
    return 1;
}
Reply
#10

I already said.. that use
pawn Код:
SetPlayerCash(playerid, PlayerInfo[playerid][Money]);
Under CMD:register put this where you give the player scores
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)