[Problem]: Ladesystem von Häuser

Wichtiger Hinweis: Bitte ändert nicht manuell die Schriftfarbe auf schwarz sondern belasst es bei der Standardeinstellung. Somit tragt ihr dazu bei dass euer Text auch bei Verwendung unseren dunklen Forenstils noch lesbar ist!

Tipp: Ihr wollt längere Codeausschnitte oder Logfiles bereitstellen? Benutzt unseren eigenen PasteBin-Dienst Link
  • Guten Abend,
    es gibt ein Problem mit mein Haussystem und zwar wenn Ich ein Haus gekauft habe und danach den Server neustarte steht in den Textlabel's das es den Staat gehört.


    Hier der Callback von "LoadHouse":

    Function LoadHouse()
    {
    new query[256];
    HouseAnz = 0;
    format(query,sizeof(query),"SELECT * FROM "HouseTable"");
    mysql_query(query);
    mysql_store_result();
    for(new i; i < mysql_num_rows(); i++)
    {
    mysql_data_seek(i+1);
    mysql_fetch_string(query);
    mysql_fetch_field("HouseId",query); HouseInfo[i][hId] = strval(query);
    mysql_fetch_field("EnterX",query); HouseInfo[i][hEntX] = floatstr(query);
    mysql_fetch_field("EnterY",query); HouseInfo[i][hEntY] = floatstr(query);
    mysql_fetch_field("EnterZ",query); HouseInfo[i][hEntZ] = floatstr(query);


    HouseInfo[i][hOwnerId] = -1;


    mysql_fetch_field("Level",query); HouseInfo[i][hLevel] = strval(query);
    mysql_fetch_field("Inte",query); HouseInfo[i][hInt] = strval(query);
    mysql_fetch_field("VWorld",query); HouseInfo[i][hVWorld] = strval(query);
    mysql_fetch_field("Price",query); HouseInfo[i][hPrice] = strval(query);
    mysql_fetch_field("hLock",query); HouseInfo[i][hLock] = strval(query);
    mysql_fetch_field("Rent",query); HouseInfo[i][hRent] = strval(query);
    mysql_fetch_field("Rentable",query); HouseInfo[i][hRent] = strval(query);
    mysql_fetch_field("Money",query); HouseInfo[i][hMoney] = strval(query);
    mysql_fetch_field("Health",query); HouseInfo[i][hHealth] = strval(query);



    HouseInfo[i][hExists] = true;
    new tmp[2][4];
    mysql_fetch_field("Gun1",query);
    splitter(query,tmp,',');
    if(strlen(tmp[0]) != 0 && strlen(tmp[1]) != 0)
    {
    HouseInfo[i][hGun1] = strval(tmp[0]); HouseInfo[i][hGun1Ammo] = strval(tmp[1]);
    }
    mysql_fetch_field("Gun2",query);
    splitter(query,tmp,',');
    if(strlen(tmp[0]) != 0 && strlen(tmp[1]) != 0)
    {
    HouseInfo[i][hGun2] = strval(tmp[0]); HouseInfo[i][hGun2Ammo] = strval(tmp[1]);
    }
    mysql_fetch_field("Gun3",query);
    splitter(query,tmp,',');
    if(strlen(tmp[0]) != 0 && strlen(tmp[1]) != 0)
    {
    HouseInfo[i][hGun3] = strval(tmp[0]); HouseInfo[i][hGun3Ammo] = strval(tmp[1]);
    }
    HouseAnz++;
    }
    mysql_free_result();
    new houseId;
    format(query,sizeof(query),"SELECT HouseKey,UserId FROM "AccTable" WHERE HouseKey IS NOT NULL AND NOT '-1'");
    mysql_query(query);
    mysql_store_result();
    for(new a; a < mysql_num_rows(); a++)
    {
    mysql_data_seek(a);
    houseId = mysql_fetch_int();
    printf("For New a: %i",mysql_fetch_int());
    for(new h; h < HouseAnz; h++)
    {
    if(HouseInfo[h][hId] == houseId)
    {
    mysql_fetch_field("UserId",query);
    HouseInfo[h][hOwnerId] = strval(query);
    h = HouseAnz;
    }
    }
    }
    for(new house; house < HouseAnz ; house++)
    HouseUpdate(house,"Icon");
    mysql_free_result();
    }


    und der Callback von "HouseUpdate":

    HouseUpdate(Id,option[])
    {
    new query[256];
    if(!strcmp(option,"Icon",true))
    {
    if(HousePickup[Id] != -1)
    {
    Delete3DTextLabel(HouseLabel[Id]);
    DestroyPickup(HousePickup[Id]);
    }
    if(HouseInfo[Id][hOwnerId] != -1)
    {
    new Name[MAX_PLAYER_NAME];
    format(query,sizeof(query),"SELECT UserName FROM `"AccTable"` WHERE UserId = '%d' LIMIT 1",HouseInfo[Id][hOwnerId]);
    mysql_query(query);
    mysql_store_result();
    mysql_fetch_string(Name);
    mysql_free_result();
    format(query,sizeof(query),"%s{FF6633}Besitzer{FFFFFF}: %s\n",GetHouseName(Id),Name);
    if(HouseInfo[Id][hRentable])
    {
    format(query,sizeof(query),"%s{FF6633}Mietbar:{FFFFFF} Ja\n{FF0000}Miete{FFFFFF}: %d\n",query,HouseInfo[Id][hRent]);
    format(query,sizeof(query),"%s{FF6633}/Rent{FFFFFF} zum einmieten ",query,HouseInfo[Id][hRent]);
    }
    format(query,sizeof(query),"%s{FF6633}/Enter{FFFFFF} zum betreten",query,HouseInfo[Id][hRent]);
    HousePickup[Id] = CreatePickup(1239,23,HouseInfo[Id][hEntX], HouseInfo[Id][hEntY], HouseInfo[Id][hEntZ], -1);
    HouseLabel[Id] = Create3DTextLabel(query, COLOR_WHITE, HouseInfo[Id][hEntX], HouseInfo[Id][hEntY], HouseInfo[Id][hEntZ] + 0.2, 20.0, 0, 0);
    }
    else
    {
    format(query,sizeof(query),"%s{FF6633}Besitzer{FFFFFF}: Der Staat\n{FF6633}Preis{FFFFFF}: %d\n{FF6633}Level{FFFFFF}: %d\n{FF6633}/Buyhouse{FFFFFF} zum Kauf",GetHouseName(Id),HouseInfo[Id][hPrice],HouseInfo[Id][hLevel]);
    HousePickup[Id] = CreatePickup(1273,23,HouseInfo[Id][hEntX], HouseInfo[Id][hEntY], HouseInfo[Id][hEntZ], -1);
    HouseLabel[Id] = Create3DTextLabel(query, COLOR_WHITE, HouseInfo[Id][hEntX], HouseInfo[Id][hEntY], HouseInfo[Id][hEntZ] + 0.2, 20.0, 0, 0);
    }
    }
    if(!strcmp(option,"OwnerId",true))
    {
    HouseUpdate(Id,"Icon");
    }
    else if(!strcmp(option,"Level",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Level` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hLevel],HouseInfo[Id][hId]);
    mysql_query(query);
    HouseUpdate(Id,"Icon");
    }
    else if(!strcmp(option,"Int",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Inte` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hInt],HouseInfo[Id][hId]);
    mysql_query(query);
    HouseUpdate(Id,"Icon");
    }
    else if(!strcmp(option,"Price",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Price` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hPrice],HouseInfo[Id][hId]);
    mysql_query(query);
    HouseUpdate(Id,"Icon");
    }
    else if(!strcmp(option,"Lock",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `hLock` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hLock],HouseInfo[Id][hId]);
    mysql_query(query);
    HouseUpdate(Id,"Icon");
    }
    else if(!strcmp(option,"Rent",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Rent` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hRent],HouseInfo[Id][hId]);
    mysql_query(query);
    HouseUpdate(Id,"Icon");
    }
    else if(!strcmp(option,"Rentable",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Rentable` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hRentable],HouseInfo[Id][hId]);
    mysql_query(query);
    HouseUpdate(Id,"Icon");
    }
    else if(!strcmp(option,"Money",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Money` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hMoney],HouseInfo[Id][hId]);
    mysql_query(query);
    }
    else if(!strcmp(option,"Health",true))
    {
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Health` = '%d' WHERE HouseId = '%d'",HouseInfo[Id][hHealth],HouseInfo[Id][hId]);
    mysql_query(query);
    }
    else if(!strcmp(option,"Gun",true))
    {
    new Gun1[32],Gun2[32],Gun3[32];
    format(Gun1,32,"%d,%d",HouseInfo[Id][hGun1],HouseInfo[Id][hGun1Ammo]);
    format(Gun2,32,"%d,%d",HouseInfo[Id][hGun2],HouseInfo[Id][hGun2Ammo]);
    format(Gun3,32,"%d,%d",HouseInfo[Id][hGun3],HouseInfo[Id][hGun3Ammo]);
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Gun1` = '%s', `Gun2` = '%s', `Gun3` = '%s' WHERE HouseId = '%d'",Gun1,Gun2,Gun3,HouseInfo[Id][hId]);
    mysql_query(query);
    }
    else if(!strcmp(option,"All",true))
    {
    new Gun1[32],Gun2[32],Gun3[32];
    format(Gun1,32,"%d,%d",HouseInfo[Id][hGun1],HouseInfo[Id][hGun1Ammo]);
    format(Gun2,32,"%d,%d",HouseInfo[Id][hGun2],HouseInfo[Id][hGun2Ammo]);
    format(Gun3,32,"%d,%d",HouseInfo[Id][hGun3],HouseInfo[Id][hGun3Ammo]);
    format(query,sizeof(query),"UPDATE "HouseTable" SET `Level` = '%d', `Inte` = '%d', `Price` = '%d', `hLock` = '%d', `Rent` = '%d',",HouseInfo[Id][hLevel],HouseInfo[Id][hInt],HouseInfo[Id][hPrice],HouseInfo[Id][hLock],HouseInfo[Id][hRent]);
    format(query,sizeof(query),"%s `Rentable` = '%d', `Money` = '%d', `Gun1` = '%s', `Gun2` = '%s', `Gun3` = '%s' WHERE HouseId = '%d'",query,HouseInfo[Id][hRentable],HouseInfo[Id][hMoney],Gun1,Gun2,Gun3, HouseInfo[Id][hId]);
    mysql_query(query);
    HouseUpdate(Id,"Icon");
    }
    }


    Ich hoffe das Ihr mir weiterhelfen könnt.

  • Stehen in der Tabelle "AccTable" bei HouseKey und UserId die richtigen Werte drin, nachdem du das Haus gekauft hast und den Server beendet hast?
    Wenn ja, was gibt dir der Code so im Log aus?
    Function LoadHouse()
    {
    new query[256];
    HouseAnz = 0;
    format(query,sizeof(query),"SELECT * FROM "HouseTable"");
    mysql_query(query);
    mysql_store_result();
    for(new i; i < mysql_num_rows(); i++)
    {
    mysql_data_seek(i+1);
    mysql_fetch_string(query);
    mysql_fetch_field("HouseId",query); HouseInfo[i][hId] = strval(query);
    mysql_fetch_field("EnterX",query); HouseInfo[i][hEntX] = floatstr(query);
    mysql_fetch_field("EnterY",query); HouseInfo[i][hEntY] = floatstr(query);
    mysql_fetch_field("EnterZ",query); HouseInfo[i][hEntZ] = floatstr(query);
    HouseInfo[i][hOwnerId] = -1;
    mysql_fetch_field("Level",query); HouseInfo[i][hLevel] = strval(query);
    mysql_fetch_field("Inte",query); HouseInfo[i][hInt] = strval(query);
    mysql_fetch_field("VWorld",query); HouseInfo[i][hVWorld] = strval(query);
    mysql_fetch_field("Price",query); HouseInfo[i][hPrice] = strval(query);
    mysql_fetch_field("hLock",query); HouseInfo[i][hLock] = strval(query);
    mysql_fetch_field("Rent",query); HouseInfo[i][hRent] = strval(query);
    mysql_fetch_field("Rentable",query); HouseInfo[i][hRent] = strval(query);
    mysql_fetch_field("Money",query); HouseInfo[i][hMoney] = strval(query);
    mysql_fetch_field("Health",query); HouseInfo[i][hHealth] = strval(query);
    HouseInfo[i][hExists] = true;
    new tmp[2][4];
    mysql_fetch_field("Gun1",query);
    splitter(query,tmp,',');
    if(strlen(tmp[0]) != 0 && strlen(tmp[1]) != 0)
    {
    HouseInfo[i][hGun1] = strval(tmp[0]); HouseInfo[i][hGun1Ammo] = strval(tmp[1]);
    }
    mysql_fetch_field("Gun2",query);
    splitter(query,tmp,',');
    if(strlen(tmp[0]) != 0 && strlen(tmp[1]) != 0)
    {
    HouseInfo[i][hGun2] = strval(tmp[0]); HouseInfo[i][hGun2Ammo] = strval(tmp[1]);
    }
    mysql_fetch_field("Gun3",query);
    splitter(query,tmp,',');
    if(strlen(tmp[0]) != 0 && strlen(tmp[1]) != 0)
    {
    HouseInfo[i][hGun3] = strval(tmp[0]); HouseInfo[i][hGun3Ammo] = strval(tmp[1]);
    }
    HouseAnz++;
    }
    mysql_free_result();
    printf("Starte Laden der Besitzer");
    new houseId;
    format(query,sizeof(query),"SELECT HouseKey,UserId FROM "AccTable" WHERE HouseKey IS NOT NULL AND NOT '-1'");
    mysql_query(query);
    mysql_store_result();
    printf("%d rows", mysql_num_rows());
    for(new a; a < mysql_num_rows(); a++)
    {
    mysql_data_seek(a);
    houseId = mysql_fetch_int();
    printf("House ID: %i",houseId);
    for(new h; h < HouseAnz; h++)
    {
    printf("House %d hat ID: %d", h, HouseInfo[h][hId]);
    if(HouseInfo[h][hId] == houseId)
    {
    printf("Match. Setze User zu: %d", HouseInfo[h][hOwnerId]);
    mysql_fetch_field("UserId",query);
    HouseInfo[h][hOwnerId] = strval(query);
    h = HouseAnz;
    break;
    }
    }
    }
    mysql_free_result();
    for(new house; house < HouseAnz ; house++) HouseUpdate(house,"Icon");
    printf("Fertig.");
    return 1;
    }

  • Hi, bin ein Kollege von ihm, es kommt nur das:
    Starte Laden der Besitzer
    0 rows
    Fertig.


    //Edit haben das SELECT geändert und nun kommt das:

    Starte Laden der Besitzer
    2 rows
    House ID: 4
    House 0 hat ID: 4
    Match. Setze User zu: -1
    House ID: 5
    House 0 hat ID: 4
    House 1 hat ID: 5
    Match. Setze User zu: -1
    Fertig.

    Einmal editiert, zuletzt von SlashQ ()

  • Haben den SELECT Befehl geändert er ist nun :
    format(query,sizeof(query),"SELECT HouseKey,UserId FROM "AccTable" WHERE HouseKey IS NOT NULL AND HouseKey != -1");


    vorher:
    format(query,sizeof(query),"SELECT HouseKey,UserId FROM "AccTable" WHERE HouseKey");