28.01.2012, 17:18
I have written a simple house system which loads/saves data from/to a MySQL database. Below is the code which loads the data and places it into the variables.
Here is the enum for the house variables:
Here is the code which show's the TDs to the player when they enter the houses CP.
The problem is that houseVars[h][hHousePrice] is supposed to equal 3000, which I have verified to be correct using some prints. However, the variable houseVars[h][hHousePrice] prints 4, not 3000. This happens with the three variables following hHousePrice in the enum as well, except instead of them equaling what they should ( 0 ), they equal "1". Anybody know what could cause this?
pawn Код:
case D_THREAD_LOADHOUSES:
{
mysql_store_result();
if(mysql_num_rows() < 1)
return 1;
new szTmpString[35];
while(mysql_retrieve_row())
{
mysql_fetch_field_row(szTmpString, "houseID");
new h = strlen(szTmpString);
mysql_fetch_field_row(szTmpString, "houseInterior");
houseVars[h][hHouseInterior] = strlen(szTmpString);
mysql_fetch_field_row(szTmpString, "houseExterior");
houseVars[h][hHouseExterior] = strlen(szTmpString);
mysql_fetch_field_row(szTmpString, "houseVirtualWorld");
houseVars[h][hHouseVirtualWorld] = strlen(szTmpString);
mysql_fetch_field_row(szTmpString, "housePosX");
houseVars[h][hHousePosition][0] = floatstr(szTmpString);
mysql_fetch_field_row(szTmpString, "housePosY");
houseVars[h][hHousePosition][1] = floatstr(szTmpString);
mysql_fetch_field_row(szTmpString, "housePosZ");
houseVars[h][hHousePosition][2] = floatstr(szTmpString);
mysql_fetch_field_row(szTmpString, "houseIntPosX");
houseVars[h][hHouseIntPosition][0] = floatstr(szTmpString);
mysql_fetch_field_row(szTmpString, "houseIntPosY");
houseVars[h][hHouseIntPosition][1] = floatstr(szTmpString);
mysql_fetch_field_row(szTmpString, "houseIntPosZ");
houseVars[h][hHouseIntPosition][2] = floatstr(szTmpString);
mysql_fetch_field_row(szTmpString, "houseIntPosRotation");
houseVars[h][hHouseIntPosition][3] = floatstr(szTmpString);
print(szTmpString);
printf("%f", houseVars[h][hHouseIntPosition][3]);
mysql_fetch_field_row(houseVars[h][hHouseOwner], "houseOwner");
mysql_fetch_field_row(houseVars[h][hHouseDescription], "houseDesc");
mysql_fetch_field_row(houseVars[h][hHouseAddress], "houseAddress");
mysql_fetch_field_row(szTmpString, "housePrice");
houseVars[h][hHousePrice] = strlen(szTmpString);
print(szTmpString);
printf("%d", houseVars[h][hHousePrice]);
mysql_fetch_field_row(szTmpString, "houseSold");
houseVars[h][hHouseSold] = strlen(szTmpString);
print(szTmpString);
printf("%d", houseVars[h][hHouseSold]);
mysql_fetch_field_row(szTmpString, "houseRentPrice");
houseVars[h][hHouseRentPrice] = strlen(szTmpString);
print(szTmpString);
printf("%d", houseVars[h][hHouseRentPrice]);
mysql_fetch_field_row(szTmpString, "houseLocked");
houseVars[h][hHouseLocked] = strlen(szTmpString);
print(szTmpString);
printf("%d", houseVars[h][hHouseLocked]);
if(houseVars[h][hHouseSold] == 1)
{
houseVars[h][hHouseScriptID] = CreateDynamicCP(houseVars[h][hHousePosition][0], houseVars[h][hHousePosition][1], houseVars[h][hHousePosition][2], 1.0, -1, -1, -1, 15.0);
CreateDynamicMapIcon(houseVars[h][hHousePosition][0], houseVars[h][hHousePosition][1], houseVars[h][hHousePosition][2], 32, -1, -1, -1, -1, 30.0);
}
else
{
houseVars[h][hHouseScriptID] = CreateDynamicCP(houseVars[h][hHousePosition][0], houseVars[h][hHousePosition][1], houseVars[h][hHousePosition][2], 1.0, -1, -1, -1, 15.0);
CreateDynamicMapIcon(houseVars[h][hHousePosition][0], houseVars[h][hHousePosition][1], houseVars[h][hHousePosition][2], 31, -1, -1, -1, -1, 30.0);
}
iTotalHouses++;
}
mysql_free_result();
}
pawn Код:
enum houseEnum
{
hHouseID, // default value: N/A
hHouseScriptID, // default value: N/A
hHouseInterior, // default value: -1
hHouseExterior, // default value: 0
hHouseVirtualWorld, // default value: 0
Float:hHousePosition[3], // default value: 0.0
Float:hHouseIntPosition[4], // default value: 0.0
hHouseOwner[25], // default value: "NULL"
hHouseDescription[23], // default value: "NULL"
hHouseAddress[28], // default value: "NULL"
hHousePrice, // default value: 3000
hHouseSold, // default value: 0
hHouseRentPrice, // default value: 0
hHouseLocked // default value: 0
};
new houseVars[MAX_HOUSES][houseEnum];
pawn Код:
new Text:houseSalesListingTD[6][MAX_PLAYERS];
public OnPlayerEnterDynamicCP(playerid, checkpointid) // only works for DYNAMIC checkpoints
{
for(new h = 0; h < iTotalHouses; h++)
{
h = h+1;
if(checkpointid == houseVars[h][hHouseScriptID])
{
if(houseVars[h][hHouseSold] == 1)
{
if(GetPVarInt(playerid, "houseSaleTDS") != 1)
{
printf("houseVars[h][hHousePrice] == %d", houseVars[h][hHousePrice]);
showHouseSaleTDS(playerid);
SendClientMessage(playerid, -1, "This house is up for sale. To purchase it, please type \"/housepurchase\".");
new szTmpString[60];
format(szTmpString, sizeof(szTmpString), "~w~Description: %s", houseVars[h][hHouseDescription]);
TextDrawSetString(houseSalesListingTD[2][playerid], szTmpString);
format(szTmpString, sizeof(szTmpString), "~w~Address: %s", houseVars[h][hHouseAddress]);
TextDrawSetString(houseSalesListingTD[3][playerid], szTmpString);
format(szTmpString, sizeof(szTmpString), "~w~Price: ~g~$~w~%d", houseVars[h][hHousePrice]);
TextDrawSetString(houseSalesListingTD[4][playerid], szTmpString);
TextDrawSetString(houseSalesListingTD[5][playerid], "~w~Addons: ~p~COMING SOON");
SetPVarInt(playerid, "houseSaleTDS", 1);
}
}
}
}
return 1;
}
public OnPlayerLeaveDynamicCP(playerid, checkpointid)
{
if(GetPVarInt(playerid, "houseSaleTDS") == 1)
{
hideHouseSaleTDS(playerid);
DeletePVar(playerid, "houseSaleTDS");
}
return 1;
}