MySQL R39-4 (Loading Interiors)
#1

I am kinda new using mysql databases and i have a question about loading interiors from a created table, i scripted something and it works fine for loading, but i don't feel that this is the right way to load. Here is it.. please tell me if it's wrong.

PHP код:
public OnGameModeExit()
{
    for(new 
0MAX_INTERIORSi++)
    {
        
mysql_tquery(ConnectionHandle"SELECT * FROM interiors""LoadInteriorData""i"i);
    }
    return 
1;
}
forward LoadInteriorData(intid);
public 
LoadInteriorData(intid)
{
    new 
rowsfieldscache_get_data(rowsfieldsConnectionHandle);
    if(!
rows) return 1;
    
cache_get_field_content(intid"intname"INTInfo[intid][INTName], ConnectionHandle64);
    
cache_get_field_content(intid"inttype"INTInfo[intid][INTType], ConnectionHandle64);
    
cache_get_field_content(intid"intlocation"INTInfo[intid][INTLocation], ConnectionHandle64);
    
INTInfo[intid][INTInterior] = cache_get_field_content_int(intid"intinterior");
    
INTInfo[intid][INTIcon] = cache_get_field_content_int(intid"inticon");
    
INTInfo[intid][INTCPOutX] = cache_get_field_content_float(intid"intcpoutx");
    
INTInfo[intid][INTCPOutY] = cache_get_field_content_float(intid"intcpouty");
    
INTInfo[intid][INTCPOutZ] = cache_get_field_content_float(intid"intcpoutz");
    
INTInfo[intid][INTSPInX] = cache_get_field_content_float(intid"intspinx");
    
INTInfo[intid][INTSPInY] = cache_get_field_content_float(intid"intspiny");
    
INTInfo[intid][INTSPInZ] = cache_get_field_content_float(intid"intspinz");
    
INTInfo[intid][INTSPInA] = cache_get_field_content_float(intid"intspina");
    
INTInfo[intid][INTSPOutX] = cache_get_field_content_float(intid"intspoutx");
    
INTInfo[intid][INTSPOutY] = cache_get_field_content_float(intid"intspouty");
    
INTInfo[intid][INTSPOutZ] = cache_get_field_content_float(intid"intspoutz");
    
INTInfo[intid][INTSPOutA] = cache_get_field_content_float(intid"intspouta");
     
InteriorCP[intid] = CreateDynamicCP(INTInfo[intid][INTCPOutX], INTInfo[intid][INTCPOutY], INTInfo[intid][INTCPOutZ], 1.500, -120);
     
CreateDynamic3DTextLabel(INTInfo[intid][INTName], COLOR_YELLOWINTInfo[intid][INTCPOutX], INTInfo[intid][INTCPOutY], INTInfo[intid][INTCPOutZ], 30);
    if(
INTInfo[intid][INTIcon] != 0CreateDynamicMapIcon(INTInfo[intid][INTCPOutX], INTInfo[intid][INTCPOutY], INTInfo[intid][INTCPOutZ], INTInfo[intid][INTIcon],0,0,0,-1,300.0);
    
printf("Loading Interior (%s)"INTInfo[intid][INTName]);
    return 
1;

Reply
#2

Bump!
Reply
#3

Quote:

i scripted something and it works fine for loading,

Are you sure? it has many mistakes...

public OnGameModeExit() <--------- ?

for(new i = 0; i < MAX_INTERIORS; i++) while using SELECT * ??

Where you used rows??
...

Fix them and read more about SAMP/MySQL.
Reply
#4

Quote:
Originally Posted by Yousha
Посмотреть сообщение
Are you sure? it has many mistakes...

public OnGameModeExit() <--------- ?
OnGameModeInIt **
Reply
#5

I think better usage should be
pawn Код:
mysql_tquery(ConnectionHandle, "SELECT * FROM interiors", "LoadInteriorData");
then in loop all rows
Reply
#6

It looks fine, to be honest. You could make it look neater by aligning all the "=" symbols and by splitting the Create functions over multiple lines. White-space has no influence on the code whatsoever. I regularly space things out like this:
PHP код:
InteriorCP[intid] = CreateDynamicCP(
    
INTInfo[intid][INTCPOutX],     // x
    
INTInfo[intid][INTCPOutY],     // y
    
INTInfo[intid][INTCPOutZ],     // z
    
1.5,                         // size
    
0,                             // worldid
    
0,                             // interiorid
    
-1,                         // playerid
    
20                            // streamdistance
); 
What you could still do, however, is splitting off all the actual game interiors. Like if you have a bunch of houses that all use the same "burglary house 1" interior then you could split those off into another table. You could then state that houses 7, 15 and 37 all use "burglary house 1" without needing to repeat those coordinates again.

Edit:
Quote:
Originally Posted by Jefff
Посмотреть сообщение
I think better usage should be
pawn Код:
mysql_tquery(ConnectionHandle, "SELECT * FROM interiors", "LoadInteriorData");
then in loop all rows
I didn't even notice that giant flaw. Sharp eye.
Reply
#7

Well it ended up like this now, and it works fine..
PHP код:
public OnGameModeInit()
{
    
mysql_tquery(ConnectionHandle"SELECT * FROM interiors""LoadInteriorData");
    return 
1;
}
forward LoadInteriorData();
public 
LoadInteriorData()
{
    new 
rowsfieldscache_get_data(rowsfieldsConnectionHandle);
    if(!
rows) return 1;
    for(new 
0MAX_INTERIORSi++)
    {
        
cache_get_field_content(i"intname"INTInfo[i][INTName], ConnectionHandle64);
        
cache_get_field_content(i"inttype"INTInfo[i][INTType], ConnectionHandle64);
        
cache_get_field_content(i"intlocation"INTInfo[i][INTLocation], ConnectionHandle64);
        
INTInfo[i][INTInterior] = cache_get_field_content_int(i"intinterior");
        
INTInfo[i][INTIcon] = cache_get_field_content_int(i"inticon");
        
INTInfo[i][INTCPOutX] = cache_get_field_content_float(i"intcpoutx");
        
INTInfo[i][INTCPOutY] = cache_get_field_content_float(i"intcpouty");
        
INTInfo[i][INTCPOutZ] = cache_get_field_content_float(i"intcpoutz");
        
INTInfo[i][INTSPInX] = cache_get_field_content_float(i"intspinx");
        
INTInfo[i][INTSPInY] = cache_get_field_content_float(i"intspiny");
        
INTInfo[i][INTSPInZ] = cache_get_field_content_float(i"intspinz");
        
INTInfo[i][INTSPInA] = cache_get_field_content_float(i"intspina");
        
INTInfo[i][INTSPOutX] = cache_get_field_content_float(i"intspoutx");
        
INTInfo[i][INTSPOutY] = cache_get_field_content_float(i"intspouty");
        
INTInfo[i][INTSPOutZ] = cache_get_field_content_float(i"intspoutz");
        
INTInfo[i][INTSPOutA] = cache_get_field_content_float(i"intspouta");
         
InteriorCP[i] = CreateDynamicCP(INTInfo[i][INTCPOutX], INTInfo[i][INTCPOutY], INTInfo[i][INTCPOutZ], 1.500, -120);
         
CreateDynamic3DTextLabel(INTInfo[i][INTName], COLOR_YELLOWINTInfo[i][INTCPOutX], INTInfo[i][INTCPOutY], INTInfo[i][INTCPOutZ], 30);
        if(
INTInfo[i][INTIcon] != 0CreateDynamicMapIcon(INTInfo[i][INTCPOutX], INTInfo[i][INTCPOutY], INTInfo[i][INTCPOutZ], INTInfo[i][INTIcon],0,0,0,-1,300.0);
    }
    return 
1;

Quote:
Originally Posted by Vince
Посмотреть сообщение
It looks fine, to be honest. You could make it look neater by aligning all the "=" symbols and by splitting the Create functions over multiple lines. White-space has no influence on the code whatsoever.
This method will take alot of lines if i applied it on the whole script.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)