• 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 How to change the spawn delay time according to the number of online players?

dudie

Member
Joined
May 23, 2016
Messages
128
Reaction score
12
All my monsters spawn in 60 seconds after die

I want change it according the players online

I'm trying to make something like it:

Code:
rateSpawn = 1 + (playerCount > 0 and (playerCount / 50) or 0),

Where I need to edit in my sources?
I'm using 0.4

I've tried change in spawn.h
Code:
uint32_t getInterval() const {return interval;}

To
Code:
  uint32_t getInterval() const {
  double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
  return (uint32_t)std::ceil(interval / bonusinterval);
  }

Full code
http://hastebin.com/ohuheqicox.cs

But I got some errors:
Code:
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

What I supossed to do?
 
Last edited:
The getPlayersOnline function returns a table not a number so to resolve the error you can simply place a hashtag ( # ) in front of the function to return the length of the table.
Since its a talk action and not an event you don't need to worry too much about a divide by zero error although in good practice these preventive measures should still be set in place.
So the config table should be defined like this.
Code:
-- we only need to call #getPlayersOnline() 1 time
-- this will update per call to the script
local playerCount = #getPlayersOnline()
local config = {
  rateExperience = getConfigInfo('rateExperience'),
  rateSkill = getConfigInfo('rateSkill') * 3,
  rateMagic = getConfigInfo('rateMagic') * 3,
  -- here we include some form of prevent incase staff members are excluded from
  -- the count of online players
  rateSpawn = 1 + (playerCount > 0 and (playerCount / 50) or 0),
  protectionLevel = getConfigInfo('protectionLevel'),
  stages = getBooleanFromString(getConfigInfo('experienceStages'))
}
There is a problem tho with this formula the respawn rate isn't considered a decimal value so all values after the decimal will be lost you would need to rethink how your formula would work otherwise under most circumstances you would be adding 0 and spawn rate would be stuck at 1.
 
The getPlayersOnline function returns a table not a number so to resolve the error you can simply place a hashtag ( # ) in front of the function to return the length of the table.
Since its a talk action and not an event you don't need to worry too much about a divide by zero error although in good practice these preventive measures should still be set in place.
So the config table should be defined like this.
Code:
-- we only need to call #getPlayersOnline() 1 time
-- this will update per call to the script
local playerCount = #getPlayersOnline()
local config = {
  rateExperience = getConfigInfo('rateExperience'),
  rateSkill = getConfigInfo('rateSkill') * 3,
  rateMagic = getConfigInfo('rateMagic') * 3,
  -- here we include some form of prevent incase staff members are excluded from
  -- the count of online players
  rateSpawn = 1 + (playerCount > 0 and (playerCount / 50) or 0),
  protectionLevel = getConfigInfo('protectionLevel'),
  stages = getBooleanFromString(getConfigInfo('experienceStages'))
}
There is a problem tho with this formula the respawn rate isn't considered a decimal value so all values after the decimal will be lost you would need to rethink how your formula would work otherwise under most circumstances you would be adding 0 and spawn rate would be stuck at 1.


Oh TYYYYY, now i edit the topic =)
 
Oh TYYYYY, now i edit the topic =)
Move to spawn.cpp:
Code:
#include "game.h"

extern Game g_game;

Change in spawn.h the getInterval to this:
Code:
uint32_t getInterval();

And on spawn.cpp:
Code:
uint32_t Spawn::getInterval()
{
    double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
    return (uint32_t)std::ceil(interval / bonusinterval);
}
 
Move to spawn.cpp:
Code:
#include "game.h"

extern Game g_game;

Change in spawn.h the getInterval to this:
Code:
uint32_t getInterval();

And on spawn.cpp:
Code:
uint32_t Spawn::getInterval()
{
    double bonusinterval = 1 + (g_game.getPlayersOnline() / 50.);
    return (uint32_t)std::ceil(interval / bonusinterval);
}

Ty so much! I have no idea to how test it...
But you are a PRO, so i think its work...
 
Back
Top