Jump to content
Maintenance ×
×
×
  • Create New...
  • 0

Problem at creating a simply lua function C++


Krixius

Question

Hi dev

 

Actually im trying to add a new function but i don't know why this is working bad:

I have in player a new column called: rank and i want that this function returns the number that i have in rank but i don't know how to do it ._.

	int pc_get_rank(lua_State* L)
	{
		DBManager::instance().Query("SELECT rank FROM player.player WHERE name='%s' ", CQuestManager::instance().GetCurrentCharacterPtr()->GetName());
		
		lua_pushnumber(L, 0);
		return 1;
	}

 

Function returns me all time 0 in game

:D

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 1
	int pc_get_rank(lua_State* L)
	{
		LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
		if (!ch)
		{
			lua_pushnumber(L, 0);
			return 1;
		}
	
		char szQuery[512];
		snprintf(szQuery, sizeof(szQuery), "SELECT rank FROM player.player WHERE name='%s'", ch->GetName());
		std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szQuery));
		
		if (pMsg->Get()->uiNumRows > 0)
		{
			MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);

			int iRank = 0;
			str_to_number(iRank, row[0]);
			lua_pushnumber(L, iRank);
			return 1;
		}
		
		lua_pushnumber(L, 0);
		return 1;
	}

You are not pushing the query return value, you're pushing 0 all the time.

Not tested. Oh, and it is better to declare first the LPCHARACTER to avoid core crashes if it doesn't exists.

PS: Where did you get the Dev member? In a bet?

  • Love 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.


  • Activity

    1. 4

      problem Dargon Soul Changre Attribute

    2. 41

      Global Chat

    3. 4

      problem Dargon Soul Changre Attribute

    4. 2

      Startup Loading Window Library

    5. 28

      Ludus2: metin2 fan project

    6. 44

      Inbuild GR2 Animation

    7. 6

      Minimap Mob proto

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.