So I started working on a new GMail. And I started thinking, I should have some generic functions for:
Take an item from a mail
Take money from a mail
Take a letter from a mail
So I looked at the old Expressmail (Tekkub has a newer nonace version thats about ten lines) and actually cobbled together a mail mixin with his functions (with his consent of course).
function Mailmix:TakeItem(index, confirmCOD)
local _, _, _, _, _, COD, _, hasItem = GetInboxHeaderInfo(index)
if not hasItem or (COD > 0 and not confirmCOD) then return end
Now, this is fine and dandy and does as intended. But now here comes the hard part. Atomic version of these functions. For reference, I checked how AH_MailCollect does this and it uses a large scoped variable which in this instance a hooked BAG_UPDATE would clear.
The AH_MailCollect method works but isn't friendly for making small atomic functions.
Alright, haven't had a chance to test this yet so consider it pseudocode. But these are the two functions I have now for my mail-lib for getting money from a mail. The first is non-atomic while the other attempts to be atomic. Any feedback is appreciated.
local _, _, _, _, money = GetInboxHeaderInfo(index)
if money == 0 then return end
local stopcode = 2
self.atom = 0
for i = 1, stopcode do
if self.atom = 1 then
if not running then
self:RegisterEvent("PLAYER_MONEY", function() self.atom = 1 end )
running = 1
stopcode = stopcode + 1