• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

TFS 1.X+ C++ Condition if in bool config.lua true/false

Forkz

Advanced OT User
Joined
Jun 29, 2020
Messages
586
Solutions
17
Reaction score
159
C++:
bool Spawn::spawnMonster(uint32_t spawnId, spawnBlock_t sb, bool startup/* = false*/)
{
    bool isBlocked = !startup && findPlayer(sb.pos);
    size_t monstersCount = sb.mTypes.size(), blockedMonsters = 0;

    const auto spawnFunc = [&](bool roll) {
        for (const auto& pair : sb.mTypes) {
            if (isBlocked && !pair.first->info.isIgnoringSpawnBlock) {
                ++blockedMonsters;
                continue;
            }

            if (!roll) {
                return spawnMonster(spawnId, pair.first, sb.pos, sb.direction, startup);
            }

            if (pair.second >= normal_random(1, 100) && spawnMonster(spawnId, pair.first, sb.pos, sb.direction, startup)) {
                return true;
            }
        }

        return false;
    };

    // Try to spawn something with chance check, unless it's single spawn
    if (spawnFunc(monstersCount > 1)) {
        return true;
    }

    // Every monster spawn is blocked, bail out
    if (monstersCount == blockedMonsters) {
        return false;
    }

    // Just try to spawn something without chance check
    return spawnFunc(false);
}

C++:
if (!g_config.getBool(ConfigManager::ALLOW_BLOCK_SPAWN))
do it
C++:
bool isBlocked = !startup && findPlayer(sb.pos);
if no
C++:
bool isBlocked = false
 
Solution
You have 3 values and all of them have to be true for it to happen. If 1 of it is false (which is your false in config.lua) then it will stay false.
Line 8
C++:
if (isBlocked && !pair.first->info.isIgnoringSpawnBlock && g_config.getBool(ConfigManager::ALLOW_BLOCK_SPAWN)) {
 
Line 8
C++:
if (isBlocked && !pair.first->info.isIgnoringSpawnBlock && g_config.getBool(ConfigManager::ALLOW_BLOCK_SPAWN)) {

C++:
bool Spawn::spawnMonster(uint32_t spawnId, spawnBlock_t sb, bool startup/* = false*/)
{
    bool isBlocked = !startup && findPlayer(sb.pos);
    size_t monstersCount = sb.mTypes.size(), blockedMonsters = 0;

    const auto spawnFunc = [&](bool roll) {
        for (const auto& pair : sb.mTypes) {
            if (isBlocked && !pair.first->info.isIgnoringSpawnBlock && g_config.getBool(ConfigManager::ALLOW_BLOCK_SPAWN)) {
                ++blockedMonsters;
                continue;
            }

            if (!roll) {
                return spawnMonster(spawnId, pair.first, sb.pos, sb.direction, startup);
            }

            if (pair.second >= normal_random(1, 100) && spawnMonster(spawnId, pair.first, sb.pos, sb.direction, startup)) {
                return true;
            }
        }

        return false;
    };

    // Try to spawn something with chance check, unless it's single spawn
    if (spawnFunc(monstersCount > 1)) {
        return true;
    }

    // Every monster spawn is blocked, bail out
    if (monstersCount == blockedMonsters) {
        return false;
    }

    // Just try to spawn something without chance check
    return spawnFunc(false);
}

config.lua
LUA:
AllowBlockRespawn = false
If I do like this "bool isBlocked = !startup && findPlayer(sb.pos);" will stay = false?
 
You have 3 values and all of them have to be true for it to happen. If 1 of it is false (which is your false in config.lua) then it will stay false.
 
Solution
Back
Top