• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] Sohw output in menu item

Status
Not open for further replies.

Reloac

BETA Tester
Hey, I've been trying to work out how to output the data from a SQL Query (Magic Gold) to a menu item , if i have 20,000 MG, it would say "Collection > 20000 Magic Gold" - i tried adding %u to the title, to output the query result.. and adding CurrentMagicGold to the side, but errors so i have no clue :/

Code:
case GOSSIP_ACTION_INFO_DEF + 12:
		{
			QueryResult result = LoginDatabase.PQuery("SELECT magic_gold FROM account WHERE id='%u'", player->GetSession()->GetAccountId());
			if (!result)
			return;

			Field* fields = result->Fetch();
			uint32 currentMagicGold = fields[0].GetUInt32();
			player->ADD_GOSSIP_ITEM(0, "|Tinterface\\icons\\inv_misc_beer_04:30|t  Magic Gold Current : %u ", CurrentMagicGold, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 20);
		}
		break;
 
Last edited:

Tommy

Founder
ADD_GOSSIP_ITEM doesn't take param arguments, auto complete plainly tells you the arguments.

Instead, you could use std::eek:stringstream:

Code:
case GOSSIP_ACTION_INFO_DEF + 12:
    {
        QueryResult result = LoginDatabase.PQuery("SELECT magic_gold FROM account WHERE id='%u'", player->GetSession()->GetAccountId());
        if (!result)
            return;

        Field* fields = result->Fetch();
        uint32 currentMagicGold = fields[0].GetUInt32();
        std::ostringstream ss;
        ss << "|Tinterface\\icons\\inv_misc_beer_04:30|t"
             << "Magic Gold Current: "
             << CurrentMagicGold;
        player->ADD_GOSSIP_ITEM(0, ss.str().c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 20);
    }break;

or snprintf (this is example #2, I'd prefer ostringstream):

Code:
case GOSSIP_ACTION_INFO_DEF + 12:
    {
        QueryResult result = LoginDatabase.PQuery("SELECT magic_gold FROM account WHERE id='%u'", player->GetSession()->GetAccountId());
        if (!result)
            return;

        Field* fields = result->Fetch();
        uint32 currentMagicGold = fields[0].GetUInt32();
        char menu[100];
        snprintf(menu, 100, "|Tinterface\\icons\\inv_misc_beer_04:30|t Magic Gold Current: %u", CurrentMagicGold);
        player->ADD_GOSSIP_ITEM(0, menu, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 20);
    }break;
 

Reloac

BETA Tester
I was thinking snprintf but then my mind went blank, i don't know why i put params inside the gossip item haha, thanks anyhow works like a charm!
 
Status
Not open for further replies.
Top