• 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?
 
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.

I'm sorry, i don't understand
 
in spawn.h there's a method getInterval https://github.com/otland/forgottenserver/blob/master/src/spawn.h
you should write additional code to change the return value of the method

example, cannot test right now:
Code:
uint32_t getInterval() const {
   double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
   return (uint32_t)std::ceil(interval / bonusinterval);
}
 
Last edited:
in spawn.h there's a method getInterval https://github.com/otland/forgottenserver/blob/master/src/spawn.h
you should write additional code to change the return value of the method

example, cannot test right now:
Code:
uint32_t getInterval() const {
   double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
   return (uint32_t)std::ceil(interval / bonusinterval);
}

Code:
Makefile:546: recipe for target 'actions.o' failed
make[1]: *** [actions.o] Error 1
make[1]: ** Esperando que outros processos terminem.
Makefile:546: recipe for target 'beds.o' failed
make[1]: *** [beds.o] Error 1
In file included from game.h:27:0,
  from chat.cpp:25:
spawn.h: In member function ‘uint32_t Spawn::getInterval() const’:
spawn.h:85:34: error: ‘g_game’ was not declared in this scope
  double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
  ^
Makefile:546: recipe for target 'chat.o' failed
make[1]: *** [chat.o] Error 1
 
You will probably need to add this code at the top of file, but I am not sure if it's also necessary to move this function into game.cpp now, and just leave a prototype in header file, or if current implementation (accessing global variables in header file) is fine.

Code:
#include "game.h"

extern Game g_game;
 
You mean it?

spawn.h
http://hastebin.com/ohuheqicox.cs

Errors
Code:
In file included from game.h:27:0,
  from chat.cpp:25:
spawn.h: In member function ‘uint32_t Spawn::getInterval() const’:
spawn.h:89:40: error: invalid use of incomplete type ‘class Game’
  double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
  ^
In file included from baseevents.h:22:0,
  from raids.h:26,
  from item.h:29,
  from tile.h:23,
  from map.h:26,
  from creature.h:28,
  from player.h:23,
  from party.h:20,
  from chat.h:24,
  from chat.cpp:18:
luascript.h:67:7: note: forward declaration of ‘class Game’
class Game;
  ^
In file included from game.h:27:0,
  from beds.cpp:25:
spawn.h: In member function ‘uint32_t Spawn::getInterval() const’:
spawn.h:89:40: error: invalid use of incomplete type ‘class Game’
  double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
  ^
In file included from baseevents.h:22:0,
  from raids.h:26,
  from item.h:29,
  from beds.h:20,
  from beds.cpp:19:
luascript.h:67:7: note: forward declaration of ‘class Game’
class Game;
  ^
In file included from game.h:27:0,
  from actions.cpp:30:
spawn.h: In member function ‘uint32_t Spawn::getInterval() const’:
spawn.h:89:40: error: invalid use of incomplete type ‘class Game’
  double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
  ^
In file included from baseevents.h:22:0,
  from actions.h:20,
  from actions.cpp:20:
luascript.h:67:7: note: forward declaration of ‘class Game’
class Game;
  ^
Makefile:546: recipe for target 'beds.o' failed
make[1]: *** [beds.o] Error 1
make[1]: ** Esperando que outros processos terminem.
Makefile:546: recipe for target 'chat.o' failed
make[1]: *** [chat.o] Error 1
Makefile:546: recipe for target 'actions.o' failed
make[1]: *** [actions.o] Error 1
make[1]: Leaving directory '/home/tiago/Documentos/warcera/3777/src'
Makefile:403: recipe for target 'all' failed
make: *** [all] Error 2
 
I tried to make !serverinfo to show this new system but i got some errors
Anyone could help me?

Code:
[18:6:20.583] [Error - TalkAction Interface]
[18:6:20.583] data/talkactions/scripts/serverinfo.lua
[18:6:20.583] Description:
[18:6:20.583] data/talkactions/scripts/serverinfo.lua:5: attempt to perform arithmetic on a table value
[18:6:20.583] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/serverinfo.lua)

Code:
local config = {
   rateExperience = getConfigInfo('rateExperience'),
   rateSkill = getConfigInfo('rateSkill') * 3,
   rateMagic = getConfigInfo('rateMagic') * 3,
   rateSpawn = 1 + (getPlayersOnline() / 50),
   protectionLevel = getConfigInfo('protectionLevel'),
   stages = getBooleanFromString(getConfigInfo('experienceStages'))
}

function onSay(cid, words, param, channel)
   local exp = config.rateExperience
   if(config.stages) then
     exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
   end
   exp = exp * 2
   local slots = getPlayerSlotItem(cid, 2)
   local rateLoot, rateGoldLoot
  if slots.itemid == 11393 then
     rateLoot = 4
     rateGoldLoot = 8
   else
     rateLoot = 2
     rateGoldLoot = 4
  end
   doPlayerPopupFYI(cid, "Server Information:\n\nExperience rate: 5x (stages)\nSkills rate: x" .. config.rateSkill .. "\nMagic rate: x" .. config.rateMagic .. "\nLoot rate: x" .. rateLoot .. "\nGold Loot rate: x" .. rateGoldLoot .. "\nSpawns rate: x" .. config.rateSpawn .. "\nHEAL/DMG based only on SKILLS!\nThis server will never reset!")
   return true
end

And pls help author topic i really want this system working =)
 
I tried to make !serverinfo to show this new system but i got some errors
Anyone could help me?

Code:
[18:6:20.583] [Error - TalkAction Interface]
[18:6:20.583] data/talkactions/scripts/serverinfo.lua
[18:6:20.583] Description:
[18:6:20.583] data/talkactions/scripts/serverinfo.lua:5: attempt to perform arithmetic on a table value
[18:6:20.583] [Warning - Event::loadScript] Cannot load script (data/talkactions/scripts/serverinfo.lua)

Code:
local config = {
   rateExperience = getConfigInfo('rateExperience'),
   rateSkill = getConfigInfo('rateSkill') * 3,
   rateMagic = getConfigInfo('rateMagic') * 3,
   rateSpawn = 1 + (getPlayersOnline() / 50),
   protectionLevel = getConfigInfo('protectionLevel'),
   stages = getBooleanFromString(getConfigInfo('experienceStages'))
}

function onSay(cid, words, param, channel)
   local exp = config.rateExperience
   if(config.stages) then
     exp = getExperienceStage(getPlayerLevel(cid), getVocationInfo(getPlayerVocation(cid)).experienceMultiplier)
   end
   exp = exp * 2
   local slots = getPlayerSlotItem(cid, 2)
   local rateLoot, rateGoldLoot
  if slots.itemid == 11393 then
     rateLoot = 4
     rateGoldLoot = 8
   else
     rateLoot = 2
     rateGoldLoot = 4
  end
   doPlayerPopupFYI(cid, "Server Information:\n\nExperience rate: 5x (stages)\nSkills rate: x" .. config.rateSkill .. "\nMagic rate: x" .. config.rateMagic .. "\nLoot rate: x" .. rateLoot .. "\nGold Loot rate: x" .. rateGoldLoot .. "\nSpawns rate: x" .. config.rateSpawn .. "\nHEAL/DMG based only on SKILLS!\nThis server will never reset!")
   return true
end

And pls help author topic i really want this system working =)
 
Back
Top