v 0. Pasted by (͡๏̯͡๏) as lua at 2012-03-27 11:11:57 MSK and set expiration to never.

Paste will expire never.

  1. SBM_Actions = {}
  2.  
  3. function SBM_SaveSkills()
  4.  
  5.     -- lookup skills
  6.     local skills = {}
  7.     local function lookupSkills(page)
  8.         local si = 1
  9.         repeat
  10.             local name,i1,icon,passive,rank,i2,cost,skillable,avail = GetSkillDetail(page,si)
  11.             if not name then break end
  12.             local link = GetSkillHyperLink(page,si)
  13.             local sid = link:match("^|H.-:(%x+)") or ''
  14.             if not skills[icon] then skills[icon] = {} end
  15.             local skill = { ['name'] = name, ['icon'] = icon, ['id'] = tonumber(sid,10), ['page'] = page, ['index'] = si }
  16.             table.insert(skills[icon], skill)
  17.             si = si + 1
  18.         until name == nil
  19.     end
  20.    
  21.     lookupSkills(3) -- subclass
  22.     lookupSkills(4) -- elite skills
  23.    
  24.     local actions, acount = {},0
  25.     for ai=1,80 do
  26.         local icon,name,count,locked,wore,cont = GetActionInfo(ai)
  27.         if name == '' and wore ~= nil and skills[icon] ~= nil then
  28.             -- possible action, check ID
  29.             local skill = skills[icon][1]
  30.             local id = nil
  31.             PickupAction(ai);
  32.             if CursorItemType() == 'action' then
  33.                 id = GetCursorItemInfo() - 1
  34.             end
  35.             PickupAction(ai)
  36.             -- printf("%d:%s possible skill of %d:%d (%d) <%s>", ai, tostring(id), skill.page, skill.index, skill.id, skill.name)
  37.             if skill.id == id then
  38.                 actions[ai] = skill
  39.                 acount = acount+1
  40.             else
  41.                 local saved = false
  42.                 -- printf("matched %d skills for same icon", #skills[icon])
  43.                 for i,ski in pairs(skills[icon]) do
  44.                     if ski.id == id then
  45.                         actions[ai] = ski
  46.                         acount = acount+1
  47.                         saved = true
  48.                     end
  49.                 end
  50.                 if not saved then
  51.                     print("not saved, missing id?")
  52.                     printf("skill: %d %d:%d <%s> <%s>", skill.id, skill.page, skill.index, skill.name, skill.icon)
  53.                     printf("action: %d <%s> <%s>", id, name, icon)
  54.                 end
  55.             end
  56.         end
  57.     end
  58.     return actions, acount
  59. end
  60.  
  61.  
  62.  
  63. function SBM_SaveActions()
  64.     local mc,sc = UnitClassToken("player")
  65.     if not sc or sc == "" then
  66.         print("can't save actions without subclass.")
  67.         return
  68.     end
  69.     SBM_Mute()
  70.     local actions, acount = SBM_SaveSkills()
  71.     local cid = mc:upper() .. sc:lower()
  72.     printf("saved %d skills of %s / %s", acount, UnitClass("player"))
  73.    
  74.     SBM_Actions[cid] = actions
  75. end
  76.  
  77. function SBM_RestoreActions()
  78.     local mc,sc = UnitClassToken("player")
  79.     if not sc or sc == "" then
  80.         print("can't restore actions without subclass.")
  81.         return
  82.     end
  83.     local cid = mc:upper() .. sc:lower()
  84.     local actions = SBM_Actions[cid]
  85.     if not actions then
  86.         print("no saved actions for ",cid)
  87.         return
  88.     end
  89.    
  90.     local acount = 0
  91.     for ai,action in pairs(actions) do
  92.         if CursorItemType() == 'action' then DeleteCursorItem() end
  93.         local icon,name,count,locked,wore,cont = GetActionInfo(ai)
  94.         if icon ~= action.icon then
  95.             printf("restoring <%s> at action #%d", action.name,ai)
  96.             DragSkillButton(action.page, action.index)
  97.             PickupAction(ai)
  98.             DeleteCursorItem()
  99.             acount = acount+1
  100.         end
  101.     end
  102.     if CursorItemType() == 'action' then DeleteCursorItem() end
  103.     printf("restored %d actions",acount)
  104.     TF:RemoveTimedFunction(SBM_RestoreActions)
  105. end
  106.  
  107. function SBM_RestoreAudio(args)
  108.     InterfaceSFXVolumeSlider_SetValue(args.sfx or 100)
  109.     TF:RemoveTimedFunction(SBM_RestoreAudio)
  110. end
  111.  
  112. function SBM_Mute()
  113.     local sfx = InterfaceSFXVolumeSlider_GetValue()
  114.     InterfaceSFXVolumeSlider_SetValue(0)
  115.     local args = { ['sfx'] = sfx }
  116.     TF:RegisterTimedFunction(SBM_RestoreAudio, 2, 1, args)
  117. end
  118.  
  119. sbmRegisterEvents("EXCHANGECLASS_SHOW", function()
  120.     if not IsShiftKeyDown() and not IsAltKeyDown() then
  121.         SBM_SaveActions()
  122.     end
  123. end)
  124.  
  125. sbmRegisterEvents("EXCHANGECLASS_SUCCESS", function()
  126.     -- SBM_RestoreActions()
  127.     local args = {}
  128.     TF:RegisterTimedFunction(SBM_RestoreActions, 3, 1, args)
  129. end)
  130.  
  131. table.insert(sbmLoadEvents, function()
  132.     SaveVariablesPerCharacter("SBM_Actions")
  133. end)