Level not save
#1

Helo, i make a bonus command and is work very good. One problem, when i enter again in game i have level 1 and again i can use /bonus.
HOW TO FIX TO SAVE LEVEL WHEN EXIT
PHP Code:
CMD:bonus(playerid)
{
    if(
PlayerInfo[playerid][pLevel] == || GetPlayerScore(playerid) == 1)
    {
        
SendClientMessage(playerid,-1,"Deoarece ai folosit comanda /bonus ai primit:");
        
SendClientMessage(playerid,-1,"-LEVEL: 3");
        
SendClientMessage(playerid,-1,"-MONEY: $5.000.000");
        
GivePlayerMoney(playerid,5000000);
        
PlayerInfo[playerid][pLevel] = SetPlayerScore(playerid,3);
    }
    else
    {
        
SendClientMessage(playerid,-1,"Trebuie sa ai minim level 1 pentru a folosi aceasta comanda.");
    }
     return 
1;

Reply
#2

pawn Code:
CMD:bonus(playerid)
{
    if(PlayerInfo[playerid][pLevel] == 1 || GetPlayerScore(playerid) == 1)
    {
        SendClientMessage(playerid,-1,"Deoarece ai folosit comanda /bonus ai primit:");
        SendClientMessage(playerid,-1,"-LEVEL: 3");
        SendClientMessage(playerid,-1,"-MONEY: $5.000.000");
        GivePlayerMoney(playerid,5000000);
        SetPlayerScore(playerid, 3);
        PlayerInfo[playerid][pLevel] = GetPlayerScore(playerid));
    }
    else
    {
        SendClientMessage(playerid,-1,"Trebuie sa ai minim level 1 pentru a folosi aceasta comanda.");
    }
     return 1;
}
Reply
#3

Fix of above code!
Code:
       SetPlayerScore(playerid, GetPlayerScore(playerid)+3);
        PlayerInfo[playerid][pLevel] = GetPlayerScore(playerid));
Reply
#4

After the player login is successful, place this:

PHP Code:
     
       
new name[MAX_PLAYER_NAME], yourfile[256];
       
GetPlayerName(playeridnameMAX_PLAYER_NAME);
       
format(yourfile256"insert here the file you want to save the level"name);
       
PlayerInfo[playerid][pLevel] = DOF2_GetInt(yourfile,"Level");
       
SetPlayerScore(playeridPlayerInfo[playerid][pLevel]); 
Inside the public OnPlayerDisconnect:

PHP Code:
        new name[MAX_PLAYER_NAME], yourfile[256];
        
GetPlayerName(playeridnameMAX_PLAYER_NAME);
        
format(yourfile256"insert here the file you want to save the level"name);
    
        if(!
DOF2_FileExists(yourfile))
    {
           
DOF2_CreateFile(yourfile);
    }
       
        
PlayerInfo[playerid][pLevel] = GetPlayerScore(playerid);
        
DOF2_SetInt(yourfile"Level"PlayerInfo[playerid][pLevel]);
        
DOF2_SaveFile(); 
Then, your command should look like this:

PHP Code:
CMD:bonus(playerid

    
    
PlayerInfo[playerid][pLevel] = GetPlayerScore(playerid); 
    if(
PlayerInfo[playerid][pLevel] == 1
    { 
        
SendClientMessage(playerid,-1,"Deoarece ai folosit comanda /bonus ai primit:"); 
        
SendClientMessage(playerid,-1,"-LEVEL: 3"); 
        
SendClientMessage(playerid,-1,"-MONEY: $5.000.000"); 
        
GivePlayerMoney(playerid,5000000); 
        
SetPlayerScore(playerid3); 
        
PlayerInfo[playerid][pLevel] = 3;
    } 
    else 
    { 
        
SendClientMessage(playerid,-1,"Trebuie sa ai minim level 1 pentru a folosi aceasta comanda."); 
    } 
     return 
1

I have not tested it, but hope it works for you, if you get errors, just show me the line.
Reply
#5

@SnakePit what the hell? Why are you setting player's level based on fetched score, then setting it again to 3? Also whats all that file saving part? You don't even know which saving system is using the OP...
Reply
#6

Quote:
Originally Posted by KeyOfKey
View Post
@SnakePit what the hell? Why are you setting player's level based on fetched score, then setting it again to 3? Also whats all that file saving part? You don't even know which saving system is using the OP...
He was supposed to replace it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)