• 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 0.x] Bed sleep outside houses

zezin009

Member
Joined
May 30, 2019
Messages
49
Reaction score
24
Well, since I didn't saw anything like this, I'll register this idea then.

Hello everyone, this one is to able any player sleep in any bed, anywhere (for TSF 0.3.6). You'll need change your source files in beds.cpp.

The commentary part is the original sentence. The first change is for 'canUse':
C++:
bool BedItem::canUse(Player* player)
{
    if(!house || !player || player->isRemoved() || (!player->isPremium() && g_config.getBool(
        ConfigManager::BED_REQUIRE_PREMIUM)) || player->hasCondition(CONDITION_INFIGHT))
        return isBed(); //return false

Then, the second change is for 'sleep', (you may notice that I only commented the first two lines):
C++:
void BedItem::sleep(Player* player)
{
    //if(!house || !player || player->isRemoved())
    //    return;

Third part is for 'wake up' (commented only, again):
C++:
void BedItem::wakeUp()
{
    //if(!house)
    //    return;

And finally, if you want to speed up the regeneration time, it is possible to do it in 'regeneratePlayer':
C++:
void BedItem::regeneratePlayer(Player* player) const
{
    const int32_t* sleepStart = getIntegerAttribute("sleepstart");
    int32_t sleptTime = (int32_t)time(NULL) - (sleepStart ? *sleepStart : 0);
    if(Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT))
    {
        int32_t amount = sleptTime; // / 30;
        if(condition->getTicks() != -1)
        {
            amount = std::min((condition->getTicks() / 1000), sleptTime); // / 30;
            int32_t tmp = condition->getTicks() - (amount * 30000);
            if(tmp <= 0)
                player->removeCondition(condition);
            else
                condition->setTicks(tmp);
        }
        player->changeHealth(amount);
        player->changeMana(amount);
    }
    player->changeSoul((int32_t)std::max((float)0, (float)sleptTime / (60 * 15)));
}

But this part you can change however you want it, notice that I left the soul regeneration untouched, but is possible to change it! That's it, I hope you like it!

Please, rep+
 
C++:
    //if(!house || !player || player->isRemoved())
    //    return;
You are possibly generating segfault here. You should have only removed that "!house" condition, but not the whole lines.

C++:
bool BedItem::canUse(Player* player)
{
    if(!house || !player || player->isRemoved() || (!player->isPremium() && g_config.getBool(
        ConfigManager::BED_REQUIRE_PREMIUM)) || player->hasCondition(CONDITION_INFIGHT))
        return isBed(); //return false
Same here, don't get rid of that "return false", but the "!house".
 
You are possibly generating segfault here. You should have only removed that "!house" condition, but not the whole lines.


Same here, don't get rid of that "return false", but the "!house".

Well notice! Thanks for the advice =)
 
Back
Top