Error in LoadOrg stock
#1

Lately, I have been creating a dynamic faction system which doesn't load the org. There are no errors in the script. Here is a debug code.

By the way, we can organizations/orgs instead of faction.

Код:
[10:22:31] CMySQLHandler::Query(SELECT * FROM `orgs` WHERE `ID` = '1') - Successfully executed.

[10:22:31] >> mysql_num_rows( Connection handle: 1 )

[10:22:31] CMySQLHandler::NumRows() - You cannot call this function now. (Reason: Dead Connection)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(X) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(Y) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(Z) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(INTERIOR) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(NAME) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(COLOR) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(LEADER) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(SKIN1) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(SKIN2) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(SKIN3) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(WEAPON1) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(WEAPON2) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(WEAPON3) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:31] >> mysql_fetch_field_row( Connection handle: 1 )

[10:22:31] CMySQLHandler::FetchField(BANK) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[10:22:56] >> mysql_query( Connection handle: 1 )
And this conflicts in the stock LoadOrgs

Here's the code.

pawn Код:
stock LoadOrgs()
{
    new id = 1;
    while(id < MAX_ORGS)
    {
        format(Query,sizeof(Query),"SELECT * FROM `orgs` WHERE `ID` = '%d'",id);
        mysql_query(Query);
        if(mysql_num_rows())
        {
           
            mysql_fetch_field_row(data,"X");
            OrgInfo[id][oX] = floatstr(data);
            mysql_fetch_field_row(data,"Y");
            OrgInfo[id][oY] = floatstr(data);
            mysql_fetch_field_row(data,"Z");
            OrgInfo[id][oZ] = floatstr(data);
            mysql_fetch_field_row(data,"INTERIOR");
            OrgInfo[id][oInt] = strval(data);
            mysql_fetch_field_row(data,"NAME");
            format(OrgInfo[id][oName],128,"%s",data);
            mysql_fetch_field_row(data,"COLOR");
            format(OrgInfo[id][oColor],11,"%s",data);
            mysql_fetch_field_row(data,"LEADER");
            format(OrgInfo[id][oLeader],24,"%s",data);
            mysql_fetch_field_row(data,"SKIN1");
            OrgInfo[id][oSkin][0] = strval(data);
            mysql_fetch_field_row(data,"SKIN2");
            OrgInfo[id][oSkin][1] = strval(data);
            mysql_fetch_field_row(data,"SKIN3");
            OrgInfo[id][oSkin][2] = strval(data);
            mysql_fetch_field_row(data,"WEAPON1");
            OrgInfo[id][oWeapon][0] = strval(data);
            mysql_fetch_field_row(data,"WEAPON2");
            OrgInfo[id][oWeapon][1] = strval(data);
            mysql_fetch_field_row(data,"WEAPON3");
            OrgInfo[id][oWeapon][2] = strval(data);
            mysql_fetch_field_row(data,"BANK");
            OrgInfo[id][oBank] = strval(data);
            CreateOrg(OrgInfo[id][oX],OrgInfo[id][oY],OrgInfo[id][oZ],OrgInfo[id][oInt],OrgInfo[id][oName],OrgInfo[id][oColor],OrgInfo[id][oWeapon][0],OrgInfo[id][oWeapon][1],OrgInfo[id][oWeapon][2],OrgInfo[id][oSkin][0],OrgInfo[id][oSkin][1],OrgInfo[id][oSkin][2],OrgInfo[id][oType]);
            return 1;
        }
        id++;
    }
    mysql_free_result();
    return 1;
}
I can provide what ever code is needed.
Reply
#2

You never store the result (mysql_store_result).
Reply
#3

Stupid me!

But why does it say Field/Row is empty even after I put mysql_store_result?

Код:
[13:30:56] CMySQLHandler::Query(SELECT * FROM `orgs` WHERE `ID` = '1') - Successfully executed.

[13:30:56] >> mysql_store_result( Connection handle: 1 )

[13:30:56] CMySQLHandler::StoreResult() - Result was stored.

[13:30:56] >> mysql_num_rows( Connection handle: 1 )

[13:30:56] CMySQLHandler::NumRows() - Returned 1 row(s)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(X) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(Y) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(Z) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(INTERIOR) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(NAME) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(COLOR) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(LEADER) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(SKIN1) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(SKIN2) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(SKIN3) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(WEAPON1) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(WEAPON2) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(WEAPON3) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:30:56] >> mysql_fetch_field_row( Connection handle: 1 )

[13:30:56] CMySQLHandler::FetchField(BANK) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[13:31:16] >> mysql_query( Connection handle: 1 )
Reply
#4

I'd suggest you to use sscanf to load this kind of stuff, I will write a code how you could load it using sscanf,

EDIT

pawn Код:
stock LoadOrgs( )
{
    new id = 1;
    while( id < MAX_ORGS ) //Loop, checks all the slots, searching for data.
    {
        format( Query,sizeof ( Query ),"SELECT * FROM `orgs` WHERE `ID` = '%d'", id ); // Selects all the information from the table
        mysql_query( Query );

        mysql_store_result( );//stores the data after using SELECT.

        if( mysql_num_rows ( ) ) //if the row is not null.
        {
            if( mysql_fetch_row_format( Query,"|" ) )
            {
                sscanf(Query, "p<|>fffis[24]s[11]s[24]iiiiiii", OrgInfo[ id ][ oX ],  OrgInfo[ id ][ oY ], OrgInfo[ id ][ oZ ], OrgInfo[ id ][ oInt ], OrgInfo[ id ][ oName ], OrgInfo[ id ][ oColor ],
                OrgInfo[ id ][ oLeader ], OrgInfo[ id ][ oSkin ][ 0 ], OrgInfo[ id ][ oSkin ][ 1 ], OrgInfo[ id ][ oSkin ][ 2 ], OrgInfo[ id ][ oWeapon ][ 0 ], OrgInfo[id][oWeapon][ 1 ], OrgInfo[id][oWeapon][ 2 ],
                OrgInfo[ id ][ oBank ]); //seperates the data into variable, so you could use it.

                CreateOrg(OrgInfo[ id ][ oX ],OrgInfo[ id ][ oY ],OrgInfo[ id ][ oZ ],OrgInfo[ id ][ oInt ],OrgInfo[ id ][ oName ],OrgInfo[ id ][ oColor ],OrgInfo[ id ][ oWeapon ][ 0 ],OrgInfo[ id ][ oWeapon ][ 1 ],OrgInfo[ id ][ oWeapon ][ 2 ],
                OrgInfo[ id ][ oSkin ][ 0 ],OrgInfo[ id ][ oSkin ][ 1 ],OrgInfo[ d ][ oSkin ][ 2 ],OrgInfo[ id ][ oType ]);  //creates the organization, using the data that sscanf loaded
            }
        }
        i++;
    }
    return 1;
}
Explanation inside, sscanf version looks simple and neat, eh'?

"p<|>" = Delimiter. / Split's the string.
Reply
#5

Thanks man, sscanf was actually a good idea.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)