PDA

View Full Version : Level not save


Calinut200
24/06/2019, 07:03 PM
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
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);
PlayerInfo[playerid][pLevel] = SetPlayerScore(playerid,3);
}
else
{
SendClientMessage(playerid,-1,"Trebuie sa ai minim level 1 pentru a folosi aceasta comanda.");
}
return 1;
}

Symon
24/06/2019, 07:51 PM
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;
}

SiaReyes
24/06/2019, 07:53 PM
Fix of above code!

SetPlayerScore(playerid, GetPlayerScore(playerid)+3);
PlayerInfo[playerid][pLevel] = GetPlayerScore(playerid));

SnakePit
24/06/2019, 08:06 PM
After the player login is successful, place this:



new name[MAX_PLAYER_NAME], yourfile[256];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(yourfile, 256, "insert here the file you want to save the level", name);
PlayerInfo[playerid][pLevel] = DOF2_GetInt(yourfile,"Level");
SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);



Inside the public OnPlayerDisconnect:


new name[MAX_PLAYER_NAME], yourfile[256];
GetPlayerName(playerid, name, MAX_PLAYER_NAME);
format(yourfile, 256, "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:


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(playerid, 3);
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.

Symon
24/06/2019, 08:10 PM
@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...

SnakePit
24/06/2019, 08:16 PM
@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.