Полезные сниппеты и функции.

crybaby

?
Администратор
Делитесь своими функциями, которые Вы считаете наиболее оптимальными и удобными для использования.

[b]Описание:[/b] *текст*
[b]Код:[/b]
[code=lua]*код*[/code]
[b]Пример использования:[/b]
[code=lua]*код примера*[/code]
 

crybaby

?
Администратор
Описание: заменяет все возможные символы на русские
Код:
Lua:
function RusToEng(text)
    lang = {['`'] = 'ё', ['~'] = 'ё', ['q'] = 'й', ['w'] = 'ц', ['e'] = 'у', ['r'] = 'к', ['t'] = 'е', ['y'] = 'н', ['u'] = 'г', ['i'] = 'ш', ['o'] = 'щ', ['p'] = 'з', ['['] = 'х', ['{'] = 'х', [']'] = 'ъ', ['}'] = 'ъ', ['a'] = 'ф', ['s'] = 'ы', ['d'] = 'в', ['f'] = 'а', ['g'] = 'п', ['h'] = 'р', ['j'] = 'о', ['k'] = 'л', ['l'] = 'д', [';'] = 'ж', ["'"] = 'э', ['"'] = 'э', ['z'] = 'я', ['x'] = 'ч', ['c'] = 'с', ['v'] = 'м', ['b'] = 'и', ['n'] = 'т', ['m'] = 'ь', ['<'] = 'б', [','] = 'б', ['>'] = 'ю', ['.'] = 'ю'}
    result = text == '' and nil or ''
    if result then
        for i = 0, #text do
            letter = string.sub(text, i, i)
            if letter then
                result = (letter:find('[A-Z/{/}/</>]') and string.rupper(lang[string.lower(letter)]) or letter:find('[a-z/,]') and lang[letter] or letter)..result
            end
        end
    end
    return result and result:reverse() or result
end
Пример использования:
Lua:
-- если ввести [eq вернёт хуй

function main()
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('asd', function(text) sampAddChatMessage(RusToEng(text), -1) end)
    wait(-1)
end

function RusToEng(text)
    lang = {['`'] = 'ё', ['~'] = 'ё', ['q'] = 'й', ['w'] = 'ц', ['e'] = 'у', ['r'] = 'к', ['t'] = 'е', ['y'] = 'н', ['u'] = 'г', ['i'] = 'ш', ['o'] = 'щ', ['p'] = 'з', ['['] = 'х', ['{'] = 'х', [']'] = 'ъ', ['}'] = 'ъ', ['a'] = 'ф', ['s'] = 'ы', ['d'] = 'в', ['f'] = 'а', ['g'] = 'п', ['h'] = 'р', ['j'] = 'о', ['k'] = 'л', ['l'] = 'д', [';'] = 'ж', ["'"] = 'э', ['"'] = 'э', ['z'] = 'я', ['x'] = 'ч', ['c'] = 'с', ['v'] = 'м', ['b'] = 'и', ['n'] = 'т', ['m'] = 'ь', ['<'] = 'б', [','] = 'б', ['>'] = 'ю', ['.'] = 'ю'}
    result = text == '' and nil or ''
    if result then
        for i = 0, #text do
            letter = string.sub(text, i, i)
            if letter then
                result = (letter:find('[A-Z/{/}/</>]') and string.rupper(lang[string.lower(letter)]) or letter:find('[a-z/,]') and lang[letter] or letter)..result
            end
        end
    end
    return result and result:reverse() or result
end

function string.rupper(s) -- function by qrlk (https://blast.hk/threads/13380/#post-170330)
    local russian_characters = { [168] = 'Ё', [184] = 'ё', [192] = 'А', [193] = 'Б', [194] = 'В', [195] = 'Г', [196] = 'Д', [197] = 'Е', [198] = 'Ж', [199] = 'З', [200] = 'И', [201] = 'Й', [202] = 'К', [203] = 'Л', [204] = 'М', [205] = 'Н', [206] = 'О', [207] = 'П', [208] = 'Р', [209] = 'С', [210] = 'Т', [211] = 'У', [212] = 'Ф', [213] = 'Х', [214] = 'Ц', [215] = 'Ч', [216] = 'Ш', [217] = 'Щ', [218] = 'Ъ', [219] = 'Ы', [220] = 'Ь', [221] = 'Э', [222] = 'Ю', [223] = 'Я', [224] = 'а', [225] = 'б', [226] = 'в', [227] = 'г', [228] = 'д', [229] = 'е', [230] = 'ж', [231] = 'з', [232] = 'и', [233] = 'й', [234] = 'к', [235] = 'л', [236] = 'м', [237] = 'н', [238] = 'о', [239] = 'п', [240] = 'р', [241] = 'с', [242] = 'т', [243] = 'у', [244] = 'ф', [245] = 'х', [246] = 'ц', [247] = 'ч', [248] = 'ш', [249] = 'щ', [250] = 'ъ', [251] = 'ы', [252] = 'ь', [253] = 'э', [254] = 'ю', [255] = 'я', }
    s = s:upper()
    local strlen = s:len()
    if strlen == 0 then return s end
    s = s:upper()
    local output = ''
    for i = 1, strlen do
        local ch = s:byte(i)
        if ch >= 224 and ch <= 255 then -- lower russian characters
            output = output .. russian_characters[ch - 32]
        elseif ch == 184 then -- ё
            output = output .. russian_characters[168]
        else
            output = output .. string.char(ch)
        end
    end
    return output
end
 
Последнее редактирование:

imring

чо тут
Администратор
Описание: рендерит свой бар
Lua:
local draw = ffi.cast('void (__cdecl *)(float, float, unsigned int, unsigned int, float, char, bool, bool, unsigned long, unsigned long)', 0x728640)
function draw_bar(x, y, width, height, progress, color)
    draw(x, y, width, height, progress, 0, false, true, color, color)
end
Пример:
Lua:
local ffi = require 'ffi'

local draw = ffi.cast('void (__cdecl *)(float, float, unsigned int, unsigned int, float, char, bool, bool, unsigned long, unsigned long)', 0x728640)
function draw_bar(x, y, width, height, progress, color)
    draw(x, y, width, height, progress, 0, false, true, color, color)
end

function onD3DPresent()
    draw_bar(40, 500, 400, 20, math.random(0, 100), 0xFF00FFCC)
end
24
 
Верх