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

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

Forkz

Well-Known Member
Joined
Jun 29, 2020
Messages
360
Solutions
1
Reaction score
76
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
 
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.
 
Back
Top