EMonitor

2 - rangechecking with sorted list

-- Based on Proof of concept for an Emergency Monitor mod
-- Originally written by Khalid on the warhammer alliance forums and WoW Temporary Insanity on Kilrogg
-- functionality rewrite by Oyzyu

EMonitor = {}

GroupData = GetGroupData()
NameTable = {}
HealthTable = {}
elements = 1
HIDnr = 1898 --default to shaman. personal pref

function EMonitor.Initialize()
    
    RegisterEventHandler( SystemData.Events.GROUP_UPDATED "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.GROUP_STATUS_UPDATED "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.GROUP_EFFECTS_UPDATED "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.GROUP_PLAYER_ADDED "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.SCENARIO_GROUP_JOIN "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.SCENARIO_GROUP_LEAVE "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.PLAYER_CUR_HIT_POINTS_UPDATED "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.PLAYER_EFFECTS_UPDATED "EMonitor.OnGroupUpdated";)
    RegisterEventHandler( SystemData.Events.PLAYER_DEATH_CLEARED "EMonitor.OnGroupUpdated";)
    --runepriest 1587 3
    -- DoK 9548 23 ???
    -- archmage 9236 20
    --shaman 1898 7
    --WP 8238 12
    -- zealot 8569 15
    if (GameData.Player.career.line == 7) then HIDnr = 1898 end
    if (GameData.Player.career.line == 3) then HIDnr = 1587 end
    if (GameData.Player.career.line == 23) then HIDnr = 9548 end
    if (GameData.Player.career.line == 20) then HIDnr = 9236 end
    if (GameData.Player.career.line == 12) then HIDnr = 8238 end
    if (GameData.Player.career.line == 15) then HIDnr = 8569 end
    
end

-- Checks if the group member is valid, gotten from CleanUnitFrames by Aiiane, email=aiiane@aiiane.net
function EMonitor.IsMemberValid(index)
    return ( GroupData ~= nil and
             GroupData[index] ~= nil and
             GroupData[index].name ~= nil and
             GroupData[index].name ~= L"" )
end

function EMonitor.OnGroupUpdated()

    elements = 0
    GroupData = GetGroupData()
    playernr = GetNumGroupmates()
    -- sort players by health % and store the list
    
    --make initial list
    for i = 1, playernr do
        if (EMonitor.IsMemberValid(i) == true) then
            NameTable[i]=GroupData[i].name
            HealthTable[i]=GroupData[i].healthPercent
            elements = elements + 1
        end
    end
    
    --simple sort lowest health to highest
    local counter=1
    while (counter < elements) do
        if ( HealthTable[counter+1] < HealthTable[counter] ) then
            local temph
            local tempn
            temph = HealthTable[counter]
            tempn = NameTable[counter]
            HealthTable[counter] = HealthTable[counter+1]
            NameTable[counter] = NameTable[counter+1]
            HealthTable[counter+1] = temph
            NameTable[counter+1] = tempn
            counter=1
        else
            counter=counter+1
        end
    end
    
end

function EMonitor.settarget()
    
    local validtarget = false
    for i = 1,elements do
        if (HealthTable[i] > 0) then --dead people ignored
            TargetPlayer(NameTable[i])
            if (IsTargetValid(HIDnr)) then --default heal abilty
                validtarget = true
                break --we have found the lowest valid member stop searching
            end
        end    
    end
    if (validtarget == false) then --normally not necessary but catches first use errors and potential exceptions
        TargetPlayer(GameData.Player.name)
    end
    
end

User When Change
oyzyu Sat, 13 Sep 2008 11:51:19 Create

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

Facts

Reported on
13 Sep 2008
Status
New - Issue has not had initial review yet.
Type
Patch - Source code patch for review
Priority
Medium - Normal priority.

Reported by

Possible assignees