SQLite wont load table?
#1

I got the saving part down(finally!) I moved on to my next thing to save/load which is my factions, they are dynamically created with a command. When you create the faction, the info saves to the table, but my stock won't execute it, and I fucked something up cause it wont print the Query!

pawn Код:
stock LoadFaction(ID)
    {
    new Query[600], string[100], DBResult: Result;
    format(Query, sizeof(Query), "SELECT * FROM `FACTIONS` WHERE `ID` = %d", ID);
    Result = db_query(survival, Query);
    if(db_num_rows(Result))
        {
        new Field[30];
        db_get_field_assoc(Result, "NAME", Field, 30);
        FactionInfo[ID][fName] = Field;
        db_get_field_assoc(Result, "ID", Field, 30);
        FactionInfo[ID][fID] = strval(Field);
        db_get_field_assoc(Result, "INTX", Field, 30);
        FactionInfo[ID][fHQintX] = strval(Field);
        db_get_field_assoc(Result, "INTY", Field, 30);
        FactionInfo[ID][fHQintY] = strval(Field);
        db_get_field_assoc(Result, "INTZ", Field, 30);
        FactionInfo[ID][fHQintZ] = strval(Field);
        db_get_field_assoc(Result, "EXTX", Field, 30);
        FactionInfo[ID][fHQextX] = strval(Field);
        db_get_field_assoc(Result, "EXTY", Field, 30);
        FactionInfo[ID][fHQextY] = strval(Field);
        db_get_field_assoc(Result, "EXTZ", Field, 30);
        FactionInfo[ID][fHQextZ] = strval(Field);
        db_get_field_assoc(Result, "VW", Field, 30);
        FactionInfo[ID][fHQVW] = strval(Field);
        db_get_field_assoc(Result, "INT", Field, 30);
        FactionInfo[ID][fHQint] = strval(Field);
        db_get_field_assoc(Result, "CREATED", Field, 30);
        FactionInfo[ID][fCreated] = strval(Field);
        return 1;
        }
    db_free_result(Result);
    print(Query);
    format(string, sizeof(string), "Faction ID %d loaded successfully", ID);
    print(string);
    return 1;
    }
pawn Код:
stock LoadAllFactions()
{
    for(new i = 0; i < 10; i++)
    {
        if(FactionInfo[i][fCreated] == 1)
        {
            LoadFaction(i);
        }
    }
}
Reply
#2

Quote:
Originally Posted by Mattakil
Посмотреть сообщение
I fucked something up cause it wont print the Query!
because you got return 1; under FactionInfo[ID][fCreated] = strval(Field);
Reply
#3

didnt fix it
Reply
#4

pawn Код:
stock LoadFaction(ID)
{
    new Query[60], DBResult:Result;
    format(Query, sizeof(Query), "SELECT * FROM `FACTIONS` WHERE `ID` = %d LIMIT 1", ID);
    Result = db_query(survival, Query);
    if(db_num_rows(Result))
    {
        new Field[30];
        db_get_field_assoc(Result, "NAME", Field, 30);
        FactionInfo[ID][fName] = Field;
        db_get_field_assoc(Result, "ID", Field, 30);
        FactionInfo[ID][fID] = strval(Field);
        db_get_field_assoc(Result, "INTX", Field, 30);
        FactionInfo[ID][fHQintX] = floatstr(Field);
        db_get_field_assoc(Result, "INTY", Field, 30);
        FactionInfo[ID][fHQintY] = floatstr(Field);
        db_get_field_assoc(Result, "INTZ", Field, 30);
        FactionInfo[ID][fHQintZ] = floatstr(Field);
        db_get_field_assoc(Result, "EXTX", Field, 30);
        FactionInfo[ID][fHQextX] = floatstr(Field);
        db_get_field_assoc(Result, "EXTY", Field, 30);
        FactionInfo[ID][fHQextY] = floatstr(Field);
        db_get_field_assoc(Result, "EXTZ", Field, 30);
        FactionInfo[ID][fHQextZ] = floatstr(Field);
        db_get_field_assoc(Result, "VW", Field, 30);
        FactionInfo[ID][fHQVW] = strval(Field);
        db_get_field_assoc(Result, "INT", Field, 30);
        FactionInfo[ID][fHQint] = strval(Field);
        db_get_field_assoc(Result, "CREATED", Field, 30);
        FactionInfo[ID][fCreated] = strval(Field);
    }
    db_free_result(Result);
    print(Query);
    return printf("Faction ID %d loaded successfully", ID);
}
and it should be

pawn Код:
if(FactionInfo[i][fCreated] == 0)
?
Reply
#5

I just realized that my /factions command suddenly doesnt work, when I posted this, if you did /createfac, it would show the faction Name and ID, now it doesn't even do it if you create a new faction? (Note: player's faction on spawn is 0, therefore there is a faction called "None" set for ID 0 and it bypasses that.

pawn Код:
CMD:factions(playerid, params[])
    {
    SCM(pid, COLYELLOW, "Factions");
    new index = 0, string[100];
    for(new i = 0; i < 10; i++)
        {
        if(FactionInfo[i][fID] == 0)
            {
            return 1;
            }
        else
            {
            format(string, sizeof(string), "ID %d: %s", FactionInfo[i][fID], FactionInfo[i][fName]);
            SCM(pid, COLGREY, string);
            index++;
            return 1;
            }
        }
    return 1;
    }
Reply
#6

pawn Код:
CMD:factions(playerid, params[])
{
    SCM(pid, COLYELLOW, "Factions");
    new string[100];
    for(new i = 0; i < 10; i++)
    {
        if(FactionInfo[i][fID] == 0) continue;

        format(string, sizeof(string), "ID %d: %s", FactionInfo[i][fID], FactionInfo[i][fName]);
        SCM(pid, COLGREY, string);
    }
    return 1;
}
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
CMD:factions(playerid, params[])
{
    SCM(pid, COLYELLOW, "Factions");
    new string[100];
    for(new i = 0; i < 10; i++)
    {
        if(FactionInfo[i][fID] == 0) continue;

        format(string, sizeof(string), "ID %d: %s", FactionInfo[i][fID], FactionInfo[i][fName]);
        SCM(pid, COLGREY, string);
    }
    return 1;
}
pid to playerid.
Reply
#8

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pid to playerid.
SCM==sendclientmessage

pid == playerid
Reply
#9

I did some playing with the loadall and saveall and got it all to work perfectly Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)