API question: What does stackcount reference?

Good evening all,
I am trying to edit an old weakaura string so that it works with shadow priest class mechanic changes. The weakaura itself plays soundfiles with a random chance after conditions are met. The out-dated conditional check looked in the combat log for successful spell casts and then applied the random chance based off of voidform’s stack count. I am trying to edit the string to instead check my insanity resource. The original string can be found below the dashed line.

What I have done so far is to replace local name, _, count = UnitAura(“player”, i, “HELPFUL”) with local count = UnitPower(“player”,13). I believe this redirects the string from checking for ‘voidform’ to checking my insanity resource. However, I do not know what to do with the four instances of ‘stackcount’ in the string. Does stackcount refer specifically to the count that used to accompany the old voidform? I was hoping that it would automatically dredge up my total insanity instead.


function(self, targ, …)
local type = select(1, …)
local source = select(4, …)
local name = UnitName(“player”)
if(source == name) then
if(type == “SPELL_CAST_SUCCESS” or type == “SPELL_ENERGIZE”) then
local stackCount = -1
for i = 1, 40 do
local name, _, count = UnitAura(“player”, i, “HELPFUL”)
if(name == “voidform”) then
stackCount = count
break
end
end
local chance = 1;
local max = 80;
if(stackCount > 0) then
local x = stackCount / 100;
x = (x^3) * max;
chance = 3 + x;
end