Yes looks good
Added a few comments, hope it's understandable.
Maybe that helps you too:
Lua Code:
function FarmersToolkit.BountyCheck()
local CurBounty=GetFullBountyPayoffAmount(); --lua does not need the ; at line ends (allthough they raise no error)
local identifier="FarmersToolkit-BountyCheck";
-- local reference variable to speed up things a bit. Can help if you access the same variables more than once.
-- Else it would each time completely search your table FarmersToolkit for the variable BountyValue again!
-- If you put a local reference it directly points there and can read and write that table's variable too
local FTbountyValue = FarmersToolkit.BountyValue
-- In case this is the first time we've been called this session...
FTbountyValue = FTbountyValue or 0 --checks if it's ot nil and uses itssself then, or else defaults it to 0
if ( CurBounty == 0 ) then -- We have no bounty, whew!
if ( FTbountyValue > 0 ) then -- We may have a outstanding timer event tho
EVENT_MANAGER:UnregisterForUpdate(identifier)
end
FTbountyValue = 0; -- Zero out internal counter / tracker
FarmersToolkit.UpdateActivities(); -- Update the screen
dft_debug("BountyCheck indicates you are safe as of " .. os.time() .. "!"); -- Debug
dft("Bounty appears cleared, cancelling timers - happy hunting."); -- Announce
else
if ( ( FTbountyValue == 0 ) and ( CurBounty > 0 ) ) then -- This is the onset of a bounty
dft("Bounty detected (" .. CurBounty .. "), updates posted to screen until cleared.");
end
FarmersToolkit.UpdateActivities();
FTbountyValue=CurBounty;
dft_debug("BountyCheck = " .. CurBounty .. ", timer set for 15 seconds as of " .. os.time());
EVENT_MANAGER:UnregisterForUpdate(identifier) -- Just in case
EVENT_MANAGER:RegisterForUpdate(identifier, 15000, FarmersToolkit.BountyCheck)
end
end -- FarmersToolkit.BountyCheck