Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console = {}
- console.__index = console
- registertimer(100, "ConsoleTimer")
- math.inf = 1 / 0
- function hprint(player, text, time, align, func)
- console[player] = console[player] or {}
- local id = nextindex(player)
- console[player][id] = {}
- console[player][id].p = player
- console[player][id].id = id
- console[player][id].msg = text
- console[player][id].t = time or 5
- console[player][id].r = time or 5
- console[player][id].f = func
- console[player][id].a = align or "left"
- setmetatable(console[player][id], console)
- return console[player][id]
- end
- function nextindex(player)
- local max = 0
- for k,v in pairs(console[player]) do
- if k > max then
- max = k
- end
- end
- return max + 1
- end
- function getmessages(player)
- return console[player]
- end
- function console:append(text, time_reset)
- local player = self.p
- if getplayer(player) then
- local id = self.id
- if console[player] then
- if console[player][id] then
- console[player][id].msg = text
- if time_reset == true or time_reset == nil then
- console[player][id].r = console[player][id].t
- end
- end
- end
- end
- end
- function console:message()
- return self.msg
- end
- function console:player()
- return self.p
- end
- function console:time()
- return self.t
- end
- function console:remaining()
- return self.r
- end
- function console:index()
- return self.id
- end
- function console:func()
- return self.f
- end
- function console:alignment()
- return self.a
- end
- function console:delete()
- console[self.p][self.id] = nil
- end
- function console:pause(duration)
- duration = duration or 5
- console[self.p][self.id].pa = duration
- end
- function console:paused()
- return self.pa
- end
- function ConsoleTimer(id, count)
- for player,t in opairs(console) do
- if type(t) == "table" and player ~= "__index" then
- for id,t2 in opairs(t) do
- if console[player][id].pa then
- console[player][id].pa = console[player][id].pa - 0.1
- if console[player][id].pa <= 0 then
- console[player][id].pa = nil
- end
- else
- console[player][id].r = console[player][id].r - 0.1
- if console[player][id].r <= 0 then
- console[player][id] = nil
- end
- end
- if console[player][id] then
- if console[player][id].f then
- if not console[player][id].f(player) then
- console[player][id] = nil
- end
- end
- end
- end
- end
- end
- for player,t in opairs(console) do
- if type(t) == "table" and player ~= "__index" then
- if getplayer(player) then
- if table.len(t) > 0 then
- local paused = 0
- for id,t2 in pairs(t) do
- if console[player][id].pa then
- paused = paused + 1
- end
- end
- if paused < table.len(t) then
- local str = ""
- for i = 0,30 do
- str = str .. "\n "
- end
- hprintf(str, player)
- for id,t2 in opairs(t) do
- if console[player][id].a == "left" then
- hprintf(console[player][id].msg, player)
- elseif console[player][id].a == "right" then
- hprintf(consolerightalign(console[player][id].msg), player)
- end
- end
- end
- end
- else
- console[player] = nil
- end
- end
- end
- return true
- end
- -- Console text length limit = 78
- function consolerightalign(text)
- local len = string.len(text)
- for i = len + 1, 78 do
- text = " " .. text
- end
- return text
- end
- function opairs(t)
- local keys = {}
- for k,v in pairs(t) do
- table.insert(keys, k)
- end
- table.sort(keys,
- function(a,b)
- if type(a) == "number" and type(b) == "number" then
- return a < b
- end
- an = string.lower(tostring(a))
- bn = string.lower(tostring(b))
- if an ~= bn then
- return an < bn
- else
- return tostring(a) < tostring(b)
- end
- end)
- local count = 1
- return function()
- if unpack(keys) then
- local key = keys[count]
- local value = t[key]
- count = count + 1
- return key,value
- end
- end
- end
- function table.len(t)
- local count = 0
- for k,v in pairs(t) do
- count = count + 1
- end
- return count
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement