Help met score saving REP++
#1

Oke! ik moet echt wat hulp hebben bij het saven van scores
Het wil maar niet werken..

pawn Code:
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 Code:
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 Code:
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 Code:
enum PlayerInfo
{
    Logged,
    Level,
    Score,
    Money,
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)