R40 HELP!!!
#1

Hello guys, please help me! I have problem with my hosue loading!
The code (OnGameModeInit):
PHP код:
mysql_format(zMySQLquerysizeof(query), "SELECT * FROM `houses`");
    
mysql_query(zMySQLquery);
    for(new 
1cache_num_rows()+1h++)
    {
          
mysql_format(zMySQLquerysizeof(query), "SELECT * FROM `houses` WHERE `ID` = %d"h);
          
mysql_tquery(zMySQLquery"LoadHouses""i"h);
        if(
strcmp(HouseInfo[h][hOwner], "No"true) == 0)
        {
            
HouseInfo[h][hPickup] = CreatePickup(12731HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ]);
            
HouseInfo[h][hIcon] = CreateDynamicMapIcon(HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ], 310,0,0);
        }
        else
        {
            
HouseInfo[h][hPickup] = CreatePickup(195221HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ]);
            
HouseInfo[h][hIcon] = CreateDynamicMapIcon(HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ], 320,0,0);
        }
    } 
And here is my callback for laoding:
PHP код:
forward LoadHouses(houseid);
    public 
LoadHouses(houseid)
    {
        new 
Float:test;
        
cache_get_value_name_float(houseid"X"test);
        
printf("%f"test);
    } 
Output:
Quote:

0.000000
0.000000
0.000000

(they are three, because I have 3 rows created)
Reply
#2

The problem appears to be your LoadHouses callback. Please check the syntax/parameters of cache_get_value_name_float, the first parameter is the row number, you are using houseid, this is likely resulting in the cache returning a non-existent row.

Instead of the first parameter being houseid it should be 0 as the row count will begin at 0.

You could also add a check to ensure that there is at least one row before selecting the value.
Код:
forward LoadHouses(houseid); 
public LoadHouses(houseid) 
{ 
	new numRows;
	cache_get_row_count(numRows);
	if(numRows == 0) return print("[MYSQL] MySQL returned no result for this query.");
	{
	    new Float:test; 
	    cache_get_value_name_float(0, "X", test); 
	    printf("%f", test); 
	}
}
MySQL R40 wiki:
https://sampwiki.blast.hk/wiki/MySQL/R40
Reply
#3

The parameters are:
Quote:

row_idx, const column_name[], &Float:destination

I think my parameters are correct!
I added a check and it fixed all!
Thank you brother!!!
PS: I'm still learning MySQL, because I want to update my server from dini to MySQL!
Reply
#4

Quote:
Originally Posted by Kraeror
Посмотреть сообщение
The parameters are:
I think my parameters are correct!
I added a check and it fixed all!
Thank you brother!!!
PS: I'm still learning MySQL, because I want to update my server from dini to MySQL!
Great to hear, good luck with your update
Reply
#5

Quote:
Originally Posted by MEW273
Посмотреть сообщение
Great to hear, good luck with your update
Thank you, but not the check fixed all, this 0(instead of houseid)
But now I can't load the full data Where is the problem with this houseid?
Can you check OnGameModeInit code again?
Reply
#6

Are you trying to load all the houses at once, or one at a time?
Reply
#7

I'm trying to load them at once!
Reply
#8

And why this:
PHP код:
forward LoadHouses(houseid); 
public 
LoadHouses(houseid

    new 
numRows;
    
cache_get_row_count(numRows);
    if(
numRows == 0) return print("[MYSQL] MySQL returned no result for this query.");
    {
        new 
Float:test
        
cache_get_value_name_float(0"X"test); 
        
printf("%f"test); 
    }

outputs correct postions, but when I'm using command like:
Код HTML:
cmd:test(playerid, params[])
{
	printf("%f", HouseInfo[2][hX]);
	return 1;
}
it outputs:
Quote:

0.000000

I have to laod it in all commands, where I'm using it?
Reply
#9

Your OnGameModeInit code as it is now will not work as you are using the threaded query version of MySQL, you can't use the cache in the same callback as where you send the query.

Try this:
Код:
mysql_format(zMySQL, query, sizeof(query), "SELECT * FROM `houses`"); 
mysql_tquery(zMySQL, query, "LoadHouses"); 

forward LoadHouses(); 
public LoadHouses() 
{ 
	new numRows;
	cache_get_row_count(numRows);
	if(numRows == 0) return print("[MYSQL] There are no rows in the houses table.");
	else
	{
		for(new i = 0; i < numRows; i++)
		{
			cache_get_value_name_float(i, "X", HouseInfo[i][hX]);
			cache_get_value_name(i, "owner", HouseInfo[i][hOwner]);
			// Add more lines here for each column in houses table
			{
				if(strcmp(HouseInfo[i][hOwner], "No", true) == 0) 
			    { 
			        HouseInfo[i][hPickup] = CreatePickup(1273, 1, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]); 
			        HouseInfo[i][hIcon] = CreateDynamicMapIcon(HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ], 31, 0,0,0); 
			    } 
			    else 
			    { 
			        HouseInfo[i][hPickup] = CreatePickup(19522, 1, HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ]); 
			        HouseInfo[i][hIcon] = CreateDynamicMapIcon(HouseInfo[i][hX], HouseInfo[i][hY], HouseInfo[i][hZ], 32, 0,0,0); 
			    }
		    }
		}
	}
}
Reply
#10

What version of MySQL I have to use :XXXXXXXXXXXXXXXXXXXXXXX
What the f*** I have to load 3d text labels too, but they are to OnPlayerConnect callback, because they are for 2 languages!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)