Skip to content

Instantly share code, notes, and snippets.

@Suor
Last active January 23, 2025 16:04
Show Gist options
  • Save Suor/f2008dfcb1afcd9ecaef1dc1c440ae52 to your computer and use it in GitHub Desktop.
Save Suor/f2008dfcb1afcd9ecaef1dc1c440ae52 to your computer and use it in GitHub Desktop.
Item Flags for Battle Brothers
local index, index2item;
mod.hook("scripts/states/world_state", function (q) {
q.onBeforeSerialize = @(__original) function (_out) {
index = 0;
__original(_out);
}
q.onBeforeDeserialize = @(__original) function (_in) {
index = 0;
index2item = {}
__original(_in);
}
})
mod.hook("scripts/statistics/statistics_manager", function (q) {
q.onDeserialize = @(__original) function (_in) {
__original(_in);
foreach (i, item in index2item) {
local packed = this.getFlags().get("itemflags:" + i);
if (packed) item.m.flags <- ::std.Util.unpack(packed);
}
index2item = null; // Release all the items refs
}
})
mod.hook("scripts/items/item", function (q) {
q.m.flags <- {};
q.onSerialize = @(__original) function (_out) {
index++;
if (this.m.flags.len() > 0)
::World.Statistics.getFlags().set("itemflags:" + index, ::std.Util.pack(this.m.flags));
else
::World.Statistics.getFlags().remove("itemflags:" + index);
__original(_out);
}
q.onDeserialize = @(__original) function (_in) {
index++;
index2item[index] <- this;
__original(_in);
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment