score saving
#1

i need code that save score to "scriptfiles/score" if player leaves and if player connects with server it automaticliy loads score
Reply
#2

please post it in script request thread.
Reply
#3

pawn Код:
#include <a_samp>
#include <YSI\y_ini>

#define ScorePath "Score/%s.ini"
enum ScoreInfo
{
    Scores
}
new sInfo[MAX_PLAYERS][ScoreInfo];

stock Path(playerid)
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),ScorePath,name);
    return str;
}

forward loadscores_user(playerid, name[], value[]);
public loadscores_user(playerid, name[], value[])
{
    INI_Int("Scores",sInfo[playerid][Scores]);
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadscores_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
    }
    else //If the connected user is not registered,
    {
        new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
        INI_Close(file);
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:file = INI_Open(Path(playerid)); //will open their file
    INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
    INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
    INI_Close(file);//Now after we've done saving their data, we now need to close the file
    return 1;
}
Reply
#4

Quote:
Originally Posted by Avi57
Посмотреть сообщение
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

#define ScorePath "Score/%s.ini"
enum ScoreInfo
{
    Scores
}
new sInfo[MAX_PLAYERS][ScoreInfo];

stock Path(playerid)
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),ScorePath,name);
    return str;
}

forward loadscores_user(playerid, name[], value[]);
public loadscores_user(playerid, name[], value[])
{
    INI_Int("Scores",sInfo[playerid][Scores]);
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadscores_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
    }
    else //If the connected user is not registered,
    {
        new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
        INI_Close(file);
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:file = INI_Open(Path(playerid)); //will open their file
    INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
    INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
    INI_Close(file);//Now after we've done saving their data, we now need to close the file
    return 1;
}
This code sets every time i connect every player score 0 but they have file in "Score/"
Reply
#5

Quote:
Originally Posted by Avi57
Посмотреть сообщение
pawn Код:
#include <a_samp>
#include <YSI\y_ini>

#define ScorePath "Score/%s.ini"
enum ScoreInfo
{
    Scores
}
new sInfo[MAX_PLAYERS][ScoreInfo];

stock Path(playerid)
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),ScorePath,name);
    return str;
}

forward loadscores_user(playerid, name[], value[]);
public loadscores_user(playerid, name[], value[])
{
    INI_Int("Scores",sInfo[playerid][Scores]);
    return 1;
}

public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadscores_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
    }
    else //If the connected user is not registered,
    {
        new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
        INI_SetTag(file,"user");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
        INI_Close(file);
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:file = INI_Open(Path(playerid)); //will open their file
    INI_SetTag(file,"user");//We will set a tag inside of user's account called "Player's Data"
    INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
    INI_Close(file);//Now after we've done saving their data, we now need to close the file
    return 1;
}
Fixed.
Reply
#6

Problem is in this:

pawn Код:
else //If the connected user is not registered,
    {
        new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
        INI_SetTag(file,"user");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
        INI_Close(file);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)