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

Feature [TFS 1.X] All players from your account can enter to your house

Joe Rod

Discord: joerod1
Joined
Mar 16, 2011
Messages
499
Solutions
2
Reaction score
172
GitHub
joerod1
Hi again :D. With this code all the players from your account can enter to your house (they become owners too)

house.h


find
Code:
uint32_t owner = 0;

add below
Code:
uint32_t ownerAcc = 0;

find:
Code:
uint32_t getOwner() const {
    return owner;
}

add below:
Code:
void setOwnerAcc(uint32_t accId)
{
    this->ownerAcc = accId;
}
uint32_t getOwnerAcc() const {
    return ownerAcc;
}

house.cpp

find
Code:
owner = 0;

add below:
Code:
ownerAcc = 0;


find
Code:
    if (guid != 0) {
        std::string name = IOLoginData::getNameByGuid(guid);
        if (!name.empty()) {
            owner = guid;
            ownerName = name;

add below:
Code:
Database& db1 = Database::getInstance();
std::ostringstream query1;
query1 << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
DBResult_ptr result = db1.storeQuery(query1.str());
ownerAcc = result->getNumber<uint32_t>("account_id");

find
Code:
if (player->getGUID() == owner) {
    return HOUSE_OWNER;
}

add this below:
Code:
if (player->getAccount() == ownerAcc)
{
    return HOUSE_OWNER;
}

That's all :)
 
TFS 1.2

Error with this code:

Code:
Database& db1 = Database::getInstance();
std::ostringstream query1;
query1 << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
DBResult_ptr result = db1.storeQuery(query1.str());
ownerAcc = result->getNumber<uint32_t>("account_id");
 
Here is the code for TFS 1.2

Code:
std::ostringstream query;
            query << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
            DBResult_ptr result = Database::getInstance()->storeQuery(query.str());
            ownerAcc = result->getNumber<uint32_t>("account_id");
 
Here is the code for TFS 1.2

Code:
std::ostringstream query;
            query << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
            DBResult_ptr result = Database::getInstance()->storeQuery(query.str());
            ownerAcc = result->getNumber<uint32_t>("account_id");

Thxx :D here work ....
 
everytime i add the datavase code into the editor i get this error TFS 1.2 (technically 1.3)

Code:
Severity    Code    Description    Project    File    Line    Suppression State
Error (active)    E0461    initial value of reference to non-const must be an lvalue    theforgottenserver    G:\Tibia\forgottenserver-1.2\forgottenserver-1.2\src\house.cpp    100
 
Here is the code for TFS 1.2

Code:
std::ostringstream query;
            query << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
            DBResult_ptr result = Database::getInstance()->storeQuery(query.str());
            ownerAcc = result->getNumber<uint32_t>("account_id");
@Zombiegod are you using this? (and no, 1.2 is not 1.3, they are quite different)
 
@Zombiegod are you using this? (and no, 1.2 is not 1.3, they are quite different)
Both give the same error(yea folder says 1.2 but following guides and stuff, turns out i have 1.3)
Post automatically merged:

found the issue

change

C++:
Database& db1 = Database::getInstance();

too

C++:
Database* db1 = Database::getInstance();

Edited to correct the solution
 
Last edited:
Both give the same error(yea folder says 1.2 but following guides and stuff, turns out i have 1.3)
Post automatically merged:

found the issue

change

C++:
Database& db1 = Database::getInstance();

too

C++:
Database & db1 = Database::getInstance();
There is absolutely no way that fixes the problem, the two are compiled to the exact same instructions, any spaces after the first don't affect anything.
C++:
int a = 0;
int& b = a;
int & c = a; // the exact same
 
all i know is visual studios complained with that error and said

Code:
Severity    Code    Description    Project    File    Line    Suppression State
Error    C2440    'initializing': cannot convert from 'Database *' to 'Database &'    theforgottenserver    G:\Tibia\forgottenserver-1.2\forgottenserver-1.2\src\house.cpp    100

when i accidentally pressed build, changing it to "database &" got rid of the previous error.

Turns out that failed to compile, but exanging & for * allowed it too for some reason, i do not know i am not a coder.
 
Last edited:
Well i just tested, and even though it spit out a complaint while compiling (still compiled) it seems to be working without flaw.
 
figured i would update the code i told. If you are using the source.zip from releases section on github.

change
C++:
Database& db1 = Database::getInstance();
std::ostringstream query1;
query1 << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
DBResult_ptr result = db1.storeQuery(query1.str());
ownerAcc = result->getNumber<uint32_t>("account_id");

to


C++:
Database* db1 = Database::getInstance();
std::ostringstream query1;
query1 << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
DBResult_ptr result = db1->storeQuery(query1.str());
ownerAcc = result->getNumber<uint32_t>("account_id");
 
for TFS 1.3+

Follow everything but on the database part use this

Lua:
std::ostringstream query;
            Database& db = Database::getInstance();
            query << "SELECT `account_id` FROM `players` WHERE `id` = " << guid;
            DBResult_ptr result = db.storeQuery(query.str());
            ownerAcc = result->getNumber<uint32_t>("account_id");

welp
 
Last edited:
Back
Top