I also use this extension and am getting the same issue. I wish there was a way to gift in the Forge because I would totally gift bmos this so he could figure it out...
Printable View
Thanks all the same, but nephranka already got me the info I needed.
Here is the fix:
open AutomaticFlankingAndRange.ext\campaign\scripts\cha r_weapon_afar.lua
replace everything from "function customOnAttackAction" to the end of the file with:
Code:function customOnAttackAction(draginfo)
--Debug.chat("my customOnAttackAction");
local nodeWeapon = getDatabaseNode();
local nodeChar = nodeWeapon.getChild("...")
-- Build basic attack action record
local rAction = CharWeaponManager.buildAttackAction(nodeChar, nodeWeapon);
-- bmos removing redundant ammo counting
-- for compatibility with ammunition tracker, make this change in your char_weapon.lua
-- this if section replaces the commented out line above: "CharWeaponManager.decrementAmmo(nodeChar, nodeWeapon);"
if not AmmunitionManager then
CharWeaponManager.decrementAmmo(nodeChar, nodeWeapon);
end
-- end bmos removing redundant ammo counting
-- Perform action
local rActor = ActorManager.resolveActor(nodeChar);
-- ActionAttack.performRoll(draginfo, rActor, rAction);
-- return true;
-- kent adding itemPath to rActor so that when effects are checked we can
-- make compare against action only effects
local _, sRecord = DB.getValue(nodeWeapon, "shortcut", "", "");
rActor.itemPath = sRecord;
-- end kent adding itemPath to rActor so that when effects are checked we can
-- bmos only allowing attacks when ammo is sufficient
-- for compatibility with ammunition tracker, make this change in your char_weapon.lua
-- this if section replaces the two commented out lines above:
-- "ActionAttack.performRoll(draginfo, rActor, rAction);" and "return true;"
local nMaxAmmo = DB.getValue(nodeWeapon, 'maxammo', 0)
local nMaxAttacks = nMaxAmmo - DB.getValue(nodeWeapon, 'ammo', 0)
if not AmmunitionManager or (not (nMaxAmmo > 0) or (nMaxAttacks >= 1)) then
ActionAttack.performRoll(draginfo, rActor, rAction);
return true;
else
ChatManager.Message(Interface.getString("char_message_atkwithnoammo"), true, rActor);
end
-- end bmos only allowing attacks when ammo is sufficient
end
Thanks bmos!
This did totally fix that issue with range & flanking. Had a few more to resolve but it is all working now.
Worked like a charm. A thousand thank yous good sir!
Totally.
In this case your fixes caught most of the others accept for Advanced effects. Once I used your link to the suggested fix (early in the thread) I was able to fold it into the advanced effects ext while we are waiting for celestian to accept the code. He did respond that he is busy with work stuff, so it might be awhile. Either way, you code worked. So, if you have the most recent version of this ext, the fix for range & flanking, and the advance effects fix then that should cover most issues. I run like 99 exts so I have a good test bed ;P
Just trying out the extension and I really like the idea! One thing though, it seems like you use the onAttack function? My Nat20 extension does too, but if you don't call the normal onAttack action it bypasses all the Nat20 code. I could try a loadorder change to see if that helps, but your extension looks like it loads in the vault so I can't debug it.
Thanks!
Glad you like it and thanks for letting me know about this issue.
Because of the "hit margin tracking" feature, I need access to some numbers only accessible from inside that function.
Check the first post. All of my code is freely available on GitHub for collaboration, modification, and debugging. If you look at my onAttack function, I have separated out some "compatibility blocks" that make adding support to other extensions easy. Just change this line in your onAttack function:
to this:Code:Comm.deliverChatMessage(rMessage);
If your extension calls the previous onAttack (doesn't need to overwrite it), you can just load after mine (although I don't have a loadorder defined right now). Let me know if a loadorder is necessary to help improve compatibility with your extension.Code:-- bmos adding hit margin tracking
-- for compatibility with ammunition tracker, add this here in your onAttack function
if AmmunitionManager then
local nHitMargin = AmmunitionManager.calculateMargin(nDefenseVal, rAction.nTotal)
if nHitMargin then table.insert(rAction.aMessages, "[BY " .. nHitMargin .. "+]") end
end
-- end bmos adding hit margin tracking
Comm.deliverChatMessage(rMessage);
-- bmos adding automatic ammunition ticker and chat messaging
-- for compatibility with ammunition tracker, add this here in your onAttack function
if AmmunitionManager and ActorManager.isPC(rSource) then AmmunitionManager.ammoTracker(rSource, rRoll.sDesc, rAction.sResult, true) end
-- end bmos adding automatic ammunition ticker and chat messaging
Thanks bmos...I'll look into that. I think the issue for me right off the bat is that I don't have a "copy" of the onAttack function in my extension, I simply set a local array tracker for a nat20, call the original onAttack, and then generate the message for display. Because of that, I don't have visibility to the rAction struct, and pasting your code into mine wouldn't work.
In my Nat20 extension, I replaced:
... with ...Code:ActionAttack.Nat20_Original_onAttack(rSource, rTarget, rRoll)
but it looks like the Nat20 onAttack isn't even executed if your extension loads after mine, so I also changed the loadorder of Nat20 to "51" and that seems to have fixed things.Code:
if AmmunitionManager then
AmmunitionManager.onAttack_5e(rSource, rTarget, rRoll)
else
ActionAttack.Nat20_Original_onAttack(rSource, rTarget, rRoll)
end
I'll do some more testing and update Nat20 if everything goes well.
Thanks!
Ooh...also, since I saw some "suggestions" ... :)
How hard would it be to automatically equip and unequip ammo when loaded or unloaded? :) It would play well with AutomaticEffects that way.
Thanks for the cool extension!