All pastes #95485 Raw Edit

Unnamed

public text v1 · immutable
#95485 ·published 2006-07-22 01:56 UTC
rendered paste body
cthun_warnings = { 
  {"tentacles", 5, 45},
  {"dark glare", 5, 40}
}

cthun_Warn = {
  warn = function(nxt,i)
    local msg = "****"..cthun_warnings[i][2].."seconds until "..cthun_warnings[i][1].."****"
    CT_RA_AddMessage("MS "..msg);
    Chat.console(msg)
    Chat.raid(msg)
    --Chronos.scheduleByName("cthun"..i, cthun_warnings[i][3]-cthun_warnings[i][2], cthun_Warn.warn, "", i)
    Chronos.scheduleByName("cthun"..i, cthun_warnings[i][3], cthun_Warn.warn, "", i)
  end
}

cthun_startOnCombat = "OFF"


-- =============================================================================

Schedule = {
  
  print = function()
    Chat.console(cthun_warnings[1][1])
    Chat.console(cthun_warnings[1][2])
    Chat.console(cthun_warnings[1][3])
    Chat.console(cthun_warnings[2][1])
    Chat.console(cthun_warnings[2][2])
    Chat.console(cthun_warnings[2][3])
  end,

  start = function()
    local t = cthun_warnings
    for i=1,table.getn(t) do
      local e = t[i]
      if(type(e)=="table") then
        local text = e[1]
        local delay = e[2]
        local cycle = e[3]
        local f = e[4]
        local index = i
        Chronos.scheduleByName("cthun"..index, cycle-delay, cthun_Warn.warn, "", index)
        Chat.console("Chronos.scheduleByName(cthun"..index..", "..cycle-delay..", "..type(cthun_Warn.warn)..", "..index..")")
      else
        Chat.console("i is "..i.." but not a table")
      end
    end
  end,
  
  stop = function()
    t = cthun_warnings
    for i=1,table.getn(t)+1 do
      Chat.console("stopping id: ".."cthun"..i-1)
      Chronos.unscheduleByName("cthun"..i-1)
    end
  end

}


-- =============================================================================

UI = {


  cthun_reset1 = function()
    Chronos.scheduleByName("cthun1", cthun_warnings[1][3]-cthun_warnings[1][2], cthun_Warn.warn, "", 1)
  end,

  cthun_reset2 = function()
    Chronos.scheduleByName("cthun2", cthun_warnings[2][3]-cthun_warnings[2][2], cthun_Warn.warn,  "", 2)
  end,
cthun_reset3 = function()
    Chronos.scheduleByName("cthun2", cthun_warnings[3][3]-cthun_warnings[3][2], cthun_Warn.warn,  "", 3)
  end,
cthun_reset4 = function()
    Chronos.scheduleByName("cthun2", cthun_warnings[4][3]-cthun_warnings[4][2], cthun_Warn.warn,  "", 4)
  end,
cthun_reset5 = function()
    Chronos.scheduleByName("cthun2", cthun_warnings[5][3]-cthun_warnings[5][2], cthun_Warn.warn,  "", 5)
  end,


  -- Toggle visibility of the frame called "cthun#"
  -- where # is a number passed as an argument to this function.
  cthun_Toggle = function(num)
     local frame = getglobal("cthunFrame" .. num)
     if (frame) then
       if (frame:IsVisible()) then
         frame:Hide();
       else
         cthunFrame1_InputBox00:SetText(cthun_warnings[1][1]) 
         cthunFrame1_InputBox01:SetText(cthun_warnings[1][2])
         cthunFrame1_InputBox02:SetText(cthun_warnings[1][3])
         cthunFrame1_InputBox10:SetText(cthun_warnings[2][1]) 
         cthunFrame1_InputBox11:SetText(cthun_warnings[2][2])
         cthunFrame1_InputBox12:SetText(cthun_warnings[2][3])
         cthunFrame1_InputBox10:SetText(cthun_warnings[3][1]) 
         cthunFrame1_InputBox11:SetText(cthun_warnings[3][2])
         cthunFrame1_InputBox12:SetText(cthun_warnings[3][3])
         cthunFrame1_InputBox10:SetText(cthun_warnings[4][1]) 
         cthunFrame1_InputBox11:SetText(cthun_warnings[4][2])
         cthunFrame1_InputBox12:SetText(cthun_warnings[4][3])
         cthunFrame1_InputBox10:SetText(cthun_warnings[5][1]) 
         cthunFrame1_InputBox11:SetText(cthun_warnings[5][2])
         cthunFrame1_InputBox12:SetText(cthun_warnings[5][3])
         frame:Show();
       end
     end
  end,

  cthun_ToggleOnCombat = function (arg1)
     if (cthun_startOnCombat == "ON") then
       cthun_startOnCombat = "OFF"
       Chat.console("start on combat disabled")
       cthun_Unregister()
     elseif (cthun_startOnCombat == "OFF") then 
       cthun_startOnCombat = "ON"
       Chat.console("start on combat enabled")
       cthun_Register()
     end
     --id = this:GetID()
     --Chat.console("OnCombat" .. this:GetName() .. ", ID:" .. id .. ", Button:" ..arg1)
  end,

  cthun_ToggleOnCombat_OnShow = function (arg1)
  	if (cthun_startOnCombat == "ON") then
  	  cthunFrame1_OnCombatCheckButton:SetChecked(1);
  	else
  		cthunFrame1_OnCombatCheckButton:SetChecked(0);
  	end
  end,


  -- info from pressing button number 'arg1'
  cthun_OnClick = function (arg1)
     id = this:GetID()
     Chat.console("cthun: OnClick:" .. this:GetName() .. ", ID:" .. id .. ", Button:" ..arg1)
  end,

  cthun_save = function (arg1)
     id = this:GetID()
     --Chat.console("cthun_start: " .. this:GetName() .. " ,ID: " .. id .. " ,Button:" ..arg1)
     if (cthunFrame1_InputBox00:GetText()) then
       cthun_warnings[1][1]=cthunFrame1_InputBox00:GetText()
     end
     if (cthunFrame1_InputBox01:GetText()) then
       cthun_warnings[1][2]=cthunFrame1_InputBox01:GetText()
     end
     if (cthunFrame1_InputBox02:GetText()) then
       cthun_warnings[1][3]=cthunFrame1_InputBox02:GetText()
     end
     if (cthunFrame1_InputBox10:GetText()) then
       cthun_warnings[2][1]=cthunFrame1_InputBox10:GetText()
     end
     if (cthunFrame1_InputBox11:GetText()) then
       cthun_warnings[2][2]=cthunFrame1_InputBox11:GetText()
     end
     if (cthunFrame1_InputBox12:GetText()) then
       cthun_warnings[2][3]=cthunFrame1_InputBox12:GetText()
     end
     if (cthunFrame1_InputBox10:GetText()) then
       cthun_warnings[3][1]=cthunFrame1_InputBox10:GetText()
     end
     if (cthunFrame1_InputBox11:GetText()) then
       cthun_warnings[3][2]=cthunFrame1_InputBox11:GetText()
     end
     if (cthunFrame1_InputBox12:GetText()) then
       cthun_warnings[3][3]=cthunFrame1_InputBox12:GetText()
     end
     if (cthunFrame1_InputBox10:GetText()) then
       cthun_warnings[4][1]=cthunFrame1_InputBox10:GetText()
     end
     if (cthunFrame1_InputBox11:GetText()) then
       cthun_warnings[4][2]=cthunFrame1_InputBox11:GetText()
     end
     if (cthunFrame1_InputBox12:GetText()) then
       cthun_warnings[4][3]=cthunFrame1_InputBox12:GetText()
     end
     if (cthunFrame1_InputBox10:GetText()) then
       cthun_warnings[5][1]=cthunFrame1_InputBox10:GetText()
     end
     if (cthunFrame1_InputBox11:GetText()) then
       cthun_warnings[5][2]=cthunFrame1_InputBox11:GetText()
     end
     if (cthunFrame1_InputBox12:GetText()) then
       cthun_warnings[5][3]=cthunFrame1_InputBox12:GetText()
     end

     if (cthunFrame1_OnCombatCheckButton:GetChecked()) then
       if (cthunFrame1_OnCombatCheckButton:GetChecked()==1) then
         cthun_startOnCombat = "ON"
         Chat.console("saved autostart on combat On")
       else
         cthun_startOnCombat = "OFF"
         Chat.console("saved autostart on combat Off")
       end
     end
     Chat.console("saved text/delay/cycle: "..cthun_warnings[1][1].."/"..cthun_warnings[1][2].."/"..cthun_warnings[1][3])
     Chat.console("saved text/delay/cycle: "..cthun_warnings[2][1].."/"..cthun_warnings[2][2].."/"..cthun_warnings[2][3])
     Chat.console("saved text/delay/cycle: "..cthun_warnings[3][1].."/"..cthun_warnings[3][2].."/"..cthun_warnings[3][3])
     Chat.console("saved text/delay/cycle: "..cthun_warnings[4][1].."/"..cthun_warnings[4][2].."/"..cthun_warnings[4][3])
     Chat.console("saved text/delay/cycle: "..cthun_warnings[5][1].."/"..cthun_warnings[5][2].."/"..cthun_warnings[5][3])
  end

}


-- =============================================================================
Chat = {

  -- displays msg in console
  console = function(msg)
    if (msg==nil) then msg = "nil" end
    if(DEFAULT_CHAT_FRAME) then
      DEFAULT_CHAT_FRAME:AddMessage(Time.cthun_getTimeHMS()..": "..msg, 0.0, 1.0, 0.0, 1.0);
    end
  end,

  -- displays msg in error frame
  error = function(msg)
    if(UIErrorsFrame) then
      UIErrorsFrame:AddMessage(text, 1.0, 1.0, 0, 1, 10)
    end
  end,

  -- displays msg in raid channel
  raid = function(msg)
    SendChatMessage(msg, "RAID");
  end,

  -- displays msg in addon frame
  frame = function(msg)
    empsFrame:AddMessage(msg, 1, 1, 1, 1, 3);
  end

}


-- =============================================================================

Time = {

  -- return the current month+day+hour+sec in seconds
  cthun_getTime = function ()
    local strtime = date("%m%d%H%M%S")
    local time = tonumber(string.sub(strtime,1,2)) * 2592000 -- month
    time = time + tonumber(string.sub(strtime,3,4)) * 86400 -- day
    time = time + tonumber(string.sub(strtime,5,6)) * 3600 -- hour
    time = time + tonumber(string.sub(strtime,7,8)) * 60 -- minute
    time = time + tonumber(string.sub(strtime,9,10)) --second
    return time;
  end, 

  -- return the current month+day+hour+sec in seconds
  cthun_getTimeHMS = function ()
    local strtime = date("%H:%M:%S")
    return string.sub(strtime,1,8);
  end  

}


-- =============================================================================

function cthun_OnLoad()
  DEFAULT_CHAT_FRAME:AddMessage("CTHUN LOADED", 0.0, 1.0, 0.0, 1.0);
  SLASH_cthun1 = "/cthun";
  SlashCmdList["cthun"] = function(msg)
    cthun_SlashCommandHandler(msg);
  end
  if (cthun_startOnCombat == "ON") then
    Chat.console("Start in combat is ON")
    cthun_Register()
  elseif (cthun_startOnCombat == "OFF") then
    Chat.console("Start in combat is OFF")
    cthun_Unregister()
  end
end


-- "/c config" toggle the visibility of the frame
function cthun_SlashCommandHandler(msg)
  if (msg == "") then
   UI.cthun_Toggle(1)
  elseif (msg == "print") then
    Schedule.print()
  elseif (msg == "start") then
    Schedule.start()
  elseif (msg == "stop") then
    Schedule.stop()
  elseif (msg == "time") then
    Chat.console(Time.cthun_getTime())
  end
end


-- =============================================================================

function cthun_OnEvent(event)
  if (event == "PLAYER_REGEN_DISABLED") then
    Schedule.start()
  end 
  --if (event == "PLAYER_REGEN_ENABLED") then
  --  Schedule.stop()
  --end 
end

function cthun_Register()
	cthunFrame:RegisterEvent("PLAYER_REGEN_ENABLED");
	cthunFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
end

function cthun_Unregister()
	cthunFrame:UnregisterEvent("PLAYER_REGEN_ENABLED");
	cthunFrame:UnregisterEvent("PLAYER_REGEN_DISABLED")
end