/trunk/EMLib
## Interface: 30200 |
## Interface: 30300 |
## Title: EMLib |
## Notes: EV's Mod Library, contains commonly used functions across his mods. |
## Author: EVmaker |
--[[ |
EV's Mod Library by EVmaker, v0.09: |
EV's Mod Library by EVmaker, v0.13: |
After getting tired of copying often used functions (such as printing to chat) over and over after each mod I work on, |
I decided to move all the most commonly used functions into a general library which I can have as a dependency for |
each of my mods and simply have them all use it instead of duplicating the code for every mod. |
Support for Levelator by SJones321 |
]]-- |
-- Declares the locals |
local EML_Version = "0.09"; |
local EML_Version = "0.13"; |
local debugMode = false; |
local EML_supportedMods = { |
["Looter"] = true, |
["QuickThreatDisplay"] = true, |
["SimpleViperWarning"] = true, |
["PVPTimer"] = true, |
["SkillsPayBills"] = true, |
["HealthPercents"] = true, |
["Inviter"] = true, |
["Levelator"] = true, |
["EVTestMod"] = true |
} |
local EML_Colors = { |
["teal"] = {0, 150, 89}, |
["green"] = {20, 150, 10}, |
["grassgreen"] = {50,150,50}, |
["darkgreen"] = {5,107,0}, |
["yellow"] = {255, 255, 0}, |
["white"] = {255, 255, 255}, |
["black"] = {0, 0, 0} |
} |
local EML_availColors = { |
[1] = "red", |
[2] = "blue", |
[3] = "cyan", |
[4] = "teal", |
[5] = "green", |
[6] = "grassgreen", |
[7] = "yellow", |
[8] = "white", |
[9] = "black" |
} |
local EML_HTMLColors = { |
["orange"] = "|cFFFF8000", |
["purple"] = "|cFFA335EE", |
function EML_getInfo(arg) |
local itemArray; |
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, itemPrice = GetItemInfo(arg) |
local itemCount = GetItemCount(arg); |
if (itemName) then |
local _,itemID = EML_Parser(itemLink); |
itemArray = { |
["MinLevel"] = itemMinLevel, |
["Type"] = itemType, |
["SubType"] = itemSubType, |
["ItemCount"] = itemCount, |
["StackCount"] = itemStackCount, |
["EquipLoc"] = itemEquipLoc, |
["Texture"] = itemTexture, |
-- Adds a value to a table |
function EML_addTable(what,where) |
local theValue = tostring(what); |
if (what == "new") then |
table.insert(where,"StartDontRemove") |
else |
if (type(where) == "table") then |
for index,value in pairs(where) do |
if (type(index) == "number") then |
table.insert(where,what) |
return true; |
elseif (type(index) == "string") then |
where[theValue] = true; |
return true; |
end |
if (type(where) == "table") then |
for index,value in pairs(where) do |
if (type(index) == "number") then |
table.insert(where,what) |
return true; |
elseif (type(index) == "string") then |
where[theValue] = true; |
return true; |
end |
table.insert(where,what) |
return true; |
else |
if (debugMode) then EMLChat("Not given a table.","chat","EML","red") end |
end |
table.insert(where,what) |
return true; |
else |
if (debugMode) then EMLChat("Not given a table.","chat","EML","red") end |
return nil; |
end |
if (theValue == "new") then |
EMLChat("Something hasn't been updated to use the new table add yet.","chat","EML","red") |
end |
end |
-- Removes a value from a table |
function EML_remTable(what,where) |
for index,value in pairs(where) do |
if (value == what) then |
table.remove(where,index) |
local removedVal = false; |
if (type(where) == "table") then |
for index,value in pairs(where) do |
if (value == what) then |
table.remove(where,index) |
removedVal = true; |
end |
end |
end |
for index,value in pairs(where) do |
if (index == what) then |
where[index]=nil; |
for index,value in pairs(where) do |
if (index == what) then |
where[index]=nil; |
removedVal = true; |
end |
end |
else |
if (debugMode) then EMLChat("RemTable Not given a table.","chat","EML","red") end |
end |
return removedVal; |
end |
-- Clears an array (table) |
isFound=true; |
end |
end |
for index,value in pairs(where) do |
if (type(value) == "table") then |
for index2,value2 in pairs(value) do |
if (value2 == what) then |
isFound = true; |
elseif (index2 == what) then |
isFound=true; |
end |
end |
end |
end |
else |
if (debugMode) then EMLChat("No table for FindTable","chat","EML") end |
return nil; |
end |
return isFound; |
end |
return value; |
elseif (what == value) then |
return index; |
elseif (type(value) == "table") then |
for index2,value2 in pairs(value) do |
if (what == index2) then |
return value2; |
elseif (what == value2) then |
return index2; |
end |
end |
end |
end |
else |
if (debugMode) then EMLChat("No table for GetTable","chat","EML") end |
return nil; |
end |
end |
-- Sets a table value |
function EML_setTable(what,where,to) |
if (type(to) == "table") then |
for index,value in pairs(to) do |
if (where == index) then |
to[where] = what; |
elseif (where == value) then |
to[index] = what |
end |
end |
else |
if (debugMode) then EMLChat("No table for SetTable","chat","EML") end |
end |
end |
-- Makes sure settings are in one array from another array |
function EML_mergeTable(arrayTo,arrayFrom) |
local newArray; |
return newArray; |
end |
-- Returns if a table is an empty table or not |
function EML_isEmpty(arg) |
local isEmpty = true; |
if (type(arg) == "table") then |
if (#(arg) < 1) then |
for index,value in pairs(arg) do |
if (index ~= nil) then |
isEmpty = false; |
end |
end |
else |
isEmpty = false; |
end |
else |
return nil; |
end |
return isEmpty; |
end |
-- Display arrays or variables |
function EML_Display(arg,from) |
local displayVar; |
EMLChat("Item "..index.." is: "..value,"chat",from) |
end |
end |
end |
if (type(arg) == "string" or type(arg) == "boolean" or type(arg) == "number") or (arg == nil) then |
else |
-- if (type(arg) == "string" or type(arg) == "boolean" or type(arg) == "number") or (arg == nil) then |
if (type(arg) == "boolean") then |
if (arg) then |
displayVar = "true" |
end |
end |
-- Displays a normal table in exact order |
function EML_displayNormal(arg,from) |
if (type(arg) == "table") then |
if (#(arg) > 0) then |
for i=1,#(arg) do |
local tempVar = tostring(arg[i]); |
EMLChat(i..": "..tempVar,"chat",from) |
end |
end |
end |
end |
-- Extracts an integrated array |
function EML_splitTwo(what) |
local val1,val2; |
val2 = value; |
end |
end |
else |
if (debugMode) then EMLChat("SplitTwo not given a table.","chat","EML","red") end |
end |
return val1,val2; |
end |
return theColor; |
end |
-- Lists availible colors in EML |
function EML_listColors(from) |
EMLChat("Availible Colors:","chat",from,"teal") |
EML_displayNormal(EML_availColors,from) |
EMLChat("----","plainchat",from,"teal") |
end |
-- EML frame toggler |
function EMLFrame_Toggle(place,what) |
if (type(place) == "string") then |
-- Prints or returns the current WoW build information |
function EML_buildInfo(what,where) |
local version, build, thedate, tocversion = GetBuildInfo() |
local buildInfo = { |
["Version"] = version, |
["Build"] = build, |
["Date"] = thedate, |
["TOC"] = tocversion, |
} |
if (debugMode) or (what == "info") then EMLChat("WoW Version: "..version..", Build: "..build..", TOC Version: "..tocversion,"chat",where) end |
return version, build, tocversion; |
return buildInfo; |
end |
-- Prints or returns the current WoW zone information |