mysql loading houses
#1

PHP код:
forward    LoadHouses();
public 
LoadHouses()
{
    new 
Hstring[250];
    
mysql_format(sql,Hstring,sizeof(Hstring),"SELECT * FROM `houses` ORDER BY `houses`.`ID` ASC");
    
mysql_tquery(sql,Hstring,"","");
    for(new 
i=0i<= MAX_HOUSES i++)
    {
        
HouseInfo[i][hID] = cache_get_field_content_int(0,"ID");
        
cache_get_field_content(0,"Owner",HouseInfo[i][hOwner],sql,129);
        
HouseInfo[i][hPrice] = cache_get_field_content_int(0,"Price");
        
cache_get_field_content(0,"Name",HouseInfo[i][hDiscription],sql,129);
        
HouseInfo[i][hInteriorX] = cache_get_field_content_float(0,"InteriorX");
        
HouseInfo[i][hInteriorX] = cache_get_field_content_float(0,"InteriorY");
        
HouseInfo[i][hInteriorZ] = cache_get_field_content_float(0,"InteriorZ");
        
HouseInfo[i][hExteriorX] = cache_get_field_content_float(0,"ExteriorX");
        
HouseInfo[i][hExteriorY] = cache_get_field_content_float(0,"ExteriorY");
        
HouseInfo[i][hExteriorZ] = cache_get_field_content_float(0,"ExteriorZ");
        
HouseInfo[i][hOwned] = cache_get_field_content_int(0,"Owned");
        
HouseInfo[i][hRentabil] = cache_get_field_content_int(0,"Rentabil");
        
    }
    
CreateTXD();
    
printf("Houses Loaded!");
    return 
1;

When i boot up the gamemode In the server console the Houses loaded message does not appear and in mysql.log i get this
PHP код:
[09:29:25] [DEBUGmysql_format connection1len250format"SELECT * FROM `houses` ORDER BY `houses`.`ID` ASC"
[09:29:25] [DEBUGmysql_tquery connection1query"SELECT * FROM `houses` ORDER BY `houses`.`ID` ASC"callback"(null)"format"(null)"
[09:29:25] [DEBUGcache_get_field_content_int row0field_name"ID"connection1
[09:29:25] [WARNINGcache_get_field_content_int no active cache
[09:29:25] [DEBUGcache_get_field_content row0field_name"Owner"connection1max_len129
[09:29:25] [WARNINGcache_get_field_content no active cache
[09:29:25] [DEBUGcache_get_field_content_int row0field_name"Price"connection1
[09:29:25] [WARNINGcache_get_field_content_int no active cache
[09:29:25] [DEBUGcache_get_field_content row0field_name"Name"connection1max_len129
[09:29:25] [WARNINGcache_get_field_content no active cache
[09:29:25] [DEBUGcache_get_field_content_float row0field_name"InteriorX"connection1
[09:29:25] [WARNINGcache_get_field_content_float no active cache
[09:29:25] [DEBUGcache_get_field_content_float row0field_name"InteriorY"connection1
[09:29:25] [WARNINGcache_get_field_content_float no active cache
[09:29:25] [DEBUGcache_get_field_content_float row0field_name"InteriorZ"connection1
[09:29:25] [WARNINGcache_get_field_content_float no active cache
[09:29:25] [DEBUGcache_get_field_content_float row0field_name"ExteriorX"connection1
[09:29:25] [WARNINGcache_get_field_content_float no active cache
[09:29:25] [DEBUGcache_get_field_content_float row0field_name"ExteriorY"connection1
[09:29:25] [WARNINGcache_get_field_content_float no active cache
[09:29:25] [DEBUGcache_get_field_content_float row0field_name"ExteriorZ"connection1
[09:29:25] [WARNINGcache_get_field_content_float no active cache
[09:29:25] [DEBUGcache_get_field_content_int row0field_name"Owned"connection1
[09:29:25] [WARNINGcache_get_field_content_int no active cache
[09:29:25] [DEBUGcache_get_field_content_int row0field_name"Rentabil"connection1
[09:29:25] [WARNINGcache_get_field_content_int no active cache 
And in game the textures are not loaded.
Reply
#2

With the new SQL plugin, it will send the cache to a callback specified in the tquery function as far as I understand. What you want to get done, should work like this (click me to go to pastebin, the forum messed up the code once posted)


I haven't tested the code, but this is how I do it in my script, and it works fine. As you might see, I replaced the for loop with the MAX_HOUSES with the amount of records loaded from the database. I also replaced the '0', the first parameter of the cache_get..... function with the 'i' variable. Now, the loop only goes as far as the amount of houses found in the database, and will give the correct value to each house variable. If you would have used the code as it was before, you would have arrays the size of MAX_HOUSES, filled with the same value (since you only took the value of row 0 each loop).

Another thing that was just optional, you formatted a string for this query (Hstring). I couldn't find any use for the string formatting in the code, meaning that you can just write the query in the query function. I also changed that as well, you can revert back on that if you like it better.
I placed some comments throughout the function to let you know what we do. If it doesn't work or if you have any questions, just post back here and we'll have a look
Reply
#3

Thank you , now i have created this public to load my textdrwas for the houses , but for some reason they do not appear ingame .
PHP код:
forward CreateTXD();
public 
CreateTXD()
{    
    new 
PropertyString[256];
    
printf("Merge");
    for(new 
1<= MAX_HOUSES i++)
    {
        if(
HouseInfo[i][hOwned] == 0)
        {
            
Delete3DTextLabel(HouseLabel[i]);
            
format(PropertyStringsizeof(PropertyString),"{347235}House {FFFFFF}%d \n{347235}Aceasta casa este de vanzare ! \nDescriere: {FFFFFF}%s \n{347235}Pret: {FFFFFF}$%s \n{347235}Level: {FFFFFF}%d \n{347235}to buy this house type /buyhouse",HouseInfo[i][hID],HouseInfo[i][hDiscription],HouseInfo[i][hPrice],HouseInfo[i][hLevel]);
            
HouseLabel[i] = Create3DTextLabel(PropertyString ,0x09FF00FF,HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ],0,1);
        }
        else if(
HouseInfo[i][hOwned] == 1)
        {
            if(
HouseInfo[i][hRentabil] == 1)
            {
                
Delete3DTextLabel(HouseLabel[i]);
                
format(PropertyStringsizeof(PropertyString),"{FFFFFF}%s\n {347235}House {FFFFFF}%d \n{347235}Aceasta casa ii apartine lui  {FFFFFF}%s \n{347235}Rent: {FFFFFF}$%s \n{347235}Level: {FFFFFF}%d \n{347235}to rent a room type /rentroom",HouseInfo[i][hDiscription],HouseInfo[i][hID],HouseInfo[i][hOwner],HouseInfo[i][hRentPrice],HouseInfo[i][hLevel]);
                
HouseLabel[i] = Create3DTextLabel(PropertyString ,0x09FF00FF,HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ],0,1);
            }
            else
            {
                
Delete3DTextLabel(HouseLabel[i]);
                
format(PropertyStringsizeof(PropertyString),"{FFFFFF}%s\n {347235}House {FFFFFF}%d \n{347235}Aceasta casa ii apartine lui {FFFFFF}%s \n{347235}Level: {FFFFFF}%d",HouseInfo[i][hDiscription],HouseInfo[i][hID],HouseInfo[i][hOwner], HouseInfo[i][hLevel]);
                
HouseLabel[i] = Create3DTextLabel(PropertyString ,0x09FF00FF,HouseInfo[i][hExteriorX], HouseInfo[i][hExteriorY], HouseInfo[i][hExteriorZ],0,1);
            }
        }
    }
    return 
1;

Reply
#4

Does it show the 'Merge' message in the console?
Reply
#5

yes it does
Reply
#6

You are setting the drawdistance of the label to 0, and the virtual world to 1.
Код:
Create3DTextLabel(PropertyString*,0x09FF00FF,HouseInfo[i][hExteriorX],*HouseInfo[i][hExteriorY],*HouseInfo[i][hExteriorZ],<drawdistance>,<virtualworld>);
The wiki has an example with draw distance on 40, and generally you'd want to set the virtual world to -1 (any vworld) or 0 (normal default vworld).
Reply
#7

still not showing the textdraw .
Reply
#8

Any ideea ?
Reply
#9

Maybe it's a good idea to verify if the SQL data is actually loaded into the variables correctly. Maybe do a printf in the CreateTDX function with the coordinates and house id.
Reply
#10

i did what you said and they are not loaded
I tested just for the X,Y,Z,ID and it printed 0.0000,0.0000,0.0000,0
so any advice ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)