Broland

Untitled

Nov 24th, 2013
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.71 KB | None | 0 0
  1. --[[
  2.     Console Version 1.0
  3.    
  4.     @author frd
  5.     @author Husky
  6.    
  7.     This script is to help seperate script errors from chat and provide
  8.     a nice interface for viewing errors and script notifications.
  9.    
  10.     The other big benefit of this script is for in-game debugging with ability
  11.     to execute Lua and view environment variables directly in the console.
  12.    
  13.     One of the features we wrote that we weren't sure were going to be used
  14.     is the ability to create binds. This is something we want to get feedback
  15.     on from the community and we can expand it from there.
  16.    
  17.     Examples:
  18.     bind j say going b; recall
  19.     bind k cast q; recall -- Stealth recall for Shaco?
  20.    
  21.     Please use your imagination and give us ideas and extra commands you
  22.     might want to see.
  23.    
  24.     Current Commands:
  25.         clear -- Clear console
  26.         say -- Message team
  27.         say_all -- Message all
  28.         buy -- Buy an item, eg: buy 1001 (buy boots)
  29.         cast -- Cast a spell eg: cast q (options: q, w, e, r, summoner1, summoner2, flash)
  30.         flash -- Flash
  31.         recall -- Recall
  32.         bind -- Bind a key eg: bind k say hello
  33.         unbind -- Unbind a key eg: unbind k
  34.         unbindall -- Unbind all keys
  35.        
  36.     Binds are automatically saved and loaded.
  37.    
  38.     To open the console press the tilt. (`)
  39.     German keyboards can use the (^) under the esc key.
  40.     ========================================================================
  41. ]]
  42.  
  43. -- Console Configuration
  44. local console = {
  45.     bgcolor = RGBA( 0, 0, 0, 170 ),
  46.     padding = 10,
  47.     textSize = 16,
  48.     height = WINDOW_H / 2,
  49.     width = WINDOW_W / 2,
  50.     linePadding = 2,
  51.     brand = "Bot of Legends - Console Version 1.0",
  52.     scrolling = {
  53.         width   = 12
  54.     },
  55.     colors = {
  56.         script = { R =   0, G = 255, B = 0 },
  57.         console = { R = 255, G = 255, B = 0 },
  58.         command = { R = 150, G = 255, B = 0 },
  59.         prompt = { R =   0, G = 255, B = 0 },
  60.         default = { R =  0, G = 255, B = 0 }
  61.     },
  62.     keys = {
  63.         220, -- German Tilt
  64.        
  65.     },
  66.     selection = {
  67.         content = "",
  68.         startLine = 1,
  69.         endLine = 1,
  70.         startPosition = 1,
  71.         endPosition = 1
  72.     }
  73. }
  74.  
  75. -- Notifications Configuration
  76. local notifications = {
  77.     bgcolor = RGBA( 0, 0, 0, 80 ),
  78.     max = 4,
  79.     length = 5000,
  80.     fadeTime = 500,
  81.     slideTime = 200,
  82.     perma = 0
  83. }
  84.  
  85. -- Binds
  86. local binds = {}
  87.  
  88. -- Command line structure
  89. local command = {
  90.     bullet = ">",
  91.     history = {},
  92.     offset = 1,
  93.     buffer = "",
  94.     methods = {
  95.         -- DEFINED at end of script to allow access to all methods
  96.     }
  97. }
  98.  
  99. -- Spell mapping (for cast/level command, etc)
  100. local spells = {
  101.     q = _Q,
  102.     w = _W,
  103.     e = _E,
  104.     r = _R,
  105.     recall = RECALL,
  106.     summoner1 = SUMMONER_1,
  107.     summoner2 = SUMMONER_2,
  108.     flash = function()
  109.         if myHero:GetSpellData(SUMMONER_1).name:find("SummonerFlash") then return SUMMONER_1
  110.         elseif myHero:GetSpellData(SUMMONER_2).name:find("SummonerFlash") then return SUMMONER_2
  111.         else return nil end
  112.     end
  113. }
  114.  
  115. -- Cursor structure
  116. local cursor = {
  117.     blinkSpeed = 1200,
  118.     offset = 0,
  119. }
  120.  
  121. -- Is the console active or not
  122. local active = false
  123.  
  124. -- The stack of console messages
  125. local stack = {}
  126. local offset = 1
  127.  
  128. -- Last notification time
  129. local closeTick = 0
  130.  
  131. -- Unorganized variables
  132. local stayAtBottom = true
  133.  
  134. -- Calculated max console messages to display on a single screen
  135. local maxMessages = math.floor((console.height - 2 * console.padding - 2 * console.textSize) / (console.textSize + console.linePadding)) + 1
  136.  
  137. -- Code ------------------------------------------------
  138. local function LoadBinds()
  139.     pcall(function() lines = io.lines(SCRIPT_PATH .. "binds.cfg") end)
  140.     if lines ~= nil then
  141.         for line in lines do
  142.             local parts = string.split(line, " ", 3)
  143.             binds[parts[2]] = parts[3]
  144.         end
  145.     end
  146. end
  147.  
  148. local function SaveBinds()
  149.     local file = assert(io.open(SCRIPT_PATH .. "binds.cfg", "w+"))
  150.     if file then
  151.         for key, cmd in pairs(binds) do
  152.             file:write("bind " .. key .. " " .. cmd .. "\n")
  153.         end
  154.         file:close()
  155.     end
  156. end
  157.  
  158. local function IsConsoleKey(key)
  159.     for i, k in ipairs(console.keys) do
  160.         if k == key then
  161.             return true
  162.         end
  163.     end
  164.  
  165.     return false
  166. end
  167.  
  168. local function GetTextColor(type, opacity)
  169.     local c = console.colors.default
  170.  
  171.     if console.colors[type] then
  172.         c = console.colors[type]
  173.     end
  174.  
  175.     return RGBA(c.R, c.G, c.B, (opacity or 1) * 255)
  176. end
  177.  
  178. local function AddMessage(msg, type, insertionOffset)
  179.     if insertionOffset then
  180.         table.insert(stack, insertionOffset, {
  181.             msg = tostring(msg),
  182.             ticks = GetTickCount(),
  183.             gameTime = GetInGameTimer(),
  184.             type = type
  185.         })
  186.     else
  187.         table.insert(stack, {
  188.             msg = tostring(msg),
  189.             ticks = GetTickCount(),
  190.             gameTime = GetInGameTimer(),
  191.             type = type
  192.         })
  193.     end
  194.  
  195.     if #stack - offset >= maxMessages and stayAtBottom then
  196.         offset = offset + 1
  197.     end
  198.  
  199.     if notifications.perma > 0 then
  200.         for i = 1, notifications.perma do
  201.             if #stack - i >= 1 then
  202.                 local item = stack[#stack - i]
  203.  
  204.                 if item.ticks < GetTickCount() - notifications.length + notifications.fadeTime then
  205.                     item.ticks = GetTickCount() - notifications.length + notifications.fadeTime
  206.                     closeTick = GetTickCount() - notifications.length + notifications.fadeTime - 1
  207.                 end
  208.             end
  209.         end
  210.     end
  211. end
  212.  
  213. local function LazyProcess(cmd)
  214.     local preExecutionStackCount = #stack
  215.     local successful, result = ExecuteLUA('return ' .. cmd)
  216.  
  217.     if successful then
  218.         successfull, result = pcall(function() return cmd .. " = " .. tostring(result) end)
  219.         if successfull then
  220.             table.remove(stack, preExecutionStackCount)
  221.             AddMessage(result, "command", preExecutionStackCount)
  222.         else
  223.             table.remove(stack, preExecutionStackCount)
  224.             AddMessage(cmd .. " = <unknown>", "command", preExecutionStackCount)
  225.         end    
  226.     else
  227.         AddMessage("Lua Error: " .. result:gsub("%[string \"\"%]:1: ", ""), "console")
  228.     end
  229. end
  230.  
  231. function ExecuteLUA(cmd)
  232.     local func, err = load(cmd, "", "t", _ENV)
  233.  
  234.     if func then
  235.         return pcall(func)
  236.     else
  237.         return false, err
  238.     end
  239. end
  240.  
  241. local function ProcessCommand(cmd)
  242.     local parts = string.split(cmd, " ", 2)
  243.     if command.methods[parts[1]] == nil then return end
  244.     return command.methods[parts[1]](#parts == 2 and parts[2] or nil)
  245. end
  246.  
  247. local function ExecuteCommand(cmd)
  248.     if cmd ~= "" then
  249.         AddMessage(cmd, "command")
  250.  
  251.         if string.len(cmd) == 0 then return end
  252.  
  253.         -- Display command in console, and add to history stack
  254.         table.insert(command.history, cmd)
  255.  
  256.         -- Parse the command
  257.         local process = ProcessCommand(cmd)
  258.  
  259.         -- If no command was found, we will attempt to execute the command as LUA code
  260.         if not process then
  261.             LazyProcess(cmd)
  262.         end
  263.     end
  264. end
  265.  
  266. local function GetTextWidth(text, textSize)
  267.     return GetTextArea("_" .. text .. "_", textSize or console.textSize).x - 2 * GetTextArea("_", textSize or console.textSize).x
  268. end
  269.  
  270. local function DrawRectangle(x, y, width, height, color)
  271.     DrawLine(x, y + (height/2), x + width, y + (height/2), height, color)
  272. end
  273.  
  274. function Console__WriteConsole(msg)
  275.     AddMessage(msg, "script")
  276. end
  277.  
  278. function Console__OnLoad()
  279.     AddMessage("Game started", "console")
  280.     AddMessage("Champion: " .. myHero.charName, "console")
  281.     LoadBinds()
  282. end
  283.  
  284. function Console__OnDraw()
  285.     local messageBoxHeight = 2 * console.padding + (maxMessages - 1) * (console.textSize + console.linePadding) + console.textSize
  286.     local promptHeight       = 2 * console.padding + console.textSize
  287.     local consoleHeight     = messageBoxHeight + promptHeight
  288.     local scrollbarHeight   = math.ceil(messageBoxHeight / math.max(#stack / maxMessages, 1))
  289.  
  290.     if active == true then
  291.         local showRatio = math.min((GetTickCount() - closeTick) / notifications.slideTime, 1)
  292.         local slideOffset = (1 - showRatio) * consoleHeight
  293.  
  294.         -- Draw console background
  295.         DrawRectangle(0, 0 - slideOffset, console.width, consoleHeight, RGBA(0, 0, 0, showRatio * 170))
  296.         DrawLine(0, messageBoxHeight - slideOffset, console.width, messageBoxHeight - slideOffset, 1, GetTextColor("prompt", showRatio * 0.16))
  297.         DrawLine(0, consoleHeight - slideOffset, console.width, consoleHeight - slideOffset, 1, GetTextColor("prompt", showRatio * 0.58))
  298.        
  299.         -- Display stack of messages
  300.         console.selection.content = ""
  301.         if #stack > 0 then
  302.             for i = offset, offset + maxMessages - 1 do
  303.                 if i > #stack then break end
  304.  
  305.                 local message = stack[i]
  306.  
  307.                 local selectionStartLine, selectionEndLine, selectionStartPosition, selectionEndPosition
  308.                 if console.selection.startLine < console.selection.endLine or (console.selection.startLine == console.selection.endLine and console.selection.startPosition < console.selection.endPosition) then
  309.                     selectionStartLine = console.selection.startLine
  310.                     selectionEndLine = console.selection.endLine
  311.                     selectionStartPosition = console.selection.startPosition
  312.                     selectionEndPosition = console.selection.endPosition
  313.                 else
  314.                     selectionStartLine = console.selection.endLine
  315.                     selectionEndLine = console.selection.startLine
  316.                     selectionStartPosition = console.selection.endPosition
  317.                     selectionEndPosition = console.selection.startPosition
  318.                 end
  319.  
  320.                 if i >= selectionStartLine and i <= selectionEndLine then
  321.                     local rightOffset
  322.                    
  323.                     local leftOffset = (i == selectionStartLine) and (GetTextArea("_" .. ("[" .. TimerText(message.gameTime) .. "] " .. message.msg):sub(1, selectionStartPosition - 1) .. "_", console.textSize).x - 2 * GetTextArea("_", console.textSize).x) or 0
  324.  
  325.                     if i == selectionEndLine then
  326.                         local selectedText = ("[" .. TimerText(message.gameTime) .. "] " .. message.msg):sub(selectionStartLine == selectionEndLine and selectionStartPosition or 1, selectionEndPosition - 1)
  327.                         rightOffset = GetTextWidth(selectedText)
  328.  
  329.                         console.selection.content = console.selection.content .. (console.selection.content ~= "" and "\r\n" or "") .. selectedText
  330.                     else
  331.                         local selectedText = ("[" .. TimerText(message.gameTime) .. "] " .. message.msg):sub(selectionStartLine == i and selectionStartPosition or 1)
  332.                         rightOffset = WINDOW_W - 2 * console.padding - leftOffset - (scrollbarHeight == messageBoxHeight and 0 or console.scrolling.width)
  333.  
  334.                         console.selection.content = console.selection.content .. (console.selection.content ~= "" and "\r\n" or "") .. selectedText
  335.                     end
  336.  
  337.                     DrawRectangle(console.padding + leftOffset, console.padding + (i - offset) * (console.textSize + console.linePadding) - slideOffset - console.linePadding / 2, rightOffset, console.textSize + console.linePadding, 1157627903)
  338.                 end
  339.  
  340.                 if message ~= nil then
  341.                     DrawText("[" .. TimerText(message.gameTime) .. "] " .. message.msg, console.textSize, console.padding, console.padding + (i - offset) * (console.textSize + console.linePadding) - slideOffset, GetTextColor(message.type, showRatio))
  342.                 end
  343.             end
  344.         end
  345.  
  346.         -- Show what user is currently typing
  347.         DrawText(command.bullet .. " " .. command.buffer, console.textSize, console.padding, messageBoxHeight + console.padding - slideOffset, GetTextColor("prompt", showRatio))
  348.         if GetTickCount() % cursor.blinkSpeed > cursor.blinkSpeed / 2 then
  349.             DrawText("_", console.textSize, console.padding + GetTextArea(command.bullet .. " " .. command.buffer:sub(1, cursor.offset) .. "_", console.textSize).x - GetTextArea("_", console.textSize).x, messageBoxHeight + console.padding - slideOffset, GetTextColor("prompt", showRatio))
  350.         end
  351.  
  352.         DrawText(console.brand, console.textSize, console.width - GetTextArea(console.brand, console.textSize).x - console.padding, messageBoxHeight + console.padding - slideOffset, GetTextColor("prompt", showRatio * 0.58))
  353.  
  354.         if scrollbarHeight ~= messageBoxHeight then
  355.             DrawRectangle(console.width - console.scrolling.width, 0 - slideOffset + (offset - 1) / (#stack - maxMessages) * (messageBoxHeight - scrollbarHeight), console.scrolling.width, scrollbarHeight, GetTextColor("prompt", showRatio * 0.4))
  356.         end
  357.     elseif #stack > 0 then
  358.         local filteredStack = {}
  359.  
  360.         for i = #stack, math.max(#stack - notifications.max + 1, 1), - 1 do
  361.             if (GetTickCount() - stack[i].ticks > notifications.length or stack[i].ticks < closeTick) and (#stack - i) >= notifications.perma then break end
  362.             table.insert(filteredStack, stack[i])
  363.         end
  364.  
  365.         if #filteredStack > 0 then
  366.             local slideOffset = 0
  367.             for i = 1, #filteredStack do
  368.                 slideOffset = slideOffset - (console.textSize + (i == #filteredStack and console.padding * 2 or console.linePadding)) * ((#filteredStack - i < notifications.perma) and 0 or math.max((GetTickCount() - filteredStack[#filteredStack - i + 1].ticks - notifications.length + notifications.fadeTime) / notifications.fadeTime, 0))
  369.             end
  370.  
  371.             DrawRectangle(0, 0, console.width, (console.textSize * #filteredStack) + (console.padding * 2) + (#filteredStack - 1) * console.linePadding + slideOffset, notifications.bgcolor)
  372.             DrawLine(0, (console.textSize * #filteredStack) + (console.padding * 2) + slideOffset + (#filteredStack - 1) * console.linePadding, console.width, (console.textSize * #filteredStack) + (console.padding * 2) + slideOffset + (#filteredStack - 1) * console.linePadding, 1, GetTextColor("prompt", 0.27))
  373.  
  374.             for i = 1, #filteredStack do
  375.                 local item = filteredStack[#filteredStack + 1 - i]
  376.  
  377.                 DrawText("[" .. TimerText(item.gameTime) .. "] " .. item.msg, console.textSize, console.padding, console.padding + (i - 1) * (console.linePadding + console.textSize) + slideOffset, GetTextColor(item.type, 1 - ((#filteredStack - i < notifications.perma) and 0 or math.max((GetTickCount() - item.ticks - notifications.length + notifications.fadeTime) / notifications.fadeTime, 0))) )
  378.             end
  379.         end
  380.     end
  381. end
  382.  
  383. function getLineCoordinates(referencePoint)
  384.     local yValue = math.max(math.ceil((referencePoint.y - console.padding - console.textSize) / (console.textSize + console.linePadding)) + 1, 1) + offset - 1
  385.     local xValue = referencePoint.x - console.padding
  386.  
  387.     if yValue > #stack then
  388.         return #stack + 1, math.huge
  389.     else
  390.         local stringValue = "[" .. TimerText(stack[yValue].gameTime) .. "] " .. stack[yValue].msg
  391.         local stringWidth = 0
  392.         local charNumber = 0
  393.         for i = 1, #stringValue do
  394.             newStringWidth = stringWidth + GetTextArea("_" .. stringValue:sub(i,i) .. "_", console.textSize).x - 2 * GetTextArea("_", console.textSize).x
  395.             if newStringWidth > xValue then break end
  396.             stringWidth = newStringWidth
  397.             charNumber = i
  398.         end
  399.  
  400.         return yValue, charNumber + 1
  401.     end
  402. end
  403.  
  404. function Console__OnMsg(msg, key)
  405.     local messageBoxHeight = 2 * console.padding + (maxMessages - 1) * (console.textSize + console.linePadding) + console.textSize
  406.     local promptHeight       = 2 * console.padding + console.textSize
  407.     local consoleHeight     = messageBoxHeight + promptHeight
  408.     local scrollbarHeight   = math.ceil(messageBoxHeight / math.max(#stack / maxMessages, 1))
  409.  
  410.     if active and msg == WM_RBUTTONUP then
  411.         SetClipboardText(console.selection.content)
  412.         console.selection = {
  413.             content = "",
  414.             startLine = 1,
  415.             endLine = 1,
  416.             startPosition = 1,
  417.             endPosition = 1
  418.         }
  419.     elseif active and msg == WM_LBUTTONDOWN then
  420.         if GetCursorPos().x >= console.width - console.scrolling.width then
  421.             dragConsole = true
  422.             dragStart = {x = GetCursorPos().x, y = GetCursorPos().y}
  423.             startOffset = offset
  424.         else
  425.             local line, char = getLineCoordinates(GetCursorPos())
  426.  
  427.             if line then
  428.                 console.selection.startLine = line
  429.                 console.selection.endLine = line
  430.                 console.selection.startPosition = char
  431.                 console.selection.endPosition = char
  432.  
  433.                 selecting = true
  434.             end
  435.         end
  436.     elseif active and msg == WM_LBUTTONUP then
  437.         if selecting then
  438.             local line, char = getLineCoordinates(GetCursorPos())
  439.  
  440.             if line then
  441.                 console.selection.endLine = line
  442.                 console.selection.endPosition = char
  443.             end
  444.         end
  445.  
  446.         dragConsole = false
  447.         selecting = false
  448.     elseif active and msg == WM_MOUSEMOVE then
  449.         if selecting then
  450.             local line, char = getLineCoordinates(GetCursorPos())
  451.  
  452.             if line then
  453.                 console.selection.endLine = line
  454.                 console.selection.endPosition = char
  455.             end
  456.         end
  457.  
  458.         if dragConsole then
  459.             if #stack > maxMessages then
  460.                 stayAtBottom = false
  461.  
  462.                 offset = startOffset + math.round(((GetCursorPos().y - dragStart.y) * (#stack - maxMessages) / (messageBoxHeight - scrollbarHeight)) + 1)
  463.                 if offset < 1 then
  464.                     offset = 1
  465.                 elseif offset >= #stack - maxMessages + 1 then
  466.                     offset = #stack - maxMessages + 1
  467.                     stayAtBottom = true
  468.                 end
  469.             end
  470.         end
  471.     end
  472.  
  473.     if active then
  474.         BlockMsg()
  475.     end
  476.  
  477.     if active and msg == KEY_DOWN then
  478.         local oldCommandBuffer = command.buffer
  479.    
  480.         if key == 13 then --enter
  481.             ExecuteCommand(command.buffer)
  482.             if #stack > maxMessages then
  483.                 offset = #stack - maxMessages + 1
  484.             end
  485.             command.buffer = ""
  486.             cursor.offset = 0
  487.             stayAtBottom = true
  488.         elseif key == 8 then --backspace
  489.             if cursor.offset > 0 then
  490.                 command.buffer = command.buffer:sub(1, cursor.offset - 1) .. oldCommandBuffer:sub(cursor.offset + 1)
  491.                 cursor.offset = cursor.offset - 1
  492.             end
  493.         elseif key == 46 then -- delete
  494.             command.buffer = command.buffer:sub(1, cursor.offset) .. oldCommandBuffer:sub(cursor.offset + 2)
  495.         elseif key == 33 then --pgup
  496.             offset = math.max(offset - maxMessages, 1)
  497.             stayAtBottom = false
  498.         elseif key == 34 then --pgdn
  499.             offset = math.max(math.min(offset + maxMessages, #stack - maxMessages + 1), 1)
  500.             if offset == #stack - maxMessages + 1 then
  501.                 stayAtBottom = true
  502.             end
  503.         elseif key == 38 and #command.history > 0 then --up arrow
  504.             if command.offset < #command.history then
  505.                 command.offset = command.offset + 1
  506.             end
  507.             command.buffer = command.history[command.offset]
  508.             cursor.offset = #command.buffer
  509.         elseif key == 40 and #command.history > 0 then --down arrow
  510.             if command.offset > 1 then
  511.                 command.offset = command.offset - 1
  512.             end
  513.             command.buffer = command.history[command.offset]
  514.             cursor.offset = #command.buffer
  515.         elseif key == 37 then --left arrow
  516.             cursor.offset = math.max(cursor.offset - 1, 0)
  517.         elseif key == 39 then --right arrow
  518.             cursor.offset = math.min(cursor.offset + 1, #command.buffer)
  519.         elseif key == 35 then
  520.             cursor.offset = #command.buffer
  521.         elseif key == 36 then
  522.             cursor.offset = 0
  523.         elseif ToAscii(key) == string.char(3) then
  524.             SetClipboardText(console.selection.content)
  525.             console.selection = {
  526.                 content = "",
  527.                 startLine = 1,
  528.                 endLine = 1,
  529.                 startPosition = 1,
  530.                 endPosition = 1
  531.             }
  532.         elseif ToAscii(key) == string.char(22) then
  533.             local textToAdd = GetClipboardText():gsub("\r", ""):gsub("\n", " ")
  534.             command.buffer = oldCommandBuffer:sub(1, cursor.offset) .. textToAdd .. oldCommandBuffer:sub(cursor.offset + 1)
  535.             cursor.offset = cursor.offset + #textToAdd
  536.         elseif key == 9 then
  537.             for k,v in pairs(_G) do
  538.                 if k:sub(1, #command.buffer) == command.buffer then
  539.                     command.buffer = k
  540.                     cursor.offset = #k
  541.                     break
  542.                 end
  543.             end
  544.         else
  545.             local asciiChar = ToAscii(key)
  546.             if asciiChar ~= nil then
  547.                 command.buffer = oldCommandBuffer:sub(1, cursor.offset) .. asciiChar .. oldCommandBuffer:sub(cursor.offset + 1)
  548.                 cursor.offset = cursor.offset + 1
  549.             end
  550.         end
  551.     end
  552.    
  553.     if msg == KEY_DOWN and IsConsoleKey(key) then
  554.         active = not active
  555.         command.buffer = ""
  556.         closeTick = GetTickCount()
  557.  
  558.         if active then
  559.             AllowKeyInput(false)
  560.             AllowCameraInput(false)
  561.         else
  562.             AllowKeyInput(true)
  563.             AllowCameraInput(true)
  564.         end
  565.     end
  566.    
  567.     if msg == KEY_DOWN and binds[ToAscii(key)] and not active then
  568.         local parts = string.split(binds[ToAscii(key)], ";")
  569.         for p, cmd in ipairs(parts) do
  570.             ProcessCommand(cmd)
  571.         end
  572.     end
  573. end
  574.  
  575. -- Console Commands ---------------------------------
  576. command.methods = {
  577.     clear = function()
  578.         stack = {}
  579.         offset = 1
  580.     end,
  581.    
  582.     say = function(query)
  583.         SendChat(query)
  584.         return true
  585.     end,
  586.    
  587.     say_all = function(query)
  588.         SendChat("/all " .. query)
  589.         return true
  590.     end,
  591.    
  592.     buy = function(query)
  593.         BuyItem(tonumber(query))
  594.         return true
  595.     end,
  596.  
  597.     cast = function(query)     
  598.         local s = type(spells[query]) == "function" and spells[query]() or spells[query]
  599.         if s then
  600.             local target = GetTarget()
  601.             if target ~= nil then
  602.                 CastSpell(s, target)
  603.             else
  604.                 CastSpell(s, mousePos.x, mousePos.z)
  605.             end
  606.         else
  607.             AddMessage("Attempted to cast invalid spell: \"" .. query .. "\"", "console")
  608.         end
  609.        
  610.         return true
  611.     end,
  612.    
  613.     flash = function() return command.methods.cast("flash") end,
  614.     recall = function() return command.methods.cast("recall") end,
  615.    
  616.     level = function(query)
  617.         local s = type(spells[query]) == "function" and spells[query]() or spells[query]
  618.         if s then
  619.             LevelSpell(s)
  620.         end
  621.        
  622.         return true
  623.     end,
  624.    
  625.     bind = function(query)
  626.         local parts = string.split(query, " ", 2)
  627.         binds[parts[1]] = parts[2]
  628.         SaveBinds()
  629.         return true
  630.     end,
  631.    
  632.     unbind = function(query)
  633.         binds[query] = nil
  634.         SaveBinds()
  635.         return true
  636.     end,
  637.    
  638.     unbindall = function()
  639.         binds = {}
  640.         SaveBinds()
  641.         return true
  642.     end,
  643.    
  644.     reload = function()
  645.         LoadBinds()
  646.         return true
  647.     end
  648. }
  649.  
  650. AddLoadCallback(Console__OnLoad)
  651. AddDrawCallback(Console__OnDraw)
  652. AddMsgCallback(Console__OnMsg)
  653. _G.WriteConsole = Console__WriteConsole
  654. _G.PrintChat = _G.WriteConsole
  655. _G.Console__IsOpen = active
Advertisement
Add Comment
Please, Sign In to add comment