Battle Brothers
0 of 0

File information

Last updated

Original upload

Created by

hackflow

Uploaded by

hackflow

Virus scan

Safe to use

About this mod

A thing to take the place of lacking Squirrel/Battle Brothers standard library. An assortment of various utils to help coding mods.

Requirements
Permissions and credits
Changelogs
This does not alter game by itself. It's purpose it to make other modders' lives easier. 

Here is a glimpse of how this could be used. See full docs on Github.


// Make local aliases for std namespaces
local Rand = ::std.Rand, Re = ::std.Re, Str = ::std.Str, Text = ::std.Text,
    Debug = ::std.Debug.with({prefix = "mymod: "});

// Choose a random weapon
local weapon = Rand.choice(["scramasax" "ancient/khopesh" "falchion"]);
actor.m.Items.equip(::new("scripts/items/weapons/" + weapon));

// Same but with different weights
local weapon = Rand.choice(["scramasax" "ancient/khopesh" "falchion"], [4 2 1]);
...

// Dropping loot for a wolf
local n = 1 + Rand.poly(2, ::World.Assets.getExtraLootChance());
local items = Rand.choices(n, ["werewolf_pelt_item" "adrenaline_gland_item"], [70 30]);
foreach (item in items) {
local loot = ::new("scripts/items/misc/" + item);
loot.drop(_tile)
}

// Log that, accepts arbitrary nested data structure
Debug.log("loot for wolf", items);
// Will log "mymod: loot for wolf = [werewolf_pelt_item adrenaline_gland_item]"

// Roll weighted talent stars
foreach (i in Rand.take(3, [0 1 2 3 4 5 6 7], weights)) {
local w = weights[i];
_player.m.Talents[i] = Rand.choice([1 2 3], [60 30*w 10*w]);
}

// Various str utils
local short = Str.cutprefix(name, "Ancient ");
if (Str.startswith("background.legends_", this.getID())) ...
Str.join("_", split(id, "."))

// Regexes
local romanNumber = Re.find(this.getName(), " ([IVXLC]+)$");
local versionNums = Re.all("1.4.25", @"\d+"); // ["1", "4", "25"]

// Patch tooltip text, add 5 to chance to hit, and make it green color
local tooltip = getTooltip();
tooltip[i].text = Re.replace(tooltip[i].text,
@"(\d+)(% chance to hit)",
@(x, end) Text.positive(x.tointeger() + 5) + end);


Compatibility

Is compatible with everything. Does not modify the game only provides useful utilities. Is safe to add and remove at any time.

Additionally, stdlib is guaranteed to be backwards compatible, i.e. it is always safe to upgrade it to a newer version. This covers all the functions and their params documented here, any pieces not metioned there should not be used.

Feedback

Any suggestions, bug reports, other feedback are welcome. The best place for it is Github, i.e. just create an issue. Creating a comment here is also fine.