24.06.2012, 04:50
I have made a house system but its not saving or loading anything.
Code:
stock CreateHouse(cijena, Float:X, Float:Y, Float:Z, Float:kIntX, Float:kIntY, Float:kIntZ, adresa[], intid) { new Field[16], DBResult:Result; new Query[128], i, string[64]; new DBResult:qresult; qresult = db_query(Database,"SELECT * FROM `HOUSES`"); format(Query,sizeof(Query),"%d", db_num_rows(qresult)); format(string, sizeof string, "%d", i); print(string); HouseInfo[i][ID] = i+1; HouseInfo[i][Cijena] = cijena; HouseInfo[i][kX] = X; HouseInfo[i][kY] = Y; HouseInfo[i][kZ] = Z; HouseInfo[i][IntX] = kIntX; HouseInfo[i][IntY] = kIntY; HouseInfo[i][IntZ] = kIntZ; HouseInfo[i][Interior] = intid; db_free_result(qresult); format(Query, sizeof(Query), "INSERT INTO `HOUSES` ( 'ID', 'NAPRODAJU', 'VLASNIK', 'CIJENA', ADRESA', 'X', 'Y', 'Z', 'INZX', 'INTY', 'INTZ', 'MATS', 'DROGA', 'NOVAC', 'BRAVA', 'INT', 'RENTABIL', 'RENT', 'ALARM') VALUES('%s','%s')", DB_Escape(HouseInfo[i][ID]), 0); db_query(Database, Query); format(Query, sizeof(Query), "UPDATE `HOUSES` SET VLASNIK = '0', CIJENA = '%d', ADRESA = '%s', X = '%f', Y = '%f', Z = '%f' WHERE `ID` = '%d' ", HouseInfo[i][Cijena], adresa, HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ], HouseInfo[i][ID]); db_query(Database, Query); format(Query, sizeof(Query), "UPDATE `HOUSES` SET INTX = '%f', INTY = '%f', INTZ = '%f', MATS = '%d', DROGA = '%d', NOVAC = '%d', BRAVA = '%d', NAPRODAJU = '1' WHERE `ID` = '%d' ", HouseInfo[i][IntX], HouseInfo[i][IntY], HouseInfo[i][IntZ], HouseInfo[i][kMats], HouseInfo[i][kDroga], HouseInfo[i][kNovac], HouseInfo[i][Brava], HouseInfo[i][ID]); db_query(Database, Query); format(Query, sizeof(Query), "UPDATE `HOUSES` SET INT = '%d', RENTABIL = '%d', RENT = '%d', ALARM = '%d' WHERE `ID` = '%d' ", HouseInfo[i][Interior], HouseInfo[i][Rentabil], HouseInfo[i][Rent], HouseInfo[i][Alarm], HouseInfo[i][ID]); db_query(Database, Query); db_get_field_assoc(Result, "ADRESA", Field, 30); HouseInfo[i][Adresa] = strval(Field); LoadHouse(HouseInfo[i][ID]); format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Kuca na PRODAJU!\n"ZELENA"Adresa: "BIJELA"%s\n"ZELENA"Cijena: "BIJELA"$%i",HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa],HouseInfo[i][Cijena]); HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,LIGHTBLUE,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+0.1,15.0,0,1); return 1; }
Code:
stock LoadHouse(i) { new Query[150], Field[16], DBResult:Result, string[64]; format(Query, sizeof(Query), "SELECT * FROM `HOUSES` WHERE `ID` = '%d'", i); Result = db_query(Database, Query); format(string, sizeof string, "%s", i); print(string); if(db_num_rows(Result)) { HouseInfo[i][ID] = i; db_get_field_assoc(Result, "NAPRODAJU", Field, 30); HouseInfo[i][KucaNaProdaju] = strval(Field); db_get_field_assoc(Result, "VLASNIK", Field, 30); HouseInfo[i][Vlasnik] = strval(Field); db_get_field_assoc(Result, "CIJENA", Field, 30); HouseInfo[i][Cijena] = strval(Field); db_get_field_assoc(Result, "VRSTAKUCE", Field, 30); HouseInfo[i][VrstaKuce] = strval(Field); db_get_field_assoc(Result, "ADRESA", Field, 30); HouseInfo[i][Adresa] = strval(Field); db_get_field_assoc(Result, "X", Field, 30); HouseInfo[i][kX] = strval(Field); db_get_field_assoc(Result, "Y", Field, 30); HouseInfo[i][kY] = strval(Field); db_get_field_assoc(Result, "Z", Field, 30); HouseInfo[i][kZ] = strval(Field); db_get_field_assoc(Result, "INTX", Field, 30); HouseInfo[i][IntX] = strval(Field); db_get_field_assoc(Result, "INTY", Field, 30); HouseInfo[i][IntY] = strval(Field); db_get_field_assoc(Result, "INTZ", Field, 30); HouseInfo[i][IntZ] = strval(Field); db_get_field_assoc(Result, "MATS", Field, 30); HouseInfo[i][kMats] = strval(Field); db_get_field_assoc(Result, "DROGA", Field, 30); HouseInfo[i][kDroga] = strval(Field); db_get_field_assoc(Result, "NOVAC", Field, 30); HouseInfo[i][kNovac] = strval(Field); db_get_field_assoc(Result, "BRAVA", Field, 30); HouseInfo[i][Brava] = strval(Field); db_get_field_assoc(Result, "INT", Field, 30); HouseInfo[i][Interior] = strval(Field); db_get_field_assoc(Result, "RENTABIL", Field, 30); HouseInfo[i][Rentabil] = strval(Field); db_get_field_assoc(Result, "RENT", Field, 30); HouseInfo[i][Rent] = strval(Field); db_get_field_assoc(Result, "ALARM", Field, 30); HouseInfo[i][Alarm] = strval(Field); if(HouseInfo[i][KucaNaProdaju] == 1) { format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Kuca na PRODAJU!\nOpis:"BIJELA" %s\n"ZELENA"Adresa: "BIJELA"%s\n"ZELENA"Cijena: "BIJELA"$%i",HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa],HouseInfo[i][Cijena]); HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,-1,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+1,30.0,0,1); } if(HouseInfo[i][KucaNaProdaju] == 0 && HouseInfo[i][Rentabil] == 1) { format(KucniLabel,sizeof(KucniLabel),""ZELENA"Vlasnik: {FFFFFF}%s\n"ZELENA"Rent: {FFFFFF}%d$\n"ZELENA"Adresa: "BIJELA"%s", HouseInfo[i][Vlasnik],HouseInfo[i][Rent],HouseInfo[i][Adresa]); HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel ,0x00FFFFAA,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+0.5,15.0, 0, 1); } else { format(KucniLabel, sizeof(KucniLabel), ""ZELENA"Vlasnik: "BIJELA"%s\n"ZELENA"Opis: "BIJELA"%s\n"ZELENA"Adresa: "BIJELA"%s",HouseInfo[i][Vlasnik],HouseInfo[i][VrstaKuce],HouseInfo[i][Adresa]); HouseInfo[i][LabelKuce] = Create3DTextLabel(KucniLabel,-1,HouseInfo[i][kX], HouseInfo[i][kY], HouseInfo[i][kZ]+1,30.0,0,1); } } return 1; }