• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.

TalkAction Tabulate

Jano

oturhaN
Joined
Feb 21, 2008
Messages
876
Solutions
1
Reaction score
68
Location
Chile
is is annoying when people post scripts without tabs, its harder to help them and its harder find errors, also they are uglier =<

PHP:
local file = "lol.lua"

local adding, closing, elses = {'function', 'if', 'while', 'for', 'repeat'}, {'end', 'until'}, {'else', 'elseif'}

function onSay(cid, words, param, channel)

    local tmp = {}
    
    for line in io.lines(file) do
    
        line = line:gsub('    ', '')
        line = line:gsub('\n', '')
        
        if line:find(' ') then
            line = (line:gsub(' ', '') == '') and '' or line
        end
        
        for _, char in ipairs({',', '='}) do
            if line:find(char) then
                if (char == '=') then
                    if line:find('==') or line:find('>=') or line:find('<=') or line:find('~=') then
                        break
                    end
                end
                local expl, new = line:explode(char), ''
                for k, str in ipairs(expl) do
                    new = new .. str ..  ((k < #expl) and ((char == ',') and ', ' or ' = ') or '')
                end
                line = new
            end
        end
        
        if (line ~= '') then
            table.insert(tmp, line)
        end
    end
    
    local function makeTab(times)
        local ret = ''
        for i = 1, times do
            ret = ret .. '    '
        end
        return ret
    end
    
    local times, text = 0, '-- generated script\n\n'
    
    for _, rewrite in ipairs(tmp) do
    
        local temp = nil
        
        for _, char in ipairs(adding) do
            if (rewrite:find(char)) then
                if not (rewrite:find('.' .. char)) then
                    temp = times
                    times = times + 1
                end
            end
        end
        
        for _, char in ipairs(closing) do
            if (rewrite:find(char)) then
                if not (rewrite:find('.' .. char)) then
                    temp = times - 1
                    times = times - 1
                end
            end
        end
        
        for _, char in ipairs(elses) do
            if (rewrite:find(char)) then
                if not (rewrite:find('.' .. char)) then
                    temp = times - 1
                end
            end
        end
        text = text .. makeTab(temp or times) .. rewrite .. '\n'
    end
    
    local open =  io.open('generated_' .. file, "w")
    if open then
        open:write(text)
        open:close()
    end
    return true
end
 

Attachments

Last edited:
nice i like it. but i already tab scripts so i dont need it. i hope people who dont tab do start to use this.
 
Very Useful!! Here's your seal of approval:
sealofapproval.png

Signed By:_______________
LOL
 
forgot to add

Code:
~=

in

Code:
if line:find('==') or line:find('>=') or  line:find('<=') then

will fix soon
 
real tabs =P

Lua tag replace tabs with spaces, but the generated file will have real tabs.

edit: just noticed that Lua tags fuck off the function lol

ok was testing and any tag break the tabs work, i ve attached the original file in the first post, so tabs should work :] <-
 
Last edited:
haha kool, but its good form to tab yourself! xD get the nubs to tab scripts by themselves
 
Back
Top