EMonitor

5 - Run OnGroup only if enabled

Since the OnGroupUpdated function gets called a due to a lot of updates, would it be worth disabling most of that code when the mod is DISabled?  I use EMonitor with a macro while disabled.  For those like me, it would save a lot of overhead if the code only ran when I pressed the button.  Constantly building, sorting and range checking the list is a fair bit of overhead, that will only increase in the future when scenario and warparty support are added.  I know the list needs to be built so the TargetLowest would have to call a standard update before doing it's normal job.  

Highlights are:
* OnGroupUpdated now does nothing if mod is not enabled.
* Moved your normal OnGroupUpdated code into another function called OnGroupUpdatedProcess (name it whatever you like)
* Snipped out the TargetLowest call from your update code and put it into the OnGroupUpdated conditional
* Added a conditional to the TargetLowest function to call the update process if the mod is disabled

function EMonitor.OnGroupUpdated()
    if (EMonitorSettings.Enabled then
        EMonitor.OnGroupUpdatedProcess()
                EMonitor.TargetLowest()
    end
end

function Emonitor.OnGroupUdatedProcess()

    -- Start off by clearing list and setting as its first element our health
    EMonitor.ClearSortedList()
    EMonitor.InsertToHealthList( GameData.Player.name,((GameData.Player.hitPoints.current * 100)/ GameData.Player.hitPoints.maximum
    
    GroupData = GetGroupData()
    -- Find lowest health percentage and store it
    playernr = GetNumGroupmates()
    for i = 1, playernr do
        -- make sure group member is valid
        -- pprint("EMonitor.IsMemberValid=",EMonitor.IsMemberValid(i))
        if (EMonitor.IsMemberValid(i) == true) then
            --pprint("valid GroupMember ",i," ",GroupData[i].healthPercent,GroupData[i].name)
            
            -- save it if we should
            if (EMonitor.isPlayerOnIgnoreList(GroupData[i].name) == false) then
                    EMonitor.InsertToHealthList(GroupData[i].name,GroupData[i].healthPercent)
            end
        end
    end
-- Snipped out the TargetLowest call since it's now above in OnGroupUpdated()    

end

function EMonitor.TargetLowest()
    idx = 0
    local success, valid
-- If mod is disabled call the process to build, sort and range check the list
    if not (EMonitorSettings.Enabled then
        EMonitor.OnGroupUpdatedProcess()
    end

    repeat
        idx = idx + 1
        -- Target our player
        success = TargetPlayer(EMonitor.SortedName[idx])
        if (success == false) then DEBUG( L"EMonitor.OnGroupUpdated():Error, Could not target the player with the lowest health, who was")
        end
        -- now check validity, should always at least find one(ourselves)
        valid, success = IsTargetValid(EMonitorSettings.friendlyAbilityCheck
        
        -- break if we have found a valid target or no more left(so should always at least target the highest health person)
    until ((success and valid) or (idx == EMonitor.SortedSize )
        
    if ( (success == false) or (valid == false) ) then
        DEBUG( L"EMonitor.TargetLowest():Error, Never found a successful and valid target in our SortedHealth list")
    end
end

User When Change
Djanee Fri, 19 Sep 2008 05:05:34 Create

You must login to post a comment. Don't have an account? Register to get one!

  • 1 comment
  • Avatar of khalid_war khalid_war Fri, 19 Sep 2008 06:21:05
      All good ideas. I finally am back from Germany so have put a big change in and already implemented some that you talked about.
    

    For one, as you said, when not enabled it now doesnt check anything at all. On being called with Target_Lowest it will then find the lowest and targetthem.

    When enabled it also does its checks based on a time interval rather than on status updates so it does the work MUCH less frequently in scenarios and is way lighter on the amchine now. I should have a new version up by the end of the night, just sitting in a scenario queue atm :(

  • 1 comment

Facts

Reported on
19 Sep 2008
Status
New - Issue has not had initial review yet.
Type
Enhancement - A change which is intended to better the project in some way
Priority
Medium - Normal priority.

Reported by

Possible assignees