• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Help with getDataInt

Rafael Hamdan

OT Developer
Joined
Dec 12, 2007
Messages
98
Reaction score
1
Location
Brasil - Minas Gerais
Hello boys!

I'm using Trunk Revision 906 (latest revision), and today, I created an event on my PVP-ENFORCED ACCOUNT server: the player who gets more frags in 1 month will gain a SPECIAL WEAPON.

So I decided to create a page on my website which shows the ranking, but it works like that:

mysql_query("SELECT * FROM playersfrags ORDER BY 'frags' DESC LIMIT 10")

It shows 10 players who got more frags. All right, but I edited at sources (I don't like creaturescripts), to insert in the table "playersfrags":

I MADE THIS WAY:

At iologindata.cpp

Code:
bool IOLoginData::addDeathToRanking(std::string name)
{
	Database* db = Database::getInstance();
	DBQuery query;
	DBResult* result;

	query << "SELECT `name` FROM `playersfrags` WHERE `name` = " << db->escapeString(name);
	if(!(result = db->storeQuery(query.str()))){
		query.str("");
		query << "INSERT INTO `playersfrags` (`name`, `frags`) VALUES (" << db->escapeString(name) << ", '1')";
		return db->executeQuery(query.str());
    }
         
    do
    {
        uint32_t frags = result->getDataInt("frags");
        uint32_t newfrags;
        newfrags = frags + 1;
       	query.str("");
	    query << "UPDATE `playersfrags` SET `frags` = " << newfrags << " WHERE `name` = " << db->escapeString(name);
	    return db->executeQuery(query.str());
     }
	while(result->next());
    db->freeResult(result);

}

at iologindata.h

Code:
		//DeathRanking System
		bool addDeathToRanking(std::string name);

and at player.cpp (all getCorpse function):

Code:
Item* Player::getCorpse()
{
	Item* corpse = Creature::getCorpse();
	if(corpse && corpse->getContainer())
	{
		Creature* lastHitCreature = NULL;
		Creature* mostDamageCreature = NULL;
		char buffer[165];
		if(getKillers(&lastHitCreature, &mostDamageCreature) && lastHitCreature)
			sprintf(buffer, "You recognize %s. %s was killed by %s.", getNameDescription().c_str(), (getSex() == PLAYERSEX_FEMALE ? "She" : "He"), lastHitCreature->getNameDescription().c_str());
		else
			sprintf(buffer, "You recognize %s.", getNameDescription().c_str());
		corpse->setSpecialDescription(buffer);
		
		//DeathRanking by Rafael Hamdan
		std::string playerNameToRank = lastHitCreature->getNameDescription().c_str();
	    if(!IOLoginData::getInstance()->addDeathToRanking(playerNameToRank))
	    std::cout << "Could not add " << getName() << "'s death to death ranking." << std::endl;
	    }
	    //End of DeathRanking
	    
	return corpse;
}

But I get an error saying: Error during getDataInt(frags)

What's wrong?

Yours,
Rafael Hamdan;
 
First. Why store name? Wouldnt it be better to have just a player id in db? ;)
Instead:
Code:
    do
    {
        uint32_t frags = result->getDataInt("frags");
        uint32_t newfrags;
        newfrags = frags + 1;
       	query.str("");
	    query << "UPDATE `playersfrags` SET `frags` = " << newfrags << " WHERE `name` = " << db->escapeString(name);
	    return db->executeQuery(query.str());
     }
	while(result->next());
Place:
Code:
query << "UPDATE `playersfrags` SET `frags` = " << "frags + " << 1 << " WHERE `name` = " << db->escapeString(name);
        return db->executeQuery(query.str());
 
Maybe because monsters don't have an ID, anh?

I'll add another column later, is_player, so I'll be able to separate at Top Fraggers monsters from players.

Well, anyway, thanks for your help, I'm not very good in C++, I'm still learning, and since it's very similiar to PHP and other programming languages, it's going well... thanks!

Yours,
Rafael Hamdan;
 
Last edited:
Back
Top