Hey, Ive been trying to understand the different functions in this lua for awhile now,
Can anyone break this down for me? My brain just cant handle it.
Thanks in advance, Jon
Code:
-- Author : Bitt (Alliance Rogue) on Jubei'Thos
--
-- Version 0.3 Date: 9 July 2006
-- Implemented an options dialog which allows toggling of whether the
-- delay time is adjusted for lag.
-- /cdo displays the Options dialog for Chat Delay.
-- Saves the state of the Lag Adjust selection between game sessions
--
-- Version 0.2 Date: 8 July 2006
-- Can be called as a slash command with comman separated arguments
-- EG: /cdel Five seconds have elapsed,5
--
-- Version 0.1 Date : 25 June 2006
-- Allows a message to be delayed by a number of seconds before being
-- sent using SAY
-- Adds 2 x latency to the chat delay
CDEL_VERSION = "0.3";
CDEL_OPTION_TEXT = "Options"
CDEL_LAG_OPTION_TEXT = "Lag Compensation"
function TimerActive()
return cdelTimer == 1;
end
function cdel_EventHandler(event)
if ( event == "VARIABLES_LOADED" ) then
if ( not CdelOptions ) then
CdelOptions = { };
CdelOptions["LagAdjust"] = true;
else
cdel_options_load();
end
end
end
function cdel_splitLine(cmd,delim)
-- Searches for 1st occurence of delim and splits the string at that point returning each part
if not delim then
delim = ',';
end
if cmd then
local s,l,str = strfind(cmd,delim);
if s then
return strsub(cmd,1,l-1), strsub(cmd,l+1);
else
return cmd;
end
end
return cmd;
end
function cdel_slashCall(cmd,func)
-- calls func with upto 10 arguments
local args = {};
local i = 0;
local j = 1;
repeat
args[i],args[j] = cdel_splitLine(cmd,',');
cmd = args[j];
i = i+1;
j = j+1;
until not cmd;
func(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[6],args[7],args[8],args[9]);
end
function cdel_load()
SLASH_CDEL1 = "/cdel";
SlashCmdList["CDEL"] = function(cmd)
cdel_slashCall(cmd,cdel);
end
SLASH_CDO1 = "/cdo";
SlashCmdList["CDO"] = cdel_opt;
-- Initialise the timers
cdel_initialize();
this:RegisterEvent("VARIABLES_LOADED");
end
function cdel_options_load()
if (CdelOptions) then
CdelOptLagAdjust:SetChecked(CdelOptions["LagAdjust"]);
end
end
function cdel_initialize()
cdelOptVisible = 0;
cdelTimer = 0;
cdelStartTime = 0;
cdelTimerFunc = doMsg;
end
function cdel_opt()
if ( cdelOptVisible == 0 ) then
cdelOptVisible = 1;
CdelOptFrame:Show();
else
cdelOptVisible = 0;
CdelOptFrame:Hide();
end
end
function Cdel_Opt_Lag_OnClick()
if ( CdelOptions.LagAdjust ) then
CdelOptions["LagAdjust"] = false;
else
CdelOptions["LagAdjust"] = true;
end
end
function cdel_credits()
chat_frame_message("Chat Delay is loaded - version "..CDEL_VERSION);
end
function cdel_update_timer()
local elapsed = getCdelElapsedTime();
if ( elapsed >= cdelTimerDelay ) then
cdel_initialize();
cdelTimerFunc(cdelTimerArgs);
end
end
function cdel_startTimer()
cdelTimer = 1;
cdelStartTime = time();
end
function chat_frame_message(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff00f100"..msg);
end
function getCdelElapsedTime()
return time() - cdelStartTime;
end
function cdel(msg,delay)
if ( CdelOptions.LagAdjust ) then
lag = GetNetStats();
else
lag = 0;
end
if not msg then
return;
end
if msg and not delay then
delay = 0;
end
-- chat_frame_message("Lag: "..lag.." milliseconds.");
cdelTimerDelay = delay + (lag * 2);
cdelTimerArgs = msg
cdel_startTimer();
end
function doMsg(msg,delay)
SendChatMessage(msg);
end