Last active
December 5, 2020 18:06
-
-
Save Suor/603cf6e06fee27c04e1d1c92e84f0e63 to your computer and use it in GitHub Desktop.
Hook enemy onInit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local gt = this.getroottable(); | |
::mods_hookNewObject("entity/tactical/enemies/orc_berserker", function(o) { | |
this.logInfo("tb: hook orc_berserker"); | |
local init = o.onInit; | |
o.onInit = function() { | |
this.logInfo("tb: orc_berserker onInit"); | |
init(); // Normal onInit | |
o.m.Skills.add(this.new("scripts/skills/perks/perk_backstabber")); | |
// Add beahavior to existing agent | |
o.m.Skills.add(this.new("scripts/skills/perks/perk_adrenalin")); | |
o.m.AIAgent.addBehavior(this.new("scripts/ai/tactical/behaviors/ai_adrenaline")); | |
// Change agent properties on the fly | |
o.m.AIAgent.m.Properties.TargetPriorityHitpointsMult *= 2; | |
// Replace ai agent | |
o.m.AIAgent = this.new("scripts/mod_true_balance/ai/tb_orc_berserker_agent"); | |
o.m.AIAgent.setActor(o); | |
// o.m.BaseProperties.Stamina += 5; | |
// o.m.BaseProperties.FatigueRecoveryRate -= 2; | |
} | |
local assignRandomEquipment = o.assignRandomEquipment; | |
o.assignRandomEquipment = function() { | |
assignRandomEquipment(); // Equip as usual | |
if (this.World.getTime().Days >= 40) return; // It's ok for day 40+ | |
// Earlier don't allow three headed flail | |
local weapon = this.m.Items.getItemAtSlot(gt.Const.ItemSlot.MainHand); | |
if (weapon && weapon.m.ID == "weapon.three_headed_flail") { | |
this.m.Items.unequip(weapon); | |
local weapons = [ | |
"weapons/scimitar", | |
"weapons/scimitar", | |
"weapons/oriental/nomad_mace", | |
"weapons/boar_spear", | |
"weapons/oriental/light_southern_mace", | |
"weapons/battle_whip" | |
]; | |
this.m.Items.equip(this.new("scripts/items/" + weapons[this.Math.rand(0, weapons.len() - 1)])); | |
} | |
}); | |
local function afterOnInit(script, func) { | |
::mods_hookNewObject(script, function(o) { | |
this.logInfo("tb: hook " + script); | |
local init = o.onInit; | |
o.onInit = function() { | |
// this.logInfo("tb: orc_berserker onInit"); | |
init(); // Normal onInit | |
func(o); | |
} | |
}); | |
} | |
afterOnInit("entity/tactical/enemies/orc_berserker", function (o) { | |
o.m.Skills.add(this.new("scripts/skills/perks/perk_backstabber")); | |
if (this.World.getDay() >= 50) { | |
o.m.BaseProperties.Stamina += 5; | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment