OriOriOri Posted July 16, 2024 Share Posted July 16, 2024 Hi! Trying to give characters unique battlecries for fighting shadow- and lunar-aligned creatures. Mod doesn't crash, but doesn't seem to work at all. Not sure what I'm doing wrong, if anyone could point me in the right direction I would be endlessly grateful! Modmain attached below. I am aware it's not very elegant, just trying to get it to work at all. modmain.lua Link to comment https://forums.kleientertainment.com/forums/topic/158306-request-modded-battlecries-help/ Share on other sites More sharing options...
ClumsyPenny Posted July 16, 2024 Share Posted July 16, 2024 You're assuming that the battlecry is tag based, but actually it's mostly prefab name based. Here's the code that handles it as an example: local function battlecrystring(combat, target) return target ~= nil and target:IsValid() and GetString( combat.inst, "BATTLECRY", (target:HasTag("prey") and not target:HasTag("hostile") and "PREY") or (string.find(target.prefab, "pig") ~= nil and target:HasTag("pig") and not target:HasTag("werepig") and "PIG") or target.prefab ) or nil end "PREY" and "PIG" has some unique checks, but it's not as a simple as having the tag, and that's just their custom behavior. In most other cases it defaults to using the target's prefab name, which is why it's not working for you. To solve this, rather than having an entry for every prefab that's shadow/lunar aligned (which would most likely become outdated next update), you can hook into the functions that handle this and add your own behavior. This code I made should work, it goes in modmain: AddPlayerPostInit(function(inst) if not GLOBAL.TheWorld.ismastersim then return end if inst.components.combat ~= nil then local function GetAlignedModifier(target) return (target:HasTag("shadow_aligned") and "SHADOW_ALIGNED") or (target:HasTag("lunar_aligned") and "LUNAR_ALIGNED") or nil end -- Hook into GetBattleCryString local _old_getbattlecrystring = inst.components.combat.GetBattleCryString inst.components.combat.GetBattleCryString = function(combat, target, ...) if target ~= nil and target:IsValid() then local modifier = GetAlignedModifier(target) if modifier ~= nil then return GLOBAL.GetString(combat.inst, "BATTLECRY", modifier) or nil end end if _old_getbattlecrystring ~= nil then return _old_getbattlecrystring(combat, target, ...) end end -- Hook into GetGiveUpString local _old_getgiveupstring = inst.components.combat.GetGiveUpString inst.components.combat.GetGiveUpString = function(combat, target, ...) if target ~= nil then local modifier = GetAlignedModifier(target) if modifier ~= nil then return GLOBAL.GetString(combat.inst, "COMBAT_QUIT", modifier) or nil end end if _old_getgiveupstring ~= nil then return _old_getgiveupstring(combat, target, ...) end end end end) If you have any questions, feel free to ask. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/158306-request-modded-battlecries-help/#findComment-1735635 Share on other sites More sharing options...
OriOriOri Posted July 16, 2024 Author Share Posted July 16, 2024 THANK YOU SO MUCH!!! 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/158306-request-modded-battlecries-help/#findComment-1735764 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now