Toy saving and loading problem
#1

Hey guys,

I worked on a toy system, but I don't get what is wrong iwth this but I had finished working on it, tested it and it has problems loading and saving the system's, like I don't get what's wrong with it and it won't work properly, and gives me a lot of errors, not sure what is going on, here is the code:

Loading player stats:
pawn Код:
for(new x = 0; x <= 12; x++)
        {
            format(bstring, sizeof(bstring), "Bone_%d", x);
            PlayerToyInfo[playerid][x][ptBone] = cache_get_field_content_int(0, bstring);
            format(modelstring, sizeof(modelstring), "Model_%d", x);
            PlayerToyInfo[playerid][x][ptModelID] = cache_get_field_content_int(0, modelstring);
           
            format(posxstring, sizeof(posxstring), "PosX_%d", x);
            PlayerToyInfo[playerid][x][ptPosX] = cache_get_field_content_int(0, posxstring);
            format(posystring, sizeof(posystring), "PosY_%d", x);
            PlayerToyInfo[playerid][x][ptPosY] = cache_get_field_content_int(0, posystring);
            format(poszstring, sizeof(poszstring), "PosZ_%d", x);
            PlayerToyInfo[playerid][x][ptPosZ] = cache_get_field_content_int(0, poszstring);
            format(rotxstring, sizeof(rotxstring), "RotX_%d", x);
            PlayerToyInfo[playerid][x][ptRotX] = cache_get_field_content_int(0, rotxstring);
            format(rotystring, sizeof(rotystring), "RotY_%d", x);
            PlayerToyInfo[playerid][x][ptRotY] = cache_get_field_content_int(0, rotystring);
            format(rotzstring, sizeof(rotzstring), "RotZ_%d", x);
            PlayerToyInfo[playerid][x][ptRotZ] = cache_get_field_content_int(0, rotzstring);
            format(scaxstring, sizeof(scaxstring), "ScaX_%d", x);
            PlayerToyInfo[playerid][x][ptScaleX] = cache_get_field_content_int(0, scaxstring);
            format(scaystring, sizeof(scaystring), "ScaY_%d", x);
            PlayerToyInfo[playerid][x][ptScaleY] = cache_get_field_content_int(0, scaystring);
            format(scazstring, sizeof(scazstring), "ScaZ_%d", x);
            PlayerToyInfo[playerid][x][ptScaleZ] = cache_get_field_content_int(0, scazstring);
           
        }
Saving player stats:
pawn Код:
for(new x = 0; x <= 12; x++)
    {
        format(bstring, sizeof(bstring), "Bone_%d", x);
        format(modelstring, sizeof(modelstring), "Model_%d", x);
       
        format(Query, sizeof(Query), "UPDATE `playerdata` SET `%s` = %d, `%s` = %d WHERE `nick` = '%s' LIMIT 1",
        bstring,
        PlayerToyInfo[playerid][x][ptBone],
        modelstring,
        PlayerToyInfo[playerid][x][ptModelID],
        PlayerInfo[playerid][Nick]);
        mysql_tquery(mysql, Query, "", "");

        format(posxstring, sizeof(posxstring), "PosX_%d", x);
        format(posystring, sizeof(posystring), "PosY_%d", x);
        format(poszstring, sizeof(poszstring), "PosZ_%d", x);
        format(rotxstring, sizeof(rotxstring), "RotX_%d", x);
        format(rotystring, sizeof(rotystring), "RotY_%d", x);
        format(rotzstring, sizeof(rotzstring), "RotZ_%d", x);
        format(scaxstring, sizeof(scaxstring), "ScaX_%d", x);
        format(scaystring, sizeof(scaystring), "ScaY_%d", x);
        format(scazstring, sizeof(scazstring), "ScaZ_%d", x);
        format(Query, sizeof(Query), "UPDATE `playerdata` SET `%s` = %f, `%s` = %f, `%s` = %f, `%s` = %f, `%s` = %f, `%s` = %f, `%s` = %f, `%s` = %f WHERE `nick` = '%s' LIMIT 1",
        posxstring,
        PlayerToyInfo[playerid][x][ptPosX],
        posystring,
        PlayerToyInfo[playerid][x][ptPosY],
        poszstring,
        PlayerToyInfo[playerid][x][ptPosZ],
        rotxstring,
        PlayerToyInfo[playerid][x][ptRotX],
        rotystring,
        PlayerToyInfo[playerid][x][ptRotY],
        rotzstring,
        PlayerToyInfo[playerid][x][ptRotZ],
        scaxstring,
        PlayerToyInfo[playerid][x][ptScaleX],
        scaystring,
        PlayerToyInfo[playerid][x][ptScaleY],
        scazstring,
        PlayerToyInfo[playerid][x][ptScaleZ],
        PlayerInfo[playerid][Nick]);
        mysql_tquery(mysql, Query, "", "");
    }
Errors from the .exe (debug):
Код:
[17:56:38] [debug] Run time error 4: "Array index out of bounds"
[17:56:38] [debug] AMX backtrace:
[17:56:38] [debug] #0 000d5994 in public OnAccountLoad (playerid=0) at C:\Users\SugaryJesus\Desktop\Sapphire Gaming\SA-MP Server Files\Sever Files\gamemodes\bcrp-b2.pwn:6840
[18:02:26] [debug] Run time error 4: "Array index out of bounds"
[18:02:26] [debug] AMX backtrace:
[18:02:26] [debug] #0 000da414 in SavePlayer (playerid=0) at C:\Users\SugaryJesus\Desktop\Sapphire Gaming\SA-MP Server Files\Sever Files\gamemodes\bcrp-b2.pwn:7085
[18:02:26] [debug] #1 000a5bb8 in public SSCANF_OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\SugaryJesus\Desktop\Sapphire Gaming\SA-MP Server Files\Sever Files\gamemodes\bcrp-b2.pwn:2289
[18:02:26] [debug] #2 0003e698 in public _y_utils_OnPlayerDisconnect (playerid=0, reason=1) at C:\Users\SugaryJesus\Desktop\Sapphire Gaming\SA-MP Server Files\Sever Files\pawno\include\sscanf2.inc:260
[18:02:26] [debug] #3 000099cc in OnPlayerDisconnect (playerid=0, reason=1, ... <1073741821 arguments>) at C:\Users\SugaryJesus\Desktop\Sapphire Gaming\SA-MP Server Files\Sever Files\pawno\include\YSI\..\YSI_Storage\..\YSI_Core\y_utils.inc:254
[18:02:26] [debug] #4 0000c0f8 in public OnPlayerDisconnect (... <2 arguments>) at C:\Users\SugaryJesus\Desktop\Sapphire Gaming\SA-MP Server Files\Sever Files\pawno\include\YSI\..\YSI_Storage\..\YSI_Coding\..\YSI_Internal\y_cgen.inc:30
[18:02:26] [part] Blaine_McGregor has left the server (0:1)
Reply
#2

pawn Код:
[17:56:38] [debug] #0 000d5994 in public OnAccountLoad (playerid=0) at C:\Users\SugaryJesus\Desktop\Sapphire Gaming\SA-MP Server Files\Sever Files\gamemodes\bcrp-b2.pwn:6840
[18:02:26] [debug] Run time error 4: "Array index out of bounds"
This is what should concern you. Show the line 6840 of your bcrp-b2.pwn.
Reply
#3

PlayerToyInfo[playerid][x][ptBone] = cache_get_field_content_int(0, bstring);

This is the code it says is out of bounds
Reply
#4

Ok, show me your PlayerToyInfo definition. I suspect you only have 12 toy slots, yet your loop
pawn Код:
for(new x = 0; x <= 12; x++)
tries to access 13th, nonexistent slot
Reply
#5

pawn Код:
enum ptInfo
{
    ptModelID,
    ptBone,
    Float:ptPosX,
    Float:ptPosY,
    Float:ptPosZ,
    Float:ptRotX,
    Float:ptRotY,
    Float:ptRotZ,
    Float:ptScaleX,
    Float:ptScaleY,
    Float:ptScaleZ,
};
new PlayerToyInfo[MAX_PLAYERS][MAX_PLAYERTOYS][ptInfo];
Reply
#6

MAX_PLAYERTOYS - is it 12 or 13?
Reply
#7

It says 8 on it
Reply
#8

Well, there's your problem then. Change
pawn Код:
for(new x = 0; x <= 12; x++)
to
pawn Код:
for(new x = 0; x < MAX_PLAYERTOYS; x++)
if you want more than 8 player toys, increase MAX_PLAYERTOYS
Reply
#9

Tested it and it works! Thank you I would have never seen the for statement being the problem to the saving of my script!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)