18.02.2013, 09:31
It saves correctly but it isn't loading correctly. I can see how many Cocaine I got in the .cfg file but it doesen't load the right amount.
pawn Код:
enum playerDrug
{
Cocaine,
Heroin,
LSD,
MDMA,
Marijuana,
Methamphetamine,
OxyContin,
Needles,
Blunts
}
new DRUG_VARS[MAX_PLAYERS][playerDrug];
stock SaveDrugsv2()
{
new Z;
new File: file2;
Z = 0;
while (Z < sizeof(DRUG_VARS))
{
new coordsstring[255];
format(coordsstring, sizeof(coordsstring), "%d,%d,%d,%d,%d,%d,%d,%d,%d\n",
DRUG_VARS[Z][Cocaine],
DRUG_VARS[Z][Heroin],
DRUG_VARS[Z][LSD],
DRUG_VARS[Z][MDMA],
DRUG_VARS[Z][Marijuana],
DRUG_VARS[Z][Methamphetamine],
DRUG_VARS[Z][OxyContin],
DRUG_VARS[Z][Needles],
DRUG_VARS[Z][Blunts]);
if(Z == 1)
{
file2 = fopen("playerdrug.cfg", io_write);
}
else
{
file2 = fopen("playerdrug.cfg", io_append);
}
fwrite(file2, coordsstring);
Z++;
fclose(file2);
}
print("Player drugs saved succesfully");
}
stock LoadDrugsv2()
{
new dinfo[15][128];
new string[256];
new File: file = fopen("playerdrug.cfg", io_read);
if (file)
{
new Z = 0;
while (Z < sizeof(DRUG_VARS))
{
fread(file, string);
split(string, dinfo, ',');
DRUG_VARS[Z][Cocaine] = strval(dinfo[1]);
DRUG_VARS[Z][Heroin] = strval(dinfo[2]);
DRUG_VARS[Z][LSD] = strval(dinfo[3]);
DRUG_VARS[Z][MDMA] = strval(dinfo[4]);
DRUG_VARS[Z][Marijuana] = strval(dinfo[5]);
DRUG_VARS[Z][Methamphetamine] = strval(dinfo[6]);
DRUG_VARS[Z][OxyContin] = strval(dinfo[7]);
DRUG_VARS[Z][Needles] = strval(dinfo[8]);
DRUG_VARS[Z][Blunts] = strval(dinfo[9]);
Z++;
}
}
print("Player Drugs loaded successfully.");
return 1;
}
pawn Код:
public OnGameModeExit()
{
SaveDrugsv2();
return true;
}
pawn Код:
public OnGameModeInit()
{
LoadDrugsv2();
return true;
}