Y_INI saving problem
#1

I'm trying to save player's info. Well, The code isn't working. I join the game, And since my user file doesn't exists, It is supposed to create a new file. And it doesn't look like it saves. Here's my code:

PHP код:
#define MAX_OWNABLE_VEHICLES 5
#define USERS_PATH "/EVO/users/%s.ini"
enum pInfo {
    
bool:pAllowed,
    
pTotalVehs,
    
pVSlot[MAX_OWNABLE_VEHICLES-1]
}
stock UserPath(playerid) {
    new 
path[64], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
format(pathsizeof(path), USERS_PATHname);
    return 
name;
}
public 
LoadUser_data(playerid,name[],value[])
{
    
printf("Read %s: %s"namevalue);
    
    
INI_Bool("allowed"PlayerInfo[playerid][pAllowed]);
    
INI_Int("totalvehs"PlayerInfo[playerid][pTotalVehs]);
    for(new 
0MAX_OWNABLE_VEHICLESi++) {
        new 
vslot[10];
        
format(vslotsizeof(vslot), "slot%d"i);
        
INI_Int(vslotPlayerInfo[playerid][pVSlot][i]);
    }
     return 
1;
}
public 
OnPlayerConnect(playerid)
{
    if(
fexist(UserPath(playerid)))
    {
        
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
    }
    else
    {
         new 
INI:File INI_Open(UserPath(playerid));
         
INI_SetTag(File,"data");
        
INI_WriteBool(File"allowed"PlayerInfo[playerid][pAllowed]);
        
INI_WriteInt(File"totalvehs"PlayerInfo[playerid][pTotalVehs]);
        for(new 
0MAX_OWNABLE_VEHICLESi++) {
            new 
vslot[10];
            
format(vslotsizeof(vslot), "slot%d"i);
            
INI_WriteInt(FilevslotPlayerInfo[playerid][pVSlot][i]);
        }    
        
INI_Close(File);
    }
    return 
1;
}
public 
OnPlayerDisconnect(playeridreason)
{
    new 
INI:File INI_Open(UserPath(playerid));
    
INI_SetTag(File,"data");
    
INI_WriteBool(File"allowed"PlayerInfo[playerid][pAllowed]);
    
INI_WriteInt(File"totalvehs"PlayerInfo[playerid][pTotalVehs]);
    for(new 
0MAX_OWNABLE_VEHICLESi++) {
        new 
vslot[10];
        
format(vslotsizeof(vslot), "slot%d"i);
        
INI_WriteInt(FilevslotPlayerInfo[playerid][pVSlot][i]);
    }    
    
INI_Close(File);
    return 
1;

EDIT: Okay, I've just seen something. It saves but it saves it directly to my scriptfiles folder. And it doesn't have the .ini extension, nor does it have any data. I'm sure that I have all the necessary folder created for the path.

Reply
#2

B.U.M.P
Reply
#3

Your UserPath function returns the name of the player instead of the path:
PHP код:
stock UserPath(playerid) { 
    new 
path[64], name[MAX_PLAYER_NAME]; 
    
GetPlayerName(playeridnamesizeof(name)); 
    
format(pathsizeof(path), USERS_PATHname); 
    return 
path

Reply
#4

Thanks Andy, It creates the file now.

But nothing gets saved in the file. It's empty.
Reply
#5

Something tells me your script is crashing in some part. Try using crashdetect.
Reply
#6

Yeah, You're right. I loaded Crashdetect and I got this:

Код:
[23:20:18] [debug] Run time error 4: "Array index out of bounds"
[23:20:18] [debug] AMX backtrace:
[23:20:18] [debug] #0 0005165c in public SSCANF_OnPlayerDisconnect (0, 1) from EVO.amx
[23:20:18] [debug] #1 00046f38 in public _y_utils_OnPlayerDisconnect (0, 1) from EVO.amx
[23:20:18] [debug] #2 000078b0 in public OnPlayerDisconnect (0, 1) from EVO.amx
I never used the plugin and I have no idea what it means. :/

EDIT: I got the same thing in OnPlayerConnect as well.
Reply
#7

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
Yeah, You're right. I loaded Crashdetect and I got this:

Код:
[23:20:18] [debug] Run time error 4: "Array index out of bounds"
[23:20:18] [debug] AMX backtrace:
[23:20:18] [debug] #0 0005165c in public SSCANF_OnPlayerDisconnect (0, 1) from EVO.amx
[23:20:18] [debug] #1 00046f38 in public _y_utils_OnPlayerDisconnect (0, 1) from EVO.amx
[23:20:18] [debug] #2 000078b0 in public OnPlayerDisconnect (0, 1) from EVO.amx
I never used the plugin and I have no idea what it means. :/

EDIT: I got the same thing in OnPlayerConnect as well.
Try using debug level 3, so it shows you the exact lines that produce the crash.
If you don't know how to do that, here's how:
You should create a file called pawn.cfg in your pawno folder, inside this file write:
PHP код:
-d3 
Save the file and recompile your script and run it with crashdetect again.


EDIT:
I just checked your script and noticed this:

PHP код:
enum pInfo 
    
bool:pAllowed
    
pTotalVehs
    
pVSlot[MAX_OWNABLE_VEHICLES-1

The array running out of bounds is pVSlot[MAX_OWNABLE_VEHICLES-1] once you perform a loop.
Thus, in order to fix that, just change the code posted to:

PHP код:
enum pInfo 
    
bool:pAllowed
    
pTotalVehs
    
pVSlot[MAX_OWNABLE_VEHICLES//The problem was here.

Reply
#8

Код:
[23:35:55] [debug] Run time error 4: "Array index out of bounds"
[23:35:55] [debug] AMX backtrace:
[23:35:55] [debug] #0 0005d6e8 in public SSCANF_OnPlayerConnect (playerid=0) at D:\SAMP\filterscripts\EVO.pwn:811
[23:35:55] [debug] #1 00050d50 in public _y_utils_OnPlayerConnect (playerid=0) at D:\SAMP\pawno\include\sscanf2.inc:205
[23:35:55] [debug] #2 00008ce0 in public OnPlayerConnect (playerid=0) at D:\SAMP\pawno\include\YSI\..\YSI_Storage\..\YSI_Core\y_utils.inc:236
I think it says on Line 811:

PHP код:
for(new 0MAX_OWNABLE_VEHICLESi++) {
            new 
vslot[10];
            
format(vslotsizeof(vslot), "slot%d"i);
            
INI_WriteInt(FilevslotPlayerInfo[playerid][pVSlot][i]); // line 811
        

Reply
#9

Quote:
Originally Posted by DarkSkull
Посмотреть сообщение
Код:
[23:35:55] [debug] Run time error 4: "Array index out of bounds"
[23:35:55] [debug] AMX backtrace:
[23:35:55] [debug] #0 0005d6e8 in public SSCANF_OnPlayerConnect (playerid=0) at D:\SAMP\filterscripts\EVO.pwn:811
[23:35:55] [debug] #1 00050d50 in public _y_utils_OnPlayerConnect (playerid=0) at D:\SAMP\pawno\include\sscanf2.inc:205
[23:35:55] [debug] #2 00008ce0 in public OnPlayerConnect (playerid=0) at D:\SAMP\pawno\include\YSI\..\YSI_Storage\..\YSI_Core\y_utils.inc:236
I think it says on Line 811:

PHP код:
for(new 0MAX_OWNABLE_VEHICLESi++) {
            new 
vslot[10];
            
format(vslotsizeof(vslot), "slot%d"i);
            
INI_WriteInt(FilevslotPlayerInfo[playerid][pVSlot][i]); // line 811
        

Check what I posted above, I edited.
Reply
#10

OMG, Thanks a lot. It worked
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)