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

Compiling Help change spawnrates per players online

dudie

Member
Joined
May 23, 2016
Messages
128
Reaction score
12
I want change spawnrates in my server by players online

Change to:
Code:
rates spawn = rateSpawn(CONFIG.LUA ) + (playersonline / 50)

For example: if ratesspawn(config.lua) = 1
And have 100 players online
spawn rates = 1 + (100 / 50)
spawnrates = 3x

I'm using 0.4... I search in spawn.cpp and found it:
Code:
void Spawn::checkSpawn()
{
#ifdef __DEBUG_SPAWN__
std::clog << "[Notice] Spawn::checkSpawn " << this << std::endl;
#endif
Monster* monster;
uint32_t spawnId;

checkSpawnEvent = 0;
for(SpawnedMap::iterator it = spawnedMap.begin(); it != spawnedMap.end();)
{
spawnId = it->first;
monster = it->second;
if(monster->isRemoved())
{
if(spawnId)
spawnMap[spawnId].lastSpawn = OTSYS_TIME();

monster->unRef();
spawnedMap.erase(it++);
}
else
{
/*if(spawnId && !isInSpawnZone(monster->getPosition()) && monster->getIdleStatus())
g_game.internalTeleport(monster, monster->getMasterPosition(), true);

*/++it;
}
}

uint32_t spawnCount = 0;
for(SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it)
{
spawnId = it->first;
spawnBlock_t& sb = it->second;
if(spawnedMap.count(spawnId))
continue;

if(OTSYS_TIME() < sb.lastSpawn + sb.interval)
continue;

if(findPlayer(sb.pos))
{
sb.lastSpawn = OTSYS_TIME();
continue;
}

spawnMonster(spawnId, sb.mType, sb.pos, sb.direction);
++spawnCount;
if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN))
break;
}

if(spawnedMap.size() < spawnMap.size())
checkSpawnEvent = Scheduler::getInstance().addEvent(createSchedulerTask(getInterval(), boost::bind(&Spawn::checkSpawn, this)));
#ifdef __DEBUG_SPAWN__
else
std::clog << "[Notice] Spawn::checkSpawn stopped " << this << std::endl;
#endif
}

How to change?
 
Do you want to change the spawn rate? the interval between the time they spawn?

intervals for spawning is handled by -spawn.xml..
"spawntime"

search your sources for 'spawntime' for that.

Or

change the amount of monsters that spawn?

if you want to change the amount of monsters the magic happens here.

Code:
if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN))
break;
}

To
Code:
if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN)+ getPlayersOnlineCode)
break;
}


getPlayersOnlineCode would return 1, 2 , 3, 4+ or w.e your algo is depending on players online. idk your functions or source
 
Last edited:
Do you want to change the spawn rate? the interval between the time they spawn?

intervals for spawning is handled by -spawn.xml..
"spawntime"

search your sources for 'spawntime' for that.

Or

change the amount of monsters that spawn?

if you want to change the amount of monsters the magic happens here.

Code:
if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN))
break;
}

To
Code:
if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN)+ getPlayersOnlineCode)
break;
}


getPlayersOnlineCode would return 1, 2 , 3, 4+ or w.e your algo is depending on players online. idk your functions or source

Yeah i want change monster spawn time depending players online:
Make this
Code:
rates spawn = rateSpawn(CONFIG.LUA) + (playersonline / 50)

For example: if ratesspawn(config.lua) = 1
And have 100 players online
spawn rates = 1 + (100 / 50)
spawnrates = 3x

Everything i found in my spawns.cpp is it:
Code:
  uint32_t spawnCount = 0;
   for(SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it)
   {
     spawnId = it->first;
     spawnBlock_t& sb = it->second;
     if(spawnedMap.count(spawnId))
       continue;

     if(OTSYS_TIME() < sb.lastSpawn + sb.interval)
       continue;

     if(findPlayer(sb.pos))
     {
       sb.lastSpawn = OTSYS_TIME();
       continue;
     }

     spawnMonster(spawnId, sb.mType, sb.pos, sb.direction);
     ++spawnCount;
     if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN))
       break;
   }

But i dont understand this code...

my spawns.cpp
http://hastebin.com/eruvesivux.coffee
 
Yeah i want change monster spawn time depending players online:
Make this
Code:
rates spawn = rateSpawn(CONFIG.LUA) + (playersonline / 50)

For example: if ratesspawn(config.lua) = 1
And have 100 players online
spawn rates = 1 + (100 / 50)
spawnrates = 3x

Everything i found in my spawns.cpp is it:
Code:
  uint32_t spawnCount = 0;
   for(SpawnMap::iterator it = spawnMap.begin(); it != spawnMap.end(); ++it)
   {
     spawnId = it->first;
     spawnBlock_t& sb = it->second;
     if(spawnedMap.count(spawnId))
       continue;

     if(OTSYS_TIME() < sb.lastSpawn + sb.interval)
       continue;

     if(findPlayer(sb.pos))
     {
       sb.lastSpawn = OTSYS_TIME();
       continue;
     }

     spawnMonster(spawnId, sb.mType, sb.pos, sb.direction);
     ++spawnCount;
     if(spawnCount >= (uint32_t)g_config.getNumber(ConfigManager::RATE_SPAWN))
       break;
   }

But i dont understand this code...

my spawns.cpp
http://hastebin.com/eruvesivux.coffee

Your lookin at the wrong code for spawn time.. spawn count is the amount of monsters that spawn per interval.

So spawn time... Like I said before.. is handled in -spawn.xml. Theres a variable called "spawntime" that the distro reads.. Most of the time its default is 60.

After a quick search through your spawns.cpp.. I found the magic happens here.

Code:
int32_t interval = MINSPAWN_INTERVAL / 1000;
            if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
            {
                if(intValue <= interval)
                {
                    std::clog << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"
                        << " be less than " << interval << " seconds." << std::endl;
                    continue;
                }

                interval = intValue;
            }

You would change
Code:
interval = intValue;
to fit your algo needs

dunno when this is handled tho, never messed with spawns.
 
Last edited:
Your lookin at the wrong code for spawn time.. spawn count is the amount of monsters that spawn per interval.

So spawn time... Like I said before.. is handled in -spawn.xml. Theres a variable called "spawntime" that the distro reads.. Most of the time its default is 60.

After a quick search through your spawns.cpp.. I found the magic happens here.

Code:
int32_t interval = MINSPAWN_INTERVAL / 1000;
            if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
            {
                if(intValue <= interval)
                {
                    std::clog << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"
                        << " be less than " << interval << " seconds." << std::endl;
                    continue;
                }

                interval = intValue;
            }

You would change
Code:
int32_t interval = MINSPAWN_INTERVAL / 1000;
to fit your algo needs


Could you help me to make this logic code to work?

Code:
      std::string name = strValue;
       int32_t bonusinterval = 1 + (playeronline / 50);
       int32_t interval = MINSPAWN_INTERVAL / 1000 / bonusinterval;

       if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
       {
         if(intValue <= interval)
         {
           std::clog << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"
             << " be less than " << interval << " seconds." << std::endl;
           continue;
         }

         interval = intValue;
       }
 
Could you help me to make this logic code to work?

Code:
      std::string name = strValue;
       int32_t bonusinterval = 1 + (playeronline / 50);
       int32_t interval = MINSPAWN_INTERVAL / 1000;

       if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
       {
         if(intValue <= interval)
         {
           std::clog << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"
             << " be less than " << interval << " seconds." << std::endl;
           continue;
         }

         interval = intValue - bonusinterval;
       }
Code:
      std::string name = strValue;
       int32_t bonusinterval = 1 + (playeronline / 50);
       int32_t interval = MINSPAWN_INTERVAL / 1000;

       if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
       {
         if(intValue <= interval)
         {
           std::clog << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"
             << " be less than " << interval << " seconds." << std::endl;
           continue;
         }

         interval = intValue - bonusinterval;
       }
Youll have to find your playersonline function.. lowering the interval will make the monster spawn faster. right now if 50 players are online, your algorithm will lower it to 58 seconds.
 
Code:
      std::string name = strValue;
       int32_t bonusinterval = 1 + (playeronline / 50);
       int32_t interval = MINSPAWN_INTERVAL / 1000;

       if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
       {
         if(intValue <= interval)
         {
           std::clog << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"
             << " be less than " << interval << " seconds." << std::endl;
           continue;
         }

         interval = intValue - bonusinterval;
       }
Youll have to find your playersonline function.. lowering the interval will make the monster spawn faster. right now if 50 players are online, your algorithm will lower it to 58 seconds.


Thats are i request for you, the get players online function

I can't make
Code:
interval = intValue / bonusinterval;

???
 
Your lookin at the wrong code for spawn time.. spawn count is the amount of monsters that spawn per interval.

So spawn time... Like I said before.. is handled in -spawn.xml. Theres a variable called "spawntime" that the distro reads.. Most of the time its default is 60.

After a quick search through your spawns.cpp.. I found the magic happens here.

Code:
int32_t interval = MINSPAWN_INTERVAL / 1000;
            if(readXMLInteger(tmpNode, "spawntime", intValue) || readXMLInteger(tmpNode, "interval", intValue))
            {
                if(intValue <= interval)
                {
                    std::clog << "[Warning - Spawns::loadFromXml] " << name << " " << centerPos << " spawntime cannot"
                        << " be less than " << interval << " seconds." << std::endl;
                    continue;
                }

                interval = intValue;
            }

You would change
Code:
interval = intValue;
to fit your algo needs

This is parsed just once when server starts.

Code:
checkSpawnEvent = Scheduler::getInstance().addEvent(createSchedulerTask(getInterval(), boost::bind(&Spawn::checkSpawn, this)));

You want to manipulate the getInterval result.
 
Back
Top