public farmsLoad(){ new query[128]; mysql_format(mysql, query, sizeof(query), "SELECT * FROM
farms_info`");
mysql_query(mysql, query);
for(new i = 0;i < cache_get_row_count(); i++){
printf("Sodyba %d buvo uzkrauta !", i);
FARM[i][ID] = cache_get_field_content_int(0, "number");
cache_get_field_content(0, "OwnerName", FARM[i][fOWNER], mysql, MAX_PLAYER_NAME);
FARM[i][hLEVEL] = cache_get_field_content_int(0, "Level");
FARM[i][hUpgrapadeTime] = cache_get_field_content_int(0, "UgrapadeTime");
FARM[i][fPRICE] = cache_get_field_content_int(0, "Price");
FARM[i][fPlantations] = cache_get_field_content_int(0, "Plantations");
FARM[i][fPlantation][0] = cache_get_field_content_int(0, "Plantation1");
FARM[i][fPlantation][1] = cache_get_field_content_int(0, "Plantation2");
FARM[i][fPlantation][2] = cache_get_field_content_int(0, "Plantation3");
FARM[i][fPlantation][3] = cache_get_field_content_int(0, "Plantation4");
FARM[i][fCow][0] = cache_get_field_content_int(0, "fCow");
FARM[i][POSX] = cache_get_field_content_float(0, "posX");
FARM[i][POSY] = cache_get_field_content_float(0, "posY");
FARM[i][POSZ] = cache_get_field_content_float(0, "posZ");
CreatePickup(19524, 1, FARM[i][POSX], FARM[i][POSY], FARM[i][POSZ], -1);
for (new p = 0; p < FARM[i][fPlantations]; ++p)
{
if(FARM[i][fPlantation][p] == 1){
CreateObject(19454, housesFarms[i][firstPlantationX], housesFarms[i][firstPlantationY], housesFarms[i][firstPlantationZ], 0.00000, housesFarms[i][firstPlantationAngle], 0.00000);
printf("%f %f %f PIRMA PLANTACIJA", housesFarms[i][firstPlantationX], housesFarms[i][firstPlantationY], housesFarms[i][firstPlantationZ]);
CreateObject(19454, housesFarms[i][secondPlantationX], housesFarms[i][secondPlantationY], housesFarms[i][secondPlantationZ], 0.00000, housesFarms[i][secondPlantationAngle], 0.00000);
printf("%f %f %f ANTRA PLANTACIJA", housesFarms[i][secondPlantationX], housesFarms[i][secondPlantationY], housesFarms[i][secondPlantationZ]);
CreateObject(19454, housesFarms[i][thirdPlantationX], housesFarms[i][thirdPlantationY], housesFarms[i][thirdPlantationZ], 0.00000, housesFarms[i][thirdPlantationAngle], 0.00000);
printf("%f %f %f TRECUA PLANTACIJA", housesFarms[i][thirdPlantationX], housesFarms[i][thirdPlantationY], housesFarms[i][thirdPlantationZ]);
CreateObject(19454, housesFarms[i][fourthPlantationX], housesFarms[i][fourthPlantationY], housesFarms[i][fourthPlantationZ], 0.00000, housesFarms[i][fourthPlantationAngle], 0.00000);
printf("%f %f %f KETVIRTA PLANTACIJA", housesFarms[i][fourthPlantationX], housesFarms[i][fourthPlantationY], housesFarms[i][fourthPlantationZ]);
}
}
printf("%d\n", FARM[i][hLEVEL]);
printf("%d nr, %d ID, %f x, %f y, %f Z", i,housesFarms[i][firstHouseId], housesFarms[i][firstHouseX], housesFarms[i][firstHouseY], housesFarms[i][firstHouseZ]);
switch(FARM[i][hLEVEL]){
case 1: FARM[i][fHouseObject] = CreateObject(housesFarms[i][firstHouseId], housesFarms[i][firstHouseX], housesFarms[i][firstHouseY], housesFarms[i][firstHouseZ], housesFarms[i][firstHouserX], housesFarms[i][firstHouserY], housesFarms[i][firstHouserZ]), printf("veikiu 1");
case 2: FARM[i][fHouseObject] = CreateObject(housesFarms[i][secondHouseId], housesFarms[i][firstHouseX], housesFarms[i][firstHouseY], housesFarms[i][firstHouseZ], housesFarms[i][firstHouserX], housesFarms[i][firstHouserY], housesFarms[i][firstHouserZ]), printf("veikiu 2");
}
new Float:x, Float:y, Float:z;
GetObjectPos(FARM[i][fHouseObject], x, y, z);
printf("%f X %f Y %f Z %d", x, y, z, GetObjectPos(FARM[i][fHouseObject], x, y, z));
}
}`
[15:04:29] Sodyba 0 buvo uzkrauta !
[15:04:29] 734.582519 -491.351501 15.096199 PIRMA PLANTACIJA
[15:04:29] 741.082519 -491.351501 15.096199 ANTRA PLANTACIJA
[15:04:29] 747.582519 -491.351501 15.096199 TRECUA PLANTACIJA
[15:04:29] 754.082519 -491.351501 0.000000 KETVIRTA PLANTACIJA
[15:04:29] 734.582519 -491.351501 15.096199 PIRMA PLANTACIJA
[15:04:29] 741.082519 -491.351501 15.096199 ANTRA PLANTACIJA
[15:04:29] 747.582519 -491.351501 15.096199 TRECUA PLANTACIJA
[15:04:29] 754.082519 -491.351501 0.000000 KETVIRTA PLANTACIJA
[15:04:29] 734.582519 -491.351501 15.096199 PIRMA PLANTACIJA
[15:04:29] 741.082519 -491.351501 15.096199 ANTRA PLANTACIJA
[15:04:29] 747.582519 -491.351501 15.096199 TRECUA PLANTACIJA
[15:04:29] 754.082519 -491.351501 0.000000 KETVIRTA PLANTACIJA
[15:04:29] 1
[15:04:29] 0 nr, 0 ID, 0.000000 x, 0.000000 y, 0.000000 Z
[15:04:29] veikiu 1
[15:04:29] 0.000000 X 0.000000 Y 0.000000 Z 1
Kažkaip durnai kraunu tas plantacijas, bet vis tiek, įdomu kodėl ketvirtosios grybauja Z koordinatė ir namas neužsikrauna. @Bebras
Bebras prieš 8 metus
Na namas neatsiranda tai dėl to nes housesFarms[i][firstHouseId]
lygus 0, bent pagal log'ą. Kodėl ketvirtos plantacijos z koordinatė neveikia nežinau.
Siūlyčiau perdaryti sistemą, neatrodo kaip geras dizainas....
Bebras prieš 8 metus
Sunku pasakyt. Ar plantacijų skaičius ribotas? Ar jų koordinatės visada bus vienodas kad esi sukišęs į enumą?
Galbūt DB būtų ir geriausias sprendimas, bet taip pat ir su kitokia struktūra nei dabar, neturėtų būti tokių stulpelių kaip plantacija1
, plantacija2
, plantacija3
, plantacija4
. MySQL yra ryšinė(relational) duomenų bazė.
create table if not exists farms
(
id int auto_increment not null,
# Visi FARM atributai
);
create table if not exists farm_plantations
(
id int auto_increment not null,
farm_id int not null,
# Visi plantacijai reikalingi atributai
foreign key(farm_id) references farms(id) on delete cascade
);```
Ta `FOREIGN KEY` eilutė, neleis plantacijai egzistuoti be fermos. O kadangi `farm_plantations` yra atskira lentelė, viena ferma gali turėti jų nuo 0 iki begalybės. Paimti visus šiuos duomenis netgi gali viena užklausa: `select * from farms left join farm_plantations on farms.id = farm_plantations.farm_id`. Tačiau tokiu atveju stipriai pasunkėja krovimas Pawn dalyje :(