This mod is for mod developers mostly. It will help with sandboxing mods that needs sandboxing.
I found myself using "a lot" of time sandboxing mods, so i made this. If anyone want to use it, feel free.
This will make your mod work when your player is in lobbies where others have the same mod and will compare amount of players in the lobby to how many have the mod, lobby filter is private or friends only or singleplayer. This all works when you as player is client or host of the lobby. More info in the file.
Check using
ifnot sandboxer:allow_mod() thenreturnend
or read the file code to use arguments in the function
You put hooks from the mod into your mod and copy the file into your mod then rename
local mod_to_check = "intimidate specials"
and use sandboxer:allow_mod() for checks in your functions. Your init functions are loaded before youre in the heist, so for a more dynamic toggle, you would have to make it yourself, not sure if what i have bellow would turn intimidation on/off dynamicly in game
elseif RequiredScript == "lib/units/enemies/cop/copbrain"then
intimsp_o_copbrain_post_init = intimsp_o_copbrain_post_init or CopBrain.post_init
functionCopBrain:post_init()
intimsp_o_copbrain_post_init(self)
ifnotself._logics.intimidated thenself._logics.intimidated = CopLogicIntimidated endifnotself._logics.flee thenself._logics.flee = CopLogicFlee endend
intimsp_o_convert_to_criminal = intimsp_o_convert_to_criminal or CopBrain.convert_to_criminal
functionCopBrain:convert_to_criminal(mastermind_criminal)
intimsp_o_convert_to_criminal(self, mastermind_criminal)
if sandboxer:allow_mod(true) then
managers.mission._fading_debug_output:script().log(string.format("%s", ".."), Color.green)
local category = self._unit:base()._tweak_table
local groupai = managers.groupai:state()
if groupai._special_units[category] then groupai._special_units[category][self._unit:key()] = nilendendendelseif RequiredScript == "lib/managers/playermanager"then
intimsp_o_has_upgrade = intimsp_o_has_upgrade or PlayerManager.has_category_upgrade
functionPlayerManager:has_category_upgrade(category, upgrade)return sandboxer:allow_mod() and upgrade == "intimidate_specials"or intimsp_o_has_upgrade(self, category, upgrade)
endend
This is what i tried to post as a mod before, it's dynamic
local surrender = CopLogicIdle._surrender
local on_intimidated = CopLogicIdle.on_intimidated
localfunctionrun_function(data, amount, aggressor_unit, ...)if sandboxer:allow_mod(true) and (data.unit:base()._tweak_table == "phalanx_vip") or (data.unit:base()._tweak_table == "phalanx_minion") thenreturn on_intimidated(data, amount, aggressor_unit, ...)
endreturn surrender(data, amount, aggressor_unit)
end
CopLogicIdle.on_intimidated = run_function
CopLogicArrest.on_intimidated = run_function
CopLogicSniper.on_intimidated = run_function
--Shield logic
CopBrain._logic_variants.shield.intimidated = CopLogicIntimidated
local _do_tied = CopLogicIntimidated._do_tied
local _chk_spawn_shield = CopInventory._chk_spawn_shield
local on_intimidated = CopLogicIntimidated.on_intimidated
functionCopLogicIntimidated.on_intimidated(data, amount, aggressor_unit, ...)if sandboxer:allow_mod(true) and data.unit:base()._tweak_table == "shield"then
_do_tied(data, aggressor_unit)
_chk_spawn_shield(data.unit:inventory())
else
on_intimidated(data, amount, aggressor_unit, ...)
endend
@✌Playhouse✌ So, this will essentially disable the mod when playing online with users who don't have it? And those who do, or if singleplayer, it will remain enabled.
I don't suppose you could link to an example mod that might use this framework? To see how it is implemented, that is.
You put hooks from the mod into your mod and copy the file into your mod then rename
local mod_to_check = "intimidate specials"
and use sandboxer:allow_mod() for checks in your functions. Your init functions are loaded before youre in the heist, so for a more dynamic toggle, you would have to make it yourself, not sure if what i have bellow would turn intimidation on/off dynamicly in game
elseif RequiredScript == "lib/units/enemies/cop/copbrain" then intimsp_o_copbrain_post_init = intimsp_o_copbrain_post_init or CopBrain.post_init function CopBrain:post_init() intimsp_o_copbrain_post_init(self) if not self._logics.intimidated then self._logics.intimidated = CopLogicIntimidated end if not self._logics.flee then self._logics.flee = CopLogicFlee end end intimsp_o_convert_to_criminal = intimsp_o_convert_to_criminal or CopBrain.convert_to_criminal function CopBrain:convert_to_criminal(mastermind_criminal) intimsp_o_convert_to_criminal(self, mastermind_criminal) if sandboxer:allow_mod(true) then managers.mission._fading_debug_output:script().log(string.format("%s", ".."), Color.green) local category = self._unit:base()._tweak_table local groupai = managers.groupai:state() if groupai._special_units[category] then groupai._special_units[category][self._unit:key()] = nil end end end elseif RequiredScript == "lib/managers/playermanager" then intimsp_o_has_upgrade = intimsp_o_has_upgrade or PlayerManager.has_category_upgrade function PlayerManager:has_category_upgrade(category, upgrade) return sandboxer:allow_mod() and upgrade == "intimidate_specials" or intimsp_o_has_upgrade(self, category, upgrade) end end
This is what i tried to post as a mod before, it's dynamic
local surrender = CopLogicIdle._surrender local on_intimidated = CopLogicIdle.on_intimidated local function run_function(data, amount, aggressor_unit, ...) if sandboxer:allow_mod(true) and (data.unit:base()._tweak_table == "phalanx_vip") or (data.unit:base()._tweak_table == "phalanx_minion") then return on_intimidated(data, amount, aggressor_unit, ...) end return surrender(data, amount, aggressor_unit) end CopLogicIdle.on_intimidated = run_function CopLogicArrest.on_intimidated = run_function CopLogicSniper.on_intimidated = run_function --Shield logic CopBrain._logic_variants.shield.intimidated = CopLogicIntimidated local _do_tied = CopLogicIntimidated._do_tied local _chk_spawn_shield = CopInventory._chk_spawn_shield local on_intimidated = CopLogicIntimidated.on_intimidated function CopLogicIntimidated.on_intimidated(data, amount, aggressor_unit, ...) if sandboxer:allow_mod(true) and data.unit:base()._tweak_table == "shield" then _do_tied(data, aggressor_unit) _chk_spawn_shield(data.unit:inventory()) else on_intimidated(data, amount, aggressor_unit, ...) end end
@✌Playhouse✌ So, this will essentially disable the mod when playing online with users who don't have it? And those who do, or if singleplayer, it will remain enabled.
@△urelius Yeah
@✌Playhouse✌ That is really cool, thanks.