• 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!

Compiling how to send a simple command to table mysql

chupaescadatri

Banned User
Joined
Jul 5, 2014
Messages
338
Reaction score
49
this is part of the source of my tfs
how do I send him the name that will be killed by "NAME".
to my mysql table?

Code:
Item* corpse = Creature::getCorpse();
    if(corpse && corpse->getContainer())
    {
        Creature* lastHitCreature_ = NULL;
        Creature* mostDamageCreature = NULL;
        char buffer[190];
        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);
 
If your trying to store a player who was killed by the last person who attacked them in a database so you can list them on your website then this can be handled in a script rather altering the sources.

We'll need more information than just a fragment of code, like the tfs version, the more information you can provide the easier it is for people to help you.
 
If your trying to store a player who was killed by the last person who attacked them in a database so you can list them on your website then this can be handled in a script rather altering the sources.

We'll need more information than just a fragment of code, like the tfs version, the more information you can provide the easier it is for people to help you.
It is that the version of tfs I use does not work the command "/ death"
when a player dies, the tfs does not send for any mysql table,
ie whenever vc of the command "/ death" he does not pull any death, for the tfs itself does not send pro mysql, so I imagine it must be done at source.
It is tfs 0.3.0
source:
http://sourceforge.net/p/otos/code/HEAD/tree/TheForgottenServer/

I need only the lvl that the character died and the guy's name who gave the last hit.
not need anything else if it is difficult, kind died to summon or to guild, do not need only the last hit and lvl'd be great.
 
There is no guarantee this will work, but here ya go :)

place this on line 29 of player.cpp
Code:
#include "database.h"

Place this inside void Player::death() starting on line 2160 of player.cpp right under sendSkills();
Code:
   Creature* lastHitCreature = NULL;
   Creature* mostDamageCreature = NULL;

   if(getKillers(&lastHitCreature, &mostDamageCreature) && lastHitCreature)
   {
     Database* db = Database::getInstance();
     DBQuery query;

     query = "INSERT INTO `player_death` (`name`, `level`, `killer`) VALUES(" << getNameDescription() << ", " << level << ", " << lastHitCreature->getNameDescription() << ");";

     if(!db->executeQuery(query.str()))
        // do nothing
   }

and run this query in your database
Code:
CREATE TABLE `player_death`(
   `id` INT NOT NULL AUTO_INCREMENT,
   `name` VARCHAR(255) NOT NULL,
   `level` INT NOT NULL DEFAULT 1,
   `killer` VARCHAR(255) NOT NULL DEFAULT '',
   PRIMARY KEY (`id`),
   FOREIGN KEY (`name`) REFERENCES `players`(`name`) ON DELETE CASCADE,
)ENGINE = InnoDB;
 
Last edited:
There is no guarantee this will work, but here ya go :)

place this on line 29 of player.cpp
Code:
#include "database.h"

Place this inside void Player::death() starting on line 2160 of player.cpp right under sendSkills();
Code:
   Creature* lastHitCreature = NULL;
   Creature* mostDamageCreature = NULL;

   if(getKillers(&lastHitCreature, &mostDamageCreature) && lastHitCreature)
   {
     Database* db = Database::getInstance();
     DBQuery query;

     query = "INSERT INTO `player_death` (`name`, `level`, `killer`) VALUES(" << getNameDescription() << ", " << level << ", " << lastHitCreature->getNameDescription() << ");";

     if(!db->executeQuery(query.str()))
        // do nothing
   }

and run this query in your database
Code:
CREATE TABLE `player_death`(
   `id` INT NOT NULL AUTO_INCREMENT,
   `name` VARCHAR(255) NOT NULL,
   `level` INT NOT NULL DEFAULT 1,
   `killer` VARCHAR(255) NOT NULL DEFAULT '',
   PRIMARY KEY (`id`),
   FOREIGN KEY (`name`) REFERENCES `players`(`name`) ON DELETE CASCADE,
)ENGINE = InnoDB;
Thank you for strength, but it did not work, it does not compile, the error on line
query = "INSERT INTO` player_death` (`name`,` level`, `killer`) VALUES (" << getNameDescription () << "," << level << "," << lastHitCreature-> getNameDescription () << ");";
probably it sends the query with other codes
I took a look at ban.cpp to see how the query works, and I thought we did not know if it has something to do:
Code:
{
    Database* db = Database::getInstance();
    DBQuery query;
    query << "UPDATE `bans` SET `active` = 0 WHERE `expires` = 0";
    return db->executeQuery(query.str());
}
 
Back
Top