MySQL - R38 loading houses help
#1

Hi, anyone have an idea how to load EVERY houses stored into the database with the lastest plugins R38, cant figured it out it should be similar to the player account like this:

Код:
stock LoadAccount(playerid)
{
	new query[128];

	format(query, sizeof(query), "SELECT * FROM `players` WHERE `ID` = %d", PlayerInfo[playerid][pSQLid]);
	mysql_tquery(g_Handle, query, "OnAccountLoad", "d", playerid);
}

forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
	ToggleMainMenu(playerid, 0);
	SetCameraBehindPlayer(playerid);

	PlayerInfo[playerid][pHealth]         = cache_get_field_content_float(0, "Health");
	PlayerInfo[playerid][pPos][0]         = cache_get_field_content_float(0, "PosX");
	PlayerInfo[playerid][pPos][1]         = cache_get_field_content_float(0, "PosY");
	PlayerInfo[playerid][pPos][2]         = cache_get_field_content_float(0, "PosZ");
	PlayerInfo[playerid][pPos][3]         = cache_get_field_content_float(0, "Angle");
	PlayerInfo[playerid][pInterior]       = cache_get_field_content_int(0, "Interior");
	PlayerInfo[playerid][pVirtualWorld]   = cache_get_field_content_int(0, "VirtualWorld");
	PlayerInfo[playerid][pSkin]           = cache_get_field_content_int(0, "Skin");
	PlayerInfo[playerid][pSex]            = cache_get_field_content_int(0, "Sex");
	PlayerInfo[playerid][pAge]            = cache_get_field_content_int(0, "Age");
	PlayerInfo[playerid][pOrigine]        = cache_get_field_content_int(0, "Origine");
	PlayerInfo[playerid][pMoney]          = cache_get_field_content_int(0, "Money");
	PlayerInfo[playerid][pJob]            = cache_get_field_content_int(0, "Job");
	PlayerInfo[playerid][pFaction]        = cache_get_field_content_int(0, "Faction");

	SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
	SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], posArr{PlayerInfo[playerid][pPos]}, PlayerInfo[playerid][pPos][3], 0, 0, 0, 0, 0, 0);
	SpawnPlayer(playerid);
	/*SetPlayerPos(playerid, posArr{PlayerInfo[playerid][pPos]});
	SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPos][3]);*/
	SetPlayerInterior(playerid, PlayerInfo[playerid][pInterior]);
	SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVirtualWorld]);
	SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
	GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
	return 1;
}
need the same who loop through all houses created into the database and then create the 3dtext etc... any ideas ?

thanks in advance
Reply
#2

Not sure if this helps any but:

pawn Код:
if(cache_num_rows())
{
    for(new i = 0; i<cache_num_rows(); i++)
    {
        cache_get_field_content_int(i,"id",connectionHandle);
        cache_get_field_content_float(i,"x",connectionHandle); //the row becomes "i". Since you're looping the number of rows found.
        //load more...
    }
}
Simple for() or maybe even a while() loop will do it.
Reply
#3

What about
Код HTML:
stock LoadAccount(playerid)
{
	new query[128];

	format(query, sizeof(query), "SELECT * FROM `users` WHERE `ID` = %d", PlayerInfo[playerid][pSQLid]);
	mysql_tquery(g_Handle, query, "OnAccountLoad", "d", playerid);
}
should i do something like this or select * houses right under OnHouseLoad by example ?
Reply
#4

You can use a straight query for that.

pawn Код:
public OnGameModeInit()
{
    mysql_pquery(connectionHandle,"SELECT * FROM `houses`","OnHousesLoad");
    return 1;
}
Reply
#5

pawn Код:
mysql_pquery(g_Handle, "SELECT * FROM `houses`", "OnHouseLoad");



pawn Код:
forward OnHouseLoad();
public OnHouseLoad()
{
    if(cache_num_rows())
    {
        for(new i = 0; i<cache_num_rows(); i++)
        {
            cache_get_field_content_int(i,"SQLID",g_Handle);
            cache_get_field_content_float(i,"Posx",g_Handle);
            cache_get_field_content_float(i,"Posy",g_Handle);
            cache_get_field_content_float(i,"Posz",g_Handle); //the row becomes "i". Since you're looping the number of rows found.
            //load more...
            print("test");
        }
    }
}


Not sure if I miss something but it doesnt print so theres is something wrong
Reply
#6

have you enabled debug mode via MySQL?
Reply
#7

Yes, I do
Reply
#8

I presume its not putting anything relating to fieldnames/tablenames into the txt file. I'll open up pawno now

Edit:

Using this script:

pawn Код:
new
    Database = 1;
main(){}
public OnGameModeInit()
{
    mysql_log(LOG_ALL,LOG_TYPE_TEXT);
    Database = mysql_connect("localhost","user","testdb","pass");
    mysql_tquery(Database,"SELECT * FROM `houses`","OnHouseLoad");
    return 1;
}
forward OnHouseLoad();
public OnHouseLoad()
{
    if(cache_num_rows())
    {
        for(new i = 0; i<cache_num_rows(); i++)
        {
            new ID = cache_get_field_content_int(i,"id",Database);
            new Float:x =  cache_get_field_content_float(i,"x",Database);
            new Float:y =  cache_get_field_content_float(i,"y",Database);
            new Float:z =  cache_get_field_content_float(i,"z",Database);
            printf("Loaded house %d %f %f %f",ID,x,y,z);
        }
    }
    else print("No houses found.");
    return 1;
}
Outputs:

Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3z-R2, ©2005-2014 SA-MP Team

[02:30:27] 
[02:30:27] Server Plugins
[02:30:27] --------------
[02:30:27]  Loading plugin: mysql
[02:30:27]  >> plugin.mysql: R38 successfully loaded.
[02:30:27]   Loaded.
[02:30:27]  Loading plugin: streamer
[02:30:27]   Loaded.
[02:30:27]  Loaded 2 plugins.

[02:30:27] 
[02:30:27] Filterscripts
[02:30:27] ---------------
[02:30:27]   Loaded 0 filterscripts.

[02:30:27] Number of vehicle models: 0
[02:30:27] Loaded house 1 123.000000 456.000000 789.000000
Reply
#9

Код HTML:
[21:26:40] [ERROR] "mysql_pquery" - invalid connection handle (id: 0)
[21:26:40] [DEBUG] mysql_connect - host: "localhost", user: "root", database: "samp", password: "****", port: 3306, autoreconnect: true, pool_size: 2
[21:26:40] [DEBUG] CMySQLHandle::Create - creating new connection..
[21:26:40] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[21:26:40] [DEBUG] CMySQLHandle::Create - connection created (id: 1)
[21:26:40] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[21:26:40] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:26:40] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[21:26:40] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[21:26:40] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[21:26:40] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:26:40] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:26:40] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:26:40] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[21:26:40] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled


Код HTML:
[21:26:40] [ERROR] "mysql_pquery" - invalid connection handle (id: 0)
Reply
#10

Wait i know!


Set your connectionhandle to 1.

EG:

pawn Код:
new Database = 1; //Database being Connection handle.
Also edited my above post.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)