Loading Factions MySQL, Assistance please.
#1

Quote:

stock LoadFactions()
{
new QueryString[ 128 ];
mysql_query( "SELECT `FactionName`, `FactionRank1`,`FactionRank2`, `FactionRank3`, `FactionRank4`, `FactionRank5`, `FactionRank6`, `FactionSkin1`, `FactionSkin2`, `FactionSkin3`, `FactionSkin4`, `FactionSkin5`, `FactionSkin6`, `FactionSkin7`, `FactionSkin8`, `FactionSkin9`, `FactionSkin10`, `FactionEntX`, `FactionEntY`, `FactionEntZ`, `FactionIntX`, `FactionIntY`, `FactionIntZ`, `FactionInt`, `FactionID`, `FactionBank` FROM `Factions`");
mysql_store_result();

if( mysql_num_rows() >= 1 )
{
{
mysql_fetch_field( "FactionName", QueryString );
FactionName[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionRank1", QueryString );
FactionRank1[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionRank2", QueryString );
FactionRank2[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionRank3", QueryString );
FactionRank3[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionRank4", QueryString );
FactionRank4[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionRank5", QueryString );
FactionRank5[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionRank6", QueryString );
FactionRank6[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionRank7", QueryString );
FactionRank7[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin1", QueryString );
FactionSkin1[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin2", QueryString );
FactionSkin2[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin3", QueryString );
FactionSkin3[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin4", QueryString );
FactionSkin4[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin5", QueryString );
FactionSkin5[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin6", QueryString );
FactionSkin6[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin7", QueryString );
FactionSkin7[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin8", QueryString );
FactionSkin8[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin9", QueryString );
FactionSkin9[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionSkin10", QueryString );
FactionSkin10[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionEntX", QueryString );
FactionEntX[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "FactionEntY", QueryString );
FactionEntY[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "FactionEntZ", QueryString );
FactionEntZ[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "FactionIntX", QueryString );
FactionIntX[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "FactionIntY", QueryString );
FactionIntY[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "FactionIntZ", QueryString );
FactionIntZ[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "SpawnX", QueryString );
SpawnX[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "SpawnY", QueryString );
SpawnY[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "SpawnZ", QueryString );
SpawnZ[FactionSQLID] = floatstr( QueryString );

mysql_fetch_field( "FactionInt", QueryString );
FactionInt[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionID", QueryString );
FactionID[FactionSQLID] = strval( QueryString );

mysql_fetch_field( "FactionBank", QueryString );
FactionBank[FactionSQLID] = strval( QueryString );
mysql_query( QueryString );
}
}
mysql_free_result();

return 1;
}

This is the part of the code where I actually load it.

Quote:

new FactionSQLID[MAX_FACTIONS];
new FactionName[MAX_FACTIONS];
new FactionRank1[MAX_FACTIONS];
new FactionRank2[MAX_FACTIONS];
new FactionRank3[MAX_FACTIONS];
new FactionRank4[MAX_FACTIONS];
new FactionRank5[MAX_FACTIONS];
new FactionRank6[MAX_FACTIONS];
new FactionRank7[MAX_FACTIONS];
new FactionSkin1[MAX_FACTIONS];
new FactionSkin2[MAX_FACTIONS];
new FactionSkin3[MAX_FACTIONS];
new FactionSkin4[MAX_FACTIONS];
new FactionSkin5[MAX_FACTIONS];
new FactionSkin6[MAX_FACTIONS];
new FactionSkin7[MAX_FACTIONS];
new FactionSkin8[MAX_FACTIONS];
new FactionSkin9[MAX_FACTIONS];
new FactionSkin10[MAX_FACTIONS];
new Float:FactionIntX[MAX_FACTIONS];
new Float:FactionIntY[MAX_FACTIONS];
new Float:FactionIntZ[MAX_FACTIONS];
new Float:FactionEntX[MAX_FACTIONS];
new Float:FactionEntY[MAX_FACTIONS];
new Float:FactionEntZ[MAX_FACTIONS];

Dont ask why I dont use Enum, It makes this MUCH easier to understand.

Quote:

error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(887) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(88 : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(890) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(891) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(893) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(894) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(896) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(897) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(899) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(900) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(902) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(903) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(905) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(906) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(90 : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(909) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(911) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(912) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(914) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(915) : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(917) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(91 : error 033: array must be indexed (variable "FactionSQLID")
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(920) : error 035: argument type mismatch (argument 1)
C:\Users\berni\Desktop\Zombie Mode\gamemodes\rp.pwn(921) : error 033: array must be indexed (variable "FactionSQLID")

I cannot figure out what this means, if someone could explain it clearly, I would be much obliged, and yes, I'm scripting from scratch.
Reply
#2

Well there's your problem, you're trying to assign an integer to an array, if you're trying to store it in a specific cell, then you need to specify the cell in which to store it. Also what's with the extra brackets?

I recommend you check up on the PAWN documentation over at Compuphase which will teach you the basics.

http://www.compuphase.com/pawn/pawn.htm

I'd rather not give you the answer straight up because then you won't really be learning anything, if you read the documentation and start from the beginning, then you will understand the problem, as this is quite a basic problem.

Note: Even if you didn't have errors, your code would not work like this at all, not the way you're intending it to work.
Reply
#3

Thank you very much, I am learning, I've been doing so for a while now, Its just faction, vehicle and business loading is the issues, however, once I've learned the factions, it shouldnt be too difficult, may I ask you one thing?

Say I wanted to set an owner of a vehicle? How would it work, as in, how would it set the playername to that vehicle id in the database? Would you give me an example of code please? and I will learn from it.
Reply
#4

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Thank you very much, I am learning, I've been doing so for a while now, Its just faction, vehicle and business loading is the issues, however, once I've learned the factions, it shouldnt be too difficult, may I ask you one thing?

Say I wanted to set an owner of a vehicle? How would it work, as in, how would it set the playername to that vehicle id in the database? Would you give me an example of code please? and I will learn from it.
That all depends on the names of the tables, columns and so on...I can't really give a rough example from something that vague.

Although I will give you an example based on the code above, which you can learn from and apply to your code:

pawn Код:
// Lets say for example, we want to load information from our table which contains two rows.

new level[2], kills[2], result[10], count;

mysql_query("SELECT level, kills FROM `users`"); // Execute the query to retrieve the information you want from the table "users"
mysql_store_result(); // Store the result

while(mysql_fetch_result(result)) // Importantly, we are getting more than a single row, so we need to call this function a few times in order to get all of the information.
{
    print(result); // This will print out level|kills for each row, with the information in each column as level and kills

    sscanf(result, "p<|>ii", level[count], kills[count]); // Here we are telling sscanf to split the string by | and that it will be splitting 2 integers, then storing them in the level/kill arrays in the appropriate cell, which is what count is for.

    count++; // We increment the count variable by 1 because we've used a cell in each of the arrays.
}

mysql_free_result(); // Make sure to free the result.
I hope that simple example helps you adapt your code.
Reply
#5

Thanks very much for the help! Helped a lot.

Still having issues.
Reply
#6

Here is how I load factions, maybe this can help you, because right now your scrpt looks huge
pawn Код:
LoadFaction()
{
    CheckConnection();
    new Field[128],row[1024],idx;
    mysql_query( "SELECT * FROM `factions` ORDER BY `id` ASC" );
    mysql_store_result();
    for(new i = 0; i < sizeof(Finfo); i++ )
    {
        idx = 0;
        mysql_fetch_row(row);
        Field = strtuk(row,idx,'|');
        for(new s = -1; s < 17; s++ )
        {
            switch(s)
            {
                case 0: Finfo[i][Freq] = strval(Field);
                case 1: strmid(Finfo[i][Name],Field, 0, strlen(Field), 255);
                case 2: strmid(Finfo[i][FullName],Field, 0, strlen(Field), 255);
                case 3: Finfo[i][FX] = floatstr(Field);
                case 4: Finfo[i][FY] = floatstr(Field);
                case 5: Finfo[i][FZ] = floatstr(Field);
                case 6: Finfo[i][FR] = floatstr(Field);
                case 7: Finfo[i][VW] = strval(Field);
                case 8: Finfo[i][Int] = strval(Field);
                case 9: Finfo[i][Dis] = strval(Field);
                case 10: Finfo[i][EID] = strval(Field);
                case 11: Finfo[i][Zone] = strval(Field);
                case 12: Finfo[i][Gang] = strval(Field);
                case 13: Finfo[i][Team] = strval(Field);
                case 14: Finfo[i][AutoFreq] = strval(Field);
                case 15: Finfo[i][FSkins] = strval(Field);
                case 16: strmid(Finfo[i][Leader],Field, 0, strlen(Field), 255);
            }
            Field = strtuk(row,idx, '|' );
        }
    }
    mysql_free_result();
    print("  Factions from MySQL loaded.");
    return 1;
}
SaveFaction(id)
{
    CheckConnection();
    new string[256],query[512],esc[64];
    format(string,sizeof(string), "UPDATE `factions` SET `Freq` = '%d',",Finfo[id][Freq]); strcat(query,string);
    mysql_real_escape_string(Finfo[id][Name],esc);
    format(string,sizeof(string), " `Name` = '%s',",esc); strcat(query,string);
    mysql_real_escape_string(Finfo[id][FullName],esc);
    format(string,sizeof(string), " `FullName` = '%s',",esc); strcat(query,string);
    format(string,sizeof(string), " `FX` = '%0.2f',",Finfo[id][FX]); strcat(query,string);
    format(string,sizeof(string), " `FY` = '%0.2f',",Finfo[id][FY]); strcat(query,string);
    format(string,sizeof(string), " `FZ` = '%0.2f',",Finfo[id][FZ]); strcat(query,string);
    format(string,sizeof(string), " `FR` = '%0.2f',",Finfo[id][FR]); strcat(query,string);
    format(string,sizeof(string), " `VW` = '%d',",Finfo[id][VW]); strcat(query,string);
    format(string,sizeof(string), " `Int` = '%d',",Finfo[id][Int]); strcat(query,string);
    format(string,sizeof(string), " `Dis` = '%d',",Finfo[id][Dis]); strcat(query,string);
    format(string,sizeof(string), " `EID` = '%d',",Finfo[id][EID]); strcat(query,string);
    format(string,sizeof(string), " `Zone` = '%d',",Finfo[id][Zone]); strcat(query,string);
    format(string,sizeof(string), " `Gang` = '%d',",Finfo[id][Gang]); strcat(query,string);
    format(string,sizeof(string), " `Team` = '%d',",Finfo[id][Team]); strcat(query,string);
    format(string,sizeof(string), " `AutoFreq` = '%d',",Finfo[id][AutoFreq]); strcat(query,string);
    format(string,sizeof(string), " `FSkins` = '%d'",Finfo[id][FSkins]); strcat(query,string);
    format(string,sizeof(string), " WHERE `id` = '%d'",id); strcat(query,string);
    mysql_query(query);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)