IMIsle Modkit
Pages in this area

population

Server

modkit.population controls which species players can pick on the character select screen. You can switch a species off, cap it at a number of players, or cap it at a share of the players who are online.

The server keeps two lists, the cooked classes (every species the server knows) and the available classes (what the select screen offers). The lock rewrites the available list as cooked classes minus blocked species. It checks again every 2 seconds and every time a player opens the select screen.

Things to know before you use it.

  • Nothing happens until you call setEnabled(true) or set an auto threshold. Rules alone do not block anything.
  • While the lock is active, the available list is built from all cooked species. A species you disabled in Game.ini comes back unless it has a rule with enabled = false.
  • The lock stops new spawns. It does not touch players who already play a blocked species.
  • Species names ignore case and punctuation, so "Tyrannosaurus" and "tyrannosaurus" mean the same species. "BP_Tyrannosaurus" does not. Use the names from modkit.population.species().
  • A cap counts living dinosaurs of online players.

modkit.population.setEnabled

modkit.population.setEnabled(enabled)

Parameter Type Description
enabled boolean master switch

Switching it off puts every cooked species back on the select screen.

modkit.population.setEnabled(true)

modkit.population.isEnabled

modkit.population.isEnabled()

Returns: two booleans. The first is the master switch. The second says if the lock is active right now, which is also true when the auto threshold is reached.

local enabled, active = modkit.population.isEnabled()

modkit.population.setAutoThreshold

modkit.population.setAutoThreshold(players)

Parameter Type Description
players integer the lock turns itself on when this many players are online. 0 switches the automatic mode off.
modkit.population.setAutoThreshold(40)

modkit.population.setRule

modkit.population.setRule(species, rule)

Parameter Type Description
species string species name
rule table fields below. Fields you leave out keep their old value.
Field Type Default Description
enabled boolean true false blocks the species completely
cap integer 0 highest number of players on this species. 0 means no cap.
percent boolean false true reads cap as a percentage of the online players, 0 to 100. The result is rounded and never lower than 1.
modkit.population.setRule("Tyrannosaurus", { cap = 4 })
modkit.population.setRule("Deinosuchus", { cap = 10, percent = true })
modkit.population.setRule("Troodon", { enabled = false })

modkit.population.enableSpecies, disableSpecies

modkit.population.enableSpecies(species) modkit.population.disableSpecies(species)

Short forms of setRule(species, { enabled = true }) and setRule(species, { enabled = false }). A cap that was set before stays.

modkit.population.disableSpecies("Herrerasaurus")

modkit.population.getRule, clearRule, rules

modkit.population.getRule(species) returns the rule table or nil. modkit.population.clearRule(species) removes the rule and returns true when there was one. modkit.population.rules() returns all rules. The keys are the normalised species names, lower case without punctuation.

for key, rule in pairs(modkit.population.rules()) do
  print(key, rule.enabled, rule.cap, rule.percent)
end

modkit.population.distribution

modkit.population.distribution()

Returns: a table species -> count of living dinosaurs, and the number of online players as second value.

local counts, online = modkit.population.distribution()
for species, n in pairs(counts) do print(species, n, online) end

modkit.population.blocked, isBlocked

modkit.population.blocked() returns an array of normalised species names that are blocked right now. modkit.population.isBlocked(species) returns a boolean.

Both return nothing blocked while the lock is not active.

if modkit.population.isBlocked("Tyrannosaurus") then
  print("no more rexes for now")
end

modkit.population.species

modkit.population.species()

Returns: array of species names from the server's cooked class list, including species added with modkit.roster.

print(table.concat(modkit.population.species(), ", "))

modkit.population.setExempt, isExempt

modkit.population.setExempt(player, exempt) modkit.population.isExempt(player)

Parameter Type Description
player player table or string player or Steam ID
exempt boolean true lets this player pick every species while the lock is active

An exempt player gets the full list about half a second after opening the select screen. The list is not saved, set it again after a server restart.

modkit.events.add("playerConnected", function(player)
  if player.admin then modkit.population.setExempt(player, true) end
end)

modkit.population.setEggCleanup

modkit.population.setEggCleanup(enabled)

With true the server destroys the nests of blocked species every 5 seconds while the lock is active. That closes the way around the lock through eggs. The search walks all game objects, so leave it off when you do not need it.

modkit.population.setEggCleanup(true)

modkit.population.apply

modkit.population.apply()

Evaluates the rules now instead of waiting for the next check.

Returns: the same array as blocked().

Event populationChanged

populationChanged(distribution, online) fires when the species counts differ from the last sweep. See events.