Jump to content

Query in C++ doesnt work.


Go to solution Solved by ѕeмa™,

Recommended Posts

i use ingame: "/set_title new title" and doesnt work the spaces --> only show "new"

void CHARACTER::SetTitleSystem(char arg1[256])
{
	if (!arg1)
	{
		return;
	}
	sys_log(0, "Hacemos update al titulo, nuevo titulo: %s", arg1);
	DBManager::instance().Query("UPDATE player%s SET titulo='%s' WHERE id=%u", get_table_postfix(), arg1, GetPlayerID());
	sys_log(0, "Update terminado.");
}

And another question about an array in c++.

void xxxx(char test[256])
	int array[2][2] = {
		{"Test",D3DXCOLOR(0.0f/255.0f, 255.0f/255.0f, 255.0f/255.0f, 1.0f)},
		{"Test2",D3DXCOLOR(0.0f/255.0f, 255.0f/255.0f, 255.0f/255.0f, 1.0f)}
	};
	for ....
	{
	       if (test == something in for)
	        {
		    return[test][2];
		    break;
	        }
        }

i need send xxx("Test") and return the color

 

someone can finish the function? i dont know how make it in c++.

 

Thanks. and sorry my english.

Link to comment
Share on other sites

void CHARACTER::SetTitle(const char * c_szRankName)
{
	if (!*c_szRankName)
		return;

	sys_log(0, "CHARACTER::SetTitle %s", c_szRankName);
	std::auto_ptr<SQLMsg> pMsg(DBManager::Instance().DirectQuery("UPDATE player.player SET title = '%s' WHERE id = %u",c_szRankName,GetPlayerID()));
	if (pMsg->Get()->uiAffectedRows == 0 || pMsg->Get()->uiAffectedRows == (uint32_t)-1)
	{
		sys_err("We can't update this[%s] player's title!",GetName());
		return;
	}
}
struct colorTable
{
	float r;
	float g;
	float b;
	float a;
} ColorTable;

typedef TR1_NS::unordered_map<std::string, colorTable> TitleRankColor;
TitleRankColor m_map_titleRankColor;

How to insert ?

    colorTable myTable = {};
    myTable.r = 0.0f / 255.0f;
    myTable.g = 255.0f / 255.0f;
    myTable.b = 255.0f / 255.0f;
    myTable.a = 1.0f;
    
    m_map_titleRankColor.insert(TitleRankColor::value_type("FirstRank",myTable));
bool CHARACTER::IsPublicRank(const char * c_szName);
{
	if (!*c_szName)
		return false;
	
	TitleRankColor::iterator it = m_map_titleRankColor.find(c_szName);

	if (it == m_map_titleRankColor.end())
		return false;

	return true;
}

Check if rank is exist in map or not.

 

Command from client ;

ACMD (do_new_title_system)
{
	if (!ch)
		return;
	
	char arg1[256];
	one_argument(argument, arg1, sizeof(arg1));
	
	if(!*arg1)
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "usage new_title_system <rankname>");
		return;
	}
	
	if (!ch->IsPublicRank(arg1))
	{
		ch->ChatPacket(CHAT_TYPE_INFO, "This rank is not find!");
		return;
	}
	
	ch->SetTitle(arg1);
}

Rest of them is easy..

 

#Edit 2

  • System is checking your query. If it's update or not.
  • Added command.
  • Added class.

 

You must put these things in public like this ;

class CMetin2Dev : public singleton<CMetin2Dev>
{
	public:
		CMetin2Dev();
		virtual ~CMetin2Dev();
		struct colorTable
		{
			float r;
			float g;
			float b;
			float a;
		} ColorTable;

		typedef TR1_NS::unordered_map<std::string, colorTable> TitleRankColor;
		TitleRankColor m_map_titleRankColor;
		
		void SetTitle(const char * c_szName)
		bool IsPublicRank(const char * c_szName);
}

If you are put these things in private, your map will destroy from your file again and again :)

 

Kind Regards

Ken

Edited by Ken
  • Love 2

Do not be sorry, be better.

Link to comment
Share on other sites

Good idea, Ken :) You can also replace

std::auto_ptr<SQLMsg> pMsg(DBManager::Instance().DirectQuery("UPDATE player.player SET title = '%s' WHERE id = %u",c_szRankName,GetPlayerID()));

 

with

 

DBManager::Instance().Query("UPDATE player.player SET title = '%s' WHERE id = %u",c_szRankName,GetPlayerID());

 

Since you aren't storing the result in a variable. It's better to not use DirectQuery unless you're selecting :)

  • Love 3
Link to comment
Share on other sites

Good idea, Ken :) You can also replace

std::auto_ptr<SQLMsg> pMsg(DBManager::Instance().DirectQuery("UPDATE player.player SET title = '%s' WHERE id = %u",c_szRankName,GetPlayerID()));

 

with

 

DBManager::Instance().Query("UPDATE player.player SET title = '%s' WHERE id = %u",c_szRankName,GetPlayerID());

 

Since you aren't storing the result in a variable. It's better to not use DirectQuery unless you're selecting :)

 

I like to use smart pointers. That's better and clearly for me.

 

#Edit 1

 

I added last query in function for check :) 

 

Thanks for comment.

 

Kind Regards

Ken

Edited by Ken

Do not be sorry, be better.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.