#define MAX_PVAR_NAME 24
#define MAX_PVAR_LENGTH 64
#define PVAR_LENGTH_COMBO MAX_PVAR_LENGTH+MAX_PVAR_NAME+10
stock SavePVars(playerid)
{
new tmp[PVAR_LENGTH_COMBO],File:file,pvar,index;
GetPlayerName(playerid,tmp,24);
format(tmp,PVAR_LENGTH_COMBO,"Accounts/%s.samp",tmp);
printf("Saving PVars at \"%s\" -- PlayerID=%d",tmp,playerid);
file=fopen(tmp,io_write);
index=GetPVarsUpperIndex(playerid);
while(pvar<index)
{
GetPVarNameAtIndex(playerid,pvar,tmp,MAX_PVAR_NAME);
switch(GetPVarType(playerid,tmp))
{
case PLAYER_VARTYPE_STRING:
{
new tmp2[MAX_PVAR_LENGTH];
GetPVarString(playerid,tmp,tmp2,MAX_PVAR_LENGTH);
format(tmp,PVAR_LENGTH_COMBO,"STRING %s%c%s\n",tmp,1,tmp2);
fwrite(file,tmp);
}
case PLAYER_VARTYPE_INT:
{
new tmp2;
tmp2=GetPVarInt(playerid,tmp);
format(tmp,PVAR_LENGTH_COMBO,"INT %s%c%d\n",tmp,1,tmp2);
fwrite(file,tmp);
}
case PLAYER_VARTYPE_FLOAT:
{
new Float:tmp2;
tmp2=GetPVarFloat(playerid,tmp);
format(tmp,PVAR_LENGTH_COMBO,"FLOAT %s%c%f\n",tmp,1,tmp2);
fwrite(file,tmp);
}
}
pvar++;
}
print("Successful");
fclose(file);
}
stock LoadPVars(playerid)
{
new tmp[PVAR_LENGTH_COMBO],File:file;
new tmp2[MAX_PVAR_LENGTH];
new spacer[2];
format(spacer,2,"%c",1);
GetPlayerName(playerid,tmp,24);
format(tmp,PVAR_LENGTH_COMBO,"Accounts/%s.samp",tmp);
if(!fexist(tmp))return printf("Loading \"%s\" failed -- PlayerID=%d",tmp,playerid);
printf("Loading PVars from \"%s\" -- PlayerID=%d",tmp,playerid);
file=fopen(tmp,io_read);
fread(file,tmp);
while(tmp[0])
{
if(!strcmp(tmp,"STRING",false,6))
{
strmid(tmp2,tmp,strfind(tmp,spacer)+1,strlen(tmp)-1);
strmid(tmp,tmp,7,strfind(tmp,spacer));
SetPVarString(playerid,tmp,tmp2);
}
if(!strcmp(tmp,"INT ",false,6))
{
strmid(tmp2,tmp,strfind(tmp,spacer)+1,strlen(tmp)-1,MAX_PVAR_LENGTH);
strmid(tmp,tmp,7,strfind(tmp,spacer),MAX_PVAR_LENGTH);
SetPVarInt(playerid,tmp,strval(tmp2));
}
if(!strcmp(tmp,"FLOAT ",false,6))
{
strmid(tmp2,tmp,strfind(tmp,spacer)+1,strlen(tmp)-1,MAX_PVAR_LENGTH);
strmid(tmp,tmp,7,strfind(tmp,spacer),MAX_PVAR_LENGTH);
SetPVarFloat(playerid,tmp,floatstr(tmp2));
}
fread(file,tmp);
}
print("Successful");
fclose(file);
return 1;
}
Originally Posted by Seif_
What's with the massive array size?
|