[+REP] Loading MySQL houses
#1

Hello, I've made a function "public" to load the houses in my "houses" mysql table, but I've put the function OnGameModeInit, and no thing was loaded.
Can someone tell me how to load them and where to put this function.
This the script:
Код:
forward Load_houses();
public Load_houses()
{
	new
        rows,
        fields;
        
    cache_get_data(rows, fields, mysql);
    if(rows == 0)
	{
	    printf("No houses were found in the database.");
	}
	else
	{
		for(new i = 0; i < rows; i++)
		{
			if(rows <= MAX_HOUSES)
			{
				hInfo[i][hID] = cache_get_field_content_int(0, "ID");
                                hInfo[i][hOwned] = cache_get_field_content_int(0, "Owned");
				hInfo[i][hPrice] = cache_get_field_content_int(0, "Price");
				hInfo[i][hEntranceX] = cache_get_field_content_float(0, "EntranceX");
				hInfo[i][hEntranceY] = cache_get_field_content_float(0, "EntranceY");
				hInfo[i][hEntranceZ] = cache_get_field_content_float(0, "EntranceZ");
				hInfo[i][hExitX] =  cache_get_field_content_float(0, "ExitX");
				hInfo[i][hExitY] =  cache_get_field_content_float(0, "ExitY");
				hInfo[i][hExitZ] =  cache_get_field_content_float(0, "ExitZ");
                                hInfo[i][InteriorID] = cache_get_field_content_int(0, "InteriorID");
                                cache_get_field_content(0, "Pass", hInfo[i][hPass]);
                                cache_get_field_content(0, "Owner", hInfo[i][hOwner]);
				
				hInfo[i][EntranceCP] = CreateDynamicCP(hInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 1.5, -1, -1, -1, 50.0);
				hInfo[i][ExitCP] = CreateDynamicCP(hInfo[i][hExitX], hInfo[i][hExitY], hInfo[i][hExitZ], 1.5, hInfo[i][hID], hInfo[i][InteriorID], -1, 100.0);

				new labelstring[200];
				switch(hInfo[i][hOwned])
				{
					case 0:
					{
						format(labelstring, sizeof(labelstring), "{FFFFFF}Home(%d)\n"COL_GOLD"Owner:{FFFFFF} No-one\n"COL_GOLD"Price:{FFFFFF} %s", hInfo[i][hID], AC(hInfo[i][hPrice]));
						hInfo[i][HouseLabel] = CreateDynamic3DTextLabel(labelstring, COLOR_WHITE, hInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 35.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 35.0);
						
					}
					case 1:
					{
						format(labelstring, sizeof(labelstring), "{FFFFFF}Home(%d)\n"COL_GOLD"Owner:{FFFFFF} %s\n"COL_GOLD"Price:{FFFFFF} %s", hInfo[i][hID], hInfo[i][hOwner], AC(hInfo[i][hPrice]));
						hInfo[i][HouseLabel] = CreateDynamic3DTextLabel(labelstring, COLOR_WHITE, hInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 35.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 35.0);
					}
				}
				hInfo[i][ExitLabel] = CreateDynamic3DTextLabel("[EXIT]", COLOR_WHITE, hInfo[i][hExitX], hInfo[i][hExitY], hInfo[i][hExitZ], 35.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, hInfo[i][hID], -1, -1, 35.0);
				LoadedHouses++;
			}
		}
	}
}
Reply
#2

Put
PHP код:
mysql_tquery(mysql"SELECT * FROM `Table_Name`""Load_houses"""); 
Under OnGameModeInIt

Edit mysql with your connection variable, and the Table_Name with the table inside of your database.
Reply
#3

Quote:
Originally Posted by itsCody
Посмотреть сообщение
Put
PHP код:
mysql_tquery(mysql"SELECT * FROM `Table_Name`""Load_houses"""); 
Under OnGameModeInIt

Edit mysql with your connection variable, and the Table_Name with the table inside of your database.
Hello, I've added to printf the total loaded houses, and it printf'ed "11 house were loaded...", but there are no checkpoints in the server, why?
Reply
#4

Corrected a small error in your loading code.

PHP код:
forward Load_houses();
public 
Load_houses()
{
    new
        
rows,
        
fields;
        
    
cache_get_data(rowsfieldsmysql);
    if(
rows == 0)
    {
        
printf("No houses were found in the database.");
    }
    else
    {
        for(new 
0rowsi++)
        {
            if(
rows <= MAX_HOUSES)
            {
                
hInfo[i][hID] = cache_get_field_content_int(i"ID");
                
hInfo[i][hOwned] = cache_get_field_content_int(i"Owned");
                
hInfo[i][hPrice] = cache_get_field_content_int(i"Price");
                
hInfo[i][hEntranceX] = cache_get_field_content_float(i"EntranceX");
                
hInfo[i][hEntranceY] = cache_get_field_content_float(i"EntranceY");
                
hInfo[i][hEntranceZ] = cache_get_field_content_float(i"EntranceZ");
                
hInfo[i][hExitX] =  cache_get_field_content_float(i"ExitX");
                
hInfo[i][hExitY] =  cache_get_field_content_float(i"ExitY");
                
hInfo[i][hExitZ] =  cache_get_field_content_float(i"ExitZ");
                
hInfo[i][InteriorID] = cache_get_field_content_int(i"InteriorID");
                
cache_get_field_content(i"Pass"hInfo[i][hPass]);
                
cache_get_field_content(i"Owner"hInfo[i][hOwner]);
                
                
hInfo[i][EntranceCP] = CreateDynamicCP(hInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 1.5, -1, -1, -150.0);
                
hInfo[i][ExitCP] = CreateDynamicCP(hInfo[i][hExitX], hInfo[i][hExitY], hInfo[i][hExitZ], 1.5hInfo[i][hID], hInfo[i][InteriorID], -1100.0);
                new 
labelstring[200];
                switch(
hInfo[i][hOwned])
                {
                    case 
0:
                    {
                        
format(labelstringsizeof(labelstring), "{FFFFFF}Home(%d)\n"COL_GOLD"Owner:{FFFFFF} No-one\n"COL_GOLD"Price:{FFFFFF} %s"hInfo[i][hID], AC(hInfo[i][hPrice]));
                        
hInfo[i][HouseLabel] = CreateDynamic3DTextLabel(labelstringCOLOR_WHITEhInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 35.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -135.0);
                        
                    }
                    case 
1:
                    {
                        
format(labelstringsizeof(labelstring), "{FFFFFF}Home(%d)\n"COL_GOLD"Owner:{FFFFFF} %s\n"COL_GOLD"Price:{FFFFFF} %s"hInfo[i][hID], hInfo[i][hOwner], AC(hInfo[i][hPrice]));
                        
hInfo[i][HouseLabel] = CreateDynamic3DTextLabel(labelstringCOLOR_WHITEhInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 35.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -135.0);
                    }
                }
                
hInfo[i][ExitLabel] = CreateDynamic3DTextLabel("[EXIT]"COLOR_WHITEhInfo[i][hExitX], hInfo[i][hExitY], hInfo[i][hExitZ], 35.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0hInfo[i][hID], -1, -135.0);
                
LoadedHouses++;
            }
        }
    }

Try that.
Reply
#5

Perhaps the X Y and Z coordinates aren't loaded correctly - try printing them.
Reply
#6

Quote:
Originally Posted by itsCody
Посмотреть сообщение
Corrected a small error in your loading code.

PHP код:
forward Load_houses();
public 
Load_houses()
{
    new
        
rows,
        
fields;
        
    
cache_get_data(rowsfieldsmysql);
    if(
rows == 0)
    {
        
printf("No houses were found in the database.");
    }
    else
    {
        for(new 
0rowsi++)
        {
            if(
rows <= MAX_HOUSES)
            {
                
hInfo[i][hID] = cache_get_field_content_int(i"ID");
                
hInfo[i][hOwned] = cache_get_field_content_int(i"Owned");
                
hInfo[i][hPrice] = cache_get_field_content_int(i"Price");
                
hInfo[i][hEntranceX] = cache_get_field_content_float(i"EntranceX");
                
hInfo[i][hEntranceY] = cache_get_field_content_float(i"EntranceY");
                
hInfo[i][hEntranceZ] = cache_get_field_content_float(i"EntranceZ");
                
hInfo[i][hExitX] =  cache_get_field_content_float(i"ExitX");
                
hInfo[i][hExitY] =  cache_get_field_content_float(i"ExitY");
                
hInfo[i][hExitZ] =  cache_get_field_content_float(i"ExitZ");
                
hInfo[i][InteriorID] = cache_get_field_content_int(i"InteriorID");
                
cache_get_field_content(i"Pass"hInfo[i][hPass]);
                
cache_get_field_content(i"Owner"hInfo[i][hOwner]);
                
                
hInfo[i][EntranceCP] = CreateDynamicCP(hInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 1.5, -1, -1, -150.0);
                
hInfo[i][ExitCP] = CreateDynamicCP(hInfo[i][hExitX], hInfo[i][hExitY], hInfo[i][hExitZ], 1.5hInfo[i][hID], hInfo[i][InteriorID], -1100.0);
                new 
labelstring[200];
                switch(
hInfo[i][hOwned])
                {
                    case 
0:
                    {
                        
format(labelstringsizeof(labelstring), "{FFFFFF}Home(%d)\n"COL_GOLD"Owner:{FFFFFF} No-one\n"COL_GOLD"Price:{FFFFFF} %s"hInfo[i][hID], AC(hInfo[i][hPrice]));
                        
hInfo[i][HouseLabel] = CreateDynamic3DTextLabel(labelstringCOLOR_WHITEhInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 35.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -135.0);
                        
                    }
                    case 
1:
                    {
                        
format(labelstringsizeof(labelstring), "{FFFFFF}Home(%d)\n"COL_GOLD"Owner:{FFFFFF} %s\n"COL_GOLD"Price:{FFFFFF} %s"hInfo[i][hID], hInfo[i][hOwner], AC(hInfo[i][hPrice]));
                        
hInfo[i][HouseLabel] = CreateDynamic3DTextLabel(labelstringCOLOR_WHITEhInfo[i][hEntranceX], hInfo[i][hEntranceY], hInfo[i][hEntranceZ], 35.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0, -1, -1, -135.0);
                    }
                }
                
hInfo[i][ExitLabel] = CreateDynamic3DTextLabel("[EXIT]"COLOR_WHITEhInfo[i][hExitX], hInfo[i][hExitY], hInfo[i][hExitZ], 35.0INVALID_PLAYER_IDINVALID_VEHICLE_ID0hInfo[i][hID], -1, -135.0);
                
LoadedHouses++;
            }
        }
    }

Try that.
Fixed, +REP'd
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)