SA-MP Forums Archive
R40 HELP!!! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: R40 HELP!!! (/showthread.php?tid=647513)



R40 HELP!!! - Kraeror - 06.01.2018

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)


Re: R40 HELP!!! - MEW273 - 06.01.2018

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


Re: R40 HELP!!! - Kraeror - 06.01.2018

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!


Re: R40 HELP!!! - MEW273 - 06.01.2018

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


Re: R40 HELP!!! - Kraeror - 06.01.2018

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?


Re: R40 HELP!!! - MEW273 - 06.01.2018

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


Re: R40 HELP!!! - Kraeror - 06.01.2018

I'm trying to load them at once!


Re: R40 HELP!!! - Kraeror - 06.01.2018

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?


Re: R40 HELP!!! - MEW273 - 06.01.2018

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); 
			    }
		    }
		}
	}
}



Re: R40 HELP!!! - Kraeror - 06.01.2018

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!