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

Solved spawn monsters randomly

silveralol

Advanced OT User
Joined
Mar 16, 2010
Messages
1,480
Solutions
9
Reaction score
211
hello folks, then I'm here to ask something about the respawn, you know that in the tibia global the spawn of monster can be different.
different how ?
exemple: have a spawn with 2 monsters, 1 minotaur and 1 minotaur archer
each monster have ur own position to spawn right?
then, sometimes in the place of the minotaur can be spawned a minotaur archer
or the inverse, I want to implement it, to make my respawn random with the monsters that are in the spawn area
seems that is here:
Code:
bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/)
{
    std::unique_ptr<Monster> monster_ptr(new Monster(mType));
    if (startup) {
        //No need to send out events to the surrounding since there is no one out there to listen!
        if (!g_game.internalPlaceCreature(monster_ptr.get(), pos, true)) {
            return false;
        }
    } else {
        if (!g_game.placeCreature(monster_ptr.get(), pos, false, true)) {
            return false;
        }
    }
    Monster* monster = monster_ptr.release();
    if (!g_events->eventMonsterOnSpawn(monster)) {
        return false;
    }
    monster->setDirection(dir);
    monster->setSpawn(this);
    monster->setMasterPos(pos);
    monster->incrementReferenceCounter();

    spawnedMap.insert(spawned_pair(spawnId, monster));
    spawnMap[spawnId].lastSpawn = OTSYS_TIME();
    return true;
}
So I need some help with this ;)
 
Solution
Place this before spawnMonster(..)
const spawnBlock_t& randSb = std::next(spawnMap.begin(), uniform_random(0, spawnMap.size() - 1))->second;
Then replace sb.mType with randSb.mType

On cellphone so it may not be correct but it's something like that.
Hello,

What makes you think that this is a TibiaGlobal related behavior? Are you referring this to CipSoft files?
 
Hello,

What makes you think that this is a TibiaGlobal related behavior? Are you referring this to CipSoft files?
I think he means;

In Real Tibia, it works like this. blah blah
How can we implement this same behaviour in this source file?
 
He basically wants creature of the same type ( folder ) to spawn sometimes instead of the creature he put in RME so if we have--array of sqm basically monsters beside each other 1, 1, 2, 1, //1= minotaur 2= minotaur archer //he wants it to randomize so after killing those it would be for example 2, 2, 2, 1, and after that 1,1,2,2, and so on.
 
He basically wants creature of the same type ( folder ) to spawn sometimes instead of the creature he put in RME so if we have--array of sqm basically monsters beside each other 1, 1, 2, 1, //1= minotaur 2= minotaur archer //he wants it to randomize so after killing those it would be for example 2, 2, 2, 1, and after that 1,1,2,2, and so on.
WTF?
folder? bro, are you crazy ? I'm not saying about the folder, I'm saying about the "spawn area" you know, in RME you put a spawn area and in this area you put the monsters, right?
then I want to randomize the monsters of this spawn area
I use the exemple of minotaur to explain but have no relation with folders
 
WTF?
folder? bro, are you crazy ? I'm not saying about the folder, I'm saying about the "spawn area" you know, in RME you put a spawn area and in this area you put the monsters, right?
then I want to randomize the monsters of this spawn area
I use the exemple of minotaur to explain but have no relation with folders
i think he said that a minotaur will transform into an mino archer, etc (same race - same folder)
 
i think he said that a minotaur will transform into an mino archer, etc (same race - same folder)
Hmm... my bad so... :oops:
I have some ideas of the logic of the soluction
need a function:
getSpawnMonsters() // return an array with the monsters in the spawn area
then we can handle with the array and get the random monster to spawn
 
Find all calls of spawnMonster like:

spawnMonster(spawnId, sb.mType, sb.pos, sb.direction);

Replace sb.mType with a random mType inside the spawnMap.
 
Place this before spawnMonster(..)
const spawnBlock_t& randSb = std::next(spawnMap.begin(), uniform_random(0, spawnMap.size() - 1))->second;
Then replace sb.mType with randSb.mType

On cellphone so it may not be correct but it's something like that.
 
Solution
Place this before spawnMonster(..)
const spawnBlock_t& randSb = std::next(spawnMap.begin(), uniform_random(0, spawnMap.size() - 1))->second;
Then replace sb.mType with randSb.mType

On cellphone so it may not be correct but it's something like that.
sure, changed, but I see something in:
Code:
bool Spawn::addMonster(const std::string& name, const Position& pos, Direction dir, uint32_t interval)
{
    MonsterType* mType = g_monsters.getMonsterType(name);
    if (!mType) {
        std::cout << "[Spawn::addMonster] Can not find " << name << std::endl;
        return false;
    }

    this->interval = std::min(this->interval, interval);

    spawnBlock_t sb;
    sb.mType = mType;
    sb.pos = pos;
    sb.direction = dir;
    sb.interval = interval;
    sb.lastSpawn = 0;

    uint32_t spawnId = spawnMap.size() + 1;
    spawnMap[spawnId] = sb;
    return true;
}
spawnBlock_t sb; will affect ?
 
No.

The only "problem" in my code is that if you have a spawn with 9 minotaurs and 1 minotaur archer, the chance of spawning a minotaur archer in this area will be 1/10 and 9/10 for minotaurs.

If you want uniform distribution of monsters in the spawn you have to create a set of monstertypes in that spawn and get a random monstertype from this set instead of getting from the spawnMap
 
Last edited:
Place this before spawnMonster(..)
const spawnBlock_t& randSb = std::next(spawnMap.begin(), uniform_random(0, spawnMap.size() - 1))->second;
Then replace sb.mType with randSb.mType

On cellphone so it may not be correct but it's something like that.
omg teach me dud
I will buy you many books
 
No.

The only "problem" in my code is that if you have a spawn with 9 minotaurs and 1 minotaur archer, the chance of spawning a minotaur archer in this area will be 1/10 and 9/10 for minotaurs.

If you want uniform distribution of monsters in the spawn you have to create a set of monstertypes in that spawn and get a random monstertype from this set instead of getting from the spawnMap
not is a problem, this should be like that
 
Back
Top