Last id works functionally but not previous
#1

I have created 3 houses.
HouseID1,HOUSEID2,HOUSEID3
IF I BUY HOUSEID1 I CAN ENTER/EXIT CORRECTLY. THEN IF I BUY HOUSEID2(I HAVE ALREADY BOUGHT HOUSEID1 TOO) I CAN'T ENTER AT HOUSEID1 LIKE IT DOESN'T EXIST. THEN IF BUY HOUSEID3(ALREADY BOUGHT THE OTHER TWO) I CAN'T ENTER NEITHER HOUSEID2 NEITHER HOUSEID1 BUT I CAN AT HOUSEID3
What could cause the problem? when i try to enter at the other two it says that you are not near any house!
PHP код:
        else if(hid != INVALID_HOUSE_ID//enter house!
        
{
                if(
pinfo[playerid][ID] != HouseInfo[hid][HOwnerID] && HouseInfo[hid][HOwned] == 1) return SendClientMessage(playerid,-1,""COL_RED"SERVER"COL_WHITE":You can't enter the house since it's not yours");
                if(
pinfo[playerid][ID] == HouseInfo[hid][HOwnerID] && HouseInfo[hid][HOwned] == 1)
                {
                    
EnterHouse(playerid,hid);
                }
        } else return 
SendClientMessage(playerid,-1,"You're not near any house"); 
ENTER /exit FUNCTION
PHP код:
function EnterHouse(playerid,houseid)
{
            
SetPlayerPos(playerid,HouseInfo[houseid][XExit],HouseInfo[houseid][YExit],HouseInfo[houseid][ZExit]);
            
SetPlayerInterior(playerid,HouseInfo[houseid][HInterior]);
            
SetPlayerVirtualWorld(playerid,HouseInfo[houseid][HVirtualWorld]);
            
Loading(playerid);
            return 
1;
}
function 
ExitHouse(playerid,houseid)
{
            
SetPlayerPos(playerid,HouseInfo[houseid][XEnt],HouseInfo[houseid][YEnt],HouseInfo[houseid][ZEnt]);
            
SetPlayerDefaultWorld(playerid);
            return 
1;

gethouse id stock
PHP код:
stock GetHouseID(playerid)
{
    for(new 
i=1i<MAX_HOUSESi++)
    {
        if(
IsPlayerInRangeOfPoint(playerid2HouseInfo[i][XExit], HouseInfo[i][YExit], HouseInfo[i][ZExit]))
        {
            return 
i;
        }
        else if(
IsPlayerInRangeOfPoint(playerid2HouseInfo[i][XEnt], HouseInfo[i][YEnt], HouseInfo[i][ZEnt]))
        {
            return 
i;
        }
    }
    return 
INVALID_HOUSE_ID;

What could cause the problem?
Reply
#2

Any suggestion? D:
Reply
#3

When you load the houses does it load all of the ID's?
Reply
#4

It prints all yea
Reply
#5

Okay and how are you storing the ID? Show me the LoadHouses please.
Reply
#6

PHP код:
LoadHouses()
{
    new 
Cache:result,rows;
    new 
label[250];
    
result mysql_query(mysql"SELECT * FROM `houses`");
    if((
rows cache_num_rows()))
    {
        for(new 
i=0rowsi++)
        {
            
HouseInfo[i][XEnt] = cache_get_field_content_float(i"XEnt"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
            
HouseInfo[i][YEnt] = cache_get_field_content_float(i"YEnt"); //Above
            
HouseInfo[i][ZEnt] = cache_get_field_content_float(i"ZEnt");//Above
            
HouseInfo[i][XExit] = cache_get_field_content_float(i"XExit");//Above. Since player's position is a float, we use cache_get_field_content_float
            
HouseInfo[i][YExit] = cache_get_field_content_float(i"YExit");//Above
            
HouseInfo[i][ZExit] = cache_get_field_content_float(i"ZExit");//Above
            
HouseInfo[i][HVirtualWorld] = cache_get_field_content_int(i"HVirtualWorld");
            
HouseInfo[i][HInterior] = cache_get_field_content_int(i"HInterior");
            
HouseInfo[i][HPrice] = cache_get_field_content_int(i"HPrice");
            
HouseInfo[i][HOwnerID] = cache_get_field_content_int(0"HOwnerID");
            
HouseInfo[i][HOwned] = cache_get_field_content_int(i"HOwned");
            
HouseInfo[i][HLocked] = cache_get_field_content_int(i"HLocked");
            
cache_get_field_content(i"HName"HouseInfo[i][HName], 30);
            if(
HouseInfo[i][HOwned] == 1)
        {
                
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[i][HName]);
                
HouseInfo[i][H3D] = CreateDynamic3DTextLabel(labelCOLOR_YELLOWHouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
        }
        
        else if(
HouseInfo[i][HOwned] == 0)
        {
            
format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",HouseInfo[i][HPrice]);
            
HouseInfo[i][H3D] = CreateDynamic3DTextLabel(labelCOLOR_YELLOWHouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
        }
        }
        
printf("Successfully Loaded All Houses! ( %d )",rows);
    }
    else
    {
        print(
"There are no houses to load!");
    }
        
cache_delete(result);

Reply
#7

Aha!

You've not added a save to the HouseID.

pawn Код:
LoadHouses()
{
    new Cache:result,rows;
    new label[250];
    result = mysql_query(mysql, "SELECT * FROM `houses`");
    if((rows = cache_num_rows()))
    {
        for(new i=1; i < rows; i++)
        {

            HouseInfo[i][hid] = cache_get_row_int(i, "HouseID");
            HouseInfo[i][XEnt] = cache_get_field_content_float(i, "XEnt"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
            HouseInfo[i][YEnt] = cache_get_field_content_float(i, "YEnt"); //Above
            HouseInfo[i][ZEnt] = cache_get_field_content_float(i, "ZEnt");//Above
            HouseInfo[i][XExit] = cache_get_field_content_float(i, "XExit");//Above. Since player's position is a float, we use cache_get_field_content_float
            HouseInfo[i][YExit] = cache_get_field_content_float(i, "YExit");//Above
            HouseInfo[i][ZExit] = cache_get_field_content_float(i, "ZExit");//Above
            HouseInfo[i][HVirtualWorld] = cache_get_field_content_int(i, "HVirtualWorld");
            HouseInfo[i][HInterior] = cache_get_field_content_int(i, "HInterior");
            HouseInfo[i][HPrice] = cache_get_field_content_int(i, "HPrice");
            HouseInfo[i][HOwnerID] = cache_get_field_content_int(0, "HOwnerID");
            HouseInfo[i][HOwned] = cache_get_field_content_int(i, "HOwned");
            HouseInfo[i][HLocked] = cache_get_field_content_int(i, "HLocked");
            cache_get_field_content(i, "HName", HouseInfo[i][HName], 30);
            if(HouseInfo[i][HOwned] == 1)
        {
                format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[i][HName]);
                HouseInfo[i][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
        }
         
        else if(HouseInfo[i][HOwned] == 0)
        {
            format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",HouseInfo[i][HPrice]);
            HouseInfo[i][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);

        }
        }
        printf("Successfully Loaded All Houses! ( %d )",rows);
    }
    else
    {
        print("There are no houses to load!");
    }
        cache_delete(result);
}
ALSO, if your IDs on the table start at 1 it's a good idea to loop from 1 instead of 0.
Reply
#8

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Aha!

You've not added a save to the HouseID.

pawn Код:
LoadHouses()
{
    new Cache:result,rows;
    new label[250];
    result = mysql_query(mysql, "SELECT * FROM `houses`");
    if((rows = cache_num_rows()))
    {
        for(new i=0; i < rows; i++)
        {

            HouseInfo[i][hid] = cache_get_row_int(i, "HouseID");
            HouseInfo[i][XEnt] = cache_get_field_content_float(i, "XEnt"); //we're getting a field 4 from row 0. And since it's an integer, we use cache_get_row_int
            HouseInfo[i][YEnt] = cache_get_field_content_float(i, "YEnt"); //Above
            HouseInfo[i][ZEnt] = cache_get_field_content_float(i, "ZEnt");//Above
            HouseInfo[i][XExit] = cache_get_field_content_float(i, "XExit");//Above. Since player's position is a float, we use cache_get_field_content_float
            HouseInfo[i][YExit] = cache_get_field_content_float(i, "YExit");//Above
            HouseInfo[i][ZExit] = cache_get_field_content_float(i, "ZExit");//Above
            HouseInfo[i][HVirtualWorld] = cache_get_field_content_int(i, "HVirtualWorld");
            HouseInfo[i][HInterior] = cache_get_field_content_int(i, "HInterior");
            HouseInfo[i][HPrice] = cache_get_field_content_int(i, "HPrice");
            HouseInfo[i][HOwnerID] = cache_get_field_content_int(0, "HOwnerID");
            HouseInfo[i][HOwned] = cache_get_field_content_int(i, "HOwned");
            HouseInfo[i][HLocked] = cache_get_field_content_int(i, "HLocked");
            cache_get_field_content(i, "HName", HouseInfo[i][HName], 30);
            if(HouseInfo[i][HOwned] == 1)
        {
                format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE":%s\n"COL_GREEN"",HouseInfo[i][HName]);
                HouseInfo[i][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);
        }
         
        else if(HouseInfo[i][HOwned] == 0)
        {
            format(label,sizeof(label),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",HouseInfo[i][HPrice]);
            HouseInfo[i][H3D] = CreateDynamic3DTextLabel(label, COLOR_YELLOW, HouseInfo[i][XEnt],  HouseInfo[i][YEnt], HouseInfo[i][ZEnt], 40.0);

        }
        }
        printf("Successfully Loaded All Houses! ( %d )",rows);
    }
    else
    {
        print("There are no houses to load!");
    }
        cache_delete(result);
}
I just did and no that's no the problem
Reply
#9

Does it look like that?

Also if your table row starts at 1, loop from 1 instead of 0.
Reply
#10

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Does it look like that?

Also if your table row starts at 1, loop from 1 instead of 0.
That could be a problem I guess!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)