All pastes #72082 Raw Edit

Kaelten

public lua v1 · immutable
#72082 ·published 2006-06-26 14:48 UTC
rendered paste body
function KC_Common:Explode(string, sep)	if (not string) then return	end	if (type(string) ~= "string") then error("Bad String was a " .. type(string) .. "value: " .. (string or "nil"), 2)	end	local a, b = self:Split(string, sep)	if (not b or b == "") then return a; end	if (not strfind(b, sep)) then return a, b; end	return a, self:Explode(b, sep)endfunction KC_Common:Split(string, sep)	if (not string or type(string) ~= "string") then error("Bad String was a " .. type(string) .. "value: " .. (string or "nil"), 2)	end	local x, y = (strfind(string , sep) or 0), (strlen(sep) or 1)	return (tonumber(strsub(string, 1, x-1)) or strsub(string, 1, x-1)), (tonumber(strsub(string, x+y)) or strsub(string, x+y))endfunction KC_Common:CharCount(str, char)	local count = 0 	for i in string.gfind(str, char) do		count = count + 1	end	return countendfunction KC_Common:StrMixed(string)	string = strlower(string)	return(strupper(strsub(string, 1,1)) .. strsub(string, 2))endfunction KC_Common:CashTextLetters(cash)	cash = floor(cash)    local g,s,c = floor(cash/(100*100)),mod(floor(cash/100),100),mod(floor(cash),100)    local str=""    if(g>0) then		str = format("%s%s%s", locals.money.gold.color, g, locals.money.gold.letter)    end    if(s>0) then		if (str == "") then			str = format("%s%s%s", locals.money.silver.color, s, locals.money.silver.letter)		else			str = format("%s %s%s%s", str, locals.money.silver.color, s, locals.money.silver.letter)		end    end    if(c>0) then		if (str == "") then			str = format("%s%s%s", locals.money.copper.color, c, locals.money.copper.letter)		else			str = format("%s %s%s%s", str, locals.money.copper.color, c, locals.money.copper.letter)		end    end    return strendfunction KC_Common:Median(values)	local num = getn(values)	if (not values or num == 0) then return end	sort(values)	return (math.mod(num,2) == 1) and values[num/2 +.5] or self:Round((values[num/2] + values[num/2 +1]) / 2,3)endfunction KC_Common:WeightedAvg(new, old, nWeight, oWeight)	if (old == 0) then return new end	if (new == 0) then return old end	return self:Round(new * nWeight + old * oWeight,3)endfunction KC_Common:Round(x, y)	return floor(x * (10^(y or 0))) / (10^y) endfunction KC_Common:Avg(values)	local total = 0	for i, v in ipairs(values) do total = total + v end	return (total > 0) and self:Round(total / getn(values),3) or nil;endfunction KC_Common:ToHex(num)	num = floor(num)	return locals.hex[floor(num/16)+1]..locals.hex[mod(num,16)+1]endfunction KC_Common:GetHexCode(r, g, b, dec)	r = dec and r * 255 or r	g = dec and g * 255 or g	b = dec and b * 255 or b	return format("|cff%s%s%s", self:ToHex(r), self:ToHex(g), self:ToHex(b))endfunction KC_Common:BellCurve(values)	if (not values or getn(values) == 0) then return; end	if (getn(values) == 1) then return values[1]; end	local avg = self:Avg(values)		local sd = self:StdDev(values, avg);	sort(values);		local lLimit = avg - (sd * 1.5);	local hLimit = avg + (sd * 1.5);		local lPass, hPass	while (not lPass or not hPass) do		lPass = (tonumber(values[1]) >= lLimit) and true or tremove(values,1)		hPass = (tonumber(values[getn(values)]) <= hLimit) and true or tremove(values)	end	local median = self:Median(values)	return median and floor(median) or nil;endfunction KC_Common:StdDev(values, avg)	local num = 0	for i,v in pairs(values) do		num = num + ((v - avg)^2)		end	num = num / getn(values);	return floor(math.sqrt(num));end-- some constants that are used by some of the other values	locals.money = {}	locals.money.gold = {}	locals.money.gold.color		=  "|cffffd700"	locals.money.gold.letter	= "g"	locals.money.gold.word		= "gold"		locals.money.silver = {}	locals.money.silver.color	=  "|cffc7c7cf"	locals.money.silver.letter	= "s"	locals.money.silver.word	= "silver"		locals.money.copper= {}	locals.money.copper.color	=  "|cffeda55f"	locals.money.copper.letter	= "c"	locals.money.copper.word	= "copper"	locals.of = " of "	locals.hex = {0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f"}