--[[ shared_functions.lua Various functions used by EFM. ]] -- Function: Return the string value for slash command options... function EFM_SF_SlashClean(commandString, msgLine) local tempValue; tempValue = string.sub(msgLine, (string.len(commandString) + 2)); if (string.find(tempValue, "^\"") ~= nil) then tempValue = string.sub(tempValue, 2); end if (string.find(tempValue, "\"$") ~= nil) then tempValue = string.sub(tempValue, 1, (string.len(tempValue) - 1)); end return tempValue; end -- Function: Check to see if a given string is in the table keys function EFM_SF_StringInTableKeys(inputTable, inputString) for key, val in pairs(inputTable) do if (key == inputString) then return true; end end return false; end -- Function: Check to see if a given string is in the table. function EFM_SF_StringInTable(inputTable, inputString) for index = 1, table.getn(inputTable) do if (inputTable[index] == inputString) then return true; end end return false; end -- Function: Merge two LUA tables function EFM_SF_mergeTable(src,dest) for key,val in pairs(src) do local dval = dest[key]; if (type(val) == "table") then if (dval == nil) then dval = {}; dest[key] = dval; end EFM_SF_mergeTable(val, dval) else if ((dval == nil) and (dval ~= val)) then dest[key] = val; end end end end -- Function: Format an input number to return a human-readable time format. function EFM_SF_FormatTime(duration) local minutes = floor(duration / 60); local seconds = duration - (minutes * 60); local tens = floor(seconds/10); local single = seconds - (tens * 10); return minutes..":"..tens..single; end -- Function: Return the value to the given precision function EFM_SF_ValueToPrecision(value, precision) local precValue = 10 ^ precision; value = floor(value * precValue) / precValue; return value; end -- Function: Send a debug message out. function EFM_Shared_DebugMessage(message, debug) if (debug) then DEFAULT_CHAT_FRAME:AddMessage("Debug: "..message, 0.8, 0.4, 0.4); end end -- Function: Get "World Map" location function EFM_Shared_GetWorldMapPosition() SetMapZoom(GetCurrentMapContinent()); local mapX, mapY = GetPlayerMapPosition("player"); mapX = EFM_SF_ValueToPrecision(mapX, 2); mapY = EFM_SF_ValueToPrecision(mapY, 2); return mapX, mapY; end -- Function: Get continent name function EFM_Shared_GetContinentName(continentNum) local continentNames, key, val = { GetMapContinents() } ; return continentNames[continentNum]; end -- Function: Get zone name function EFM_Shared_GetZoneName(continentNum, zoneNum) local zoneNames = { GetMapZones(continentNum) } ; return zoneNames[zoneNum]; end