Cost in AP to transfer items

Since there's not an existing cost for transferring items between characters, there's no existing code that calls for AP reduction in that case - so a quick hex patch isn't really possible.

If you're willing to use FTSE (latest version only - 0.56a), I think I have a script that will do that:

Code:
function Vtable510(ent, commandstruct)
  if commandstruct.type == 19 then
    local amt = math.floor(commandstruct.param / 8)
    logger:log(ent:GetName() .. " is exchanging item " .. commandstruct.entity2:GetName() .. " (x" .. tostring(amt) .. ") to " .. commandstruct.entity1:GetName())
    if ent:GetAP() < 3 then
      world:CombatLog(COMBATLOG_FEW, "Not enough AP to exchange.")
      return
    end
    ent:AdjustAP(-3)
  end
  ent:CallOrigVtable(510, commandstruct)
end

function OnStart()
  hookexecutor:InstallVtableHook("Actor",510,Vtable510)
end

Change the "3" and "-3" values in the GetAP and AdjustAP lines to set the cost that you want. Might also want to remove the "logger:log" line once you confirm it is working correctly (this will show up in ftse.log in case you need to check if it's working, or if there's a problem).

---

Tech details: Vtable 510 in Entity is a "command handler" - it appears to take events from either UI, network, or maybe even the AI code, and pass them on to the corresponding behavior in each entity's code. Event 19 looks like the one for exchange of inventory items. So, we trap Actor vtable 510 (to be notified on events), look for event type 19, then add our logic to check for sufficient AP and reduce by the desired amount. We then call the original Vtable 510 code to actually perform the item transfer.

Note that we deduct AP even if the exchange fails. This won't happen if the characters are too far apart - that's checked even before event 19 is triggered. But if the receiving character is too full, or otherwise can't carry the item for some reason, then the AP will still be lost.
 
Back
Top