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

lorgon

Известный
657
268
Описание: Функция точек на кубической кривой Безье

Код:
Code:
function cubicBezier(p0, p1, p2, p3, t) -- t ∈ [0; 1]
    local x = (1 - t)^3 * p0[1] + 3 * (1 - t)^2 * t * p1[1] + 3 * (1 - t) * t^2 * p2[1] + t^3 * p3[1]
    local y = (1 - t)^3 * p0[2] + 3 * (1 - t)^2 * t * p1[2] + 3 * (1 - t) * t^2 * p2[2] + t^3 * p3[2]
    return {x, y}
end
Пример использования:
Example:
function cubicBezier(p0, p1, p2, p3, t)
    local x = (1 - t)^3 * p0[1] + 3 * (1 - t)^2 * t * p1[1] + 3 * (1 - t) * t^2 * p2[1] + t^3 * p3[1]
    local y = (1 - t)^3 * p0[2] + 3 * (1 - t)^2 * t * p1[2] + 3 * (1 - t) * t^2 * p2[2] + t^3 * p3[2]
    return {x, y}
end

local p0, p1, p2, p3 = {0, 0}, {0.5, 0.0}, {0.5, 1.0}, {1, 1}
for t = 0, 1, 0.05 do
    local p = cubicBezier(p0, p1, p2, p3, t)
    drawPoint(p[1], p[2]) -- условная функция
end

1667048990733.png
- Плавная или красивая анимация чего-либо
- Соединение двух элементов плавной кривой (дизайн)
 

Cosmo

Известный
Друг
646
2,597
Описание: Функция точек на кубической кривой Безье

Код:
Code:
function cubicBezier(p0, p1, p2, p3, t) -- t ∈ [0; 1]
    local x = (1 - t)^3 * p0[1] + 3 * (1 - t)^2 * t * p1[1] + 3 * (1 - t) * t^2 * p2[1] + t^3 * p3[1]
    local y = (1 - t)^3 * p0[2] + 3 * (1 - t)^2 * t * p1[2] + 3 * (1 - t) * t^2 * p2[2] + t^3 * p3[2]
    return {x, y}
end
Пример использования:
Example:
function cubicBezier(p0, p1, p2, p3, t)
    local x = (1 - t)^3 * p0[1] + 3 * (1 - t)^2 * t * p1[1] + 3 * (1 - t) * t^2 * p2[1] + t^3 * p3[1]
    local y = (1 - t)^3 * p0[2] + 3 * (1 - t)^2 * t * p1[2] + 3 * (1 - t) * t^2 * p2[2] + t^3 * p3[2]
    return {x, y}
end

local p0, p1, p2, p3 = {0, 0}, {0.5, 0.0}, {0.5, 1.0}, {1, 1}
for t = 0, 1, 0.05 do
    local p = cubicBezier(p0, p1, p2, p3, t)
    drawPoint(p[1], p[2]) -- условная функция
end

- Плавная или красивая анимация чего-либо
- Соединение двух элементов плавной кривой (дизайн)
Сайт на котором можно подобрать нужную кривую: https://easings.net/ru
 
  • Нравится
Реакции: lorgon

Lolendor

вотофак
Проверенный
546
567

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Описание: Изменяет цвет обводки маркеров на карте которыми позначают: Игроков, серверные метки и т.д

Скриншот:
1667596750148.png


Код:
Lua:
local memory = require 'memory'

-- Квадрат
memory.seutint8(0x584114, 0xFF, true) -- R
memory.setuint8(0x584112, 0xFF, true) -- G
memory.setuint8(0x58410A, 0xFF, true) -- B

-- Треугольник вниз
memory.setuint8(0x584252, 0xFF, true) -- R
memory.setuint8(0x584250, 0xFF, true) -- G
memory.setuint8(0x584248, 0xFF, true) -- B

-- Треугольник вверх
memory.setuint8(0x58438D, 0xFF, true) -- R
memory.setuint8(0x58438B, 0xFF, true) -- G
memory.setuint8(0x584385, 0xFF, true) -- B
 

VRush

https://t.me/vrushscript
Проверенный
2,341
1,089
Описание: Увидел в терминале такую штуку ТЫК и сделал на имгуи ТЫК
Пример использования:
Lua:
if imgui.InputText('', input) then

else
    gotext(math.random(#texts),input)
end

Код:
Lua:
local texts = {
   'К,и,ї,в,с,т,а,р',
   'L,i,f,e,c,e,l,l',
   'V,a,d,a,f,o,n',
}

function gotext(num, i)
   if n == nil then n = 0 end
   if s == nil then s = '' end
   lua_thread.create(function()
      while act do wait(0) end
      if num == n then num = num - 1 if num <= 0 then num = 1 end end
      n, act = num, true
      for w in string.gmatch(texts[num],"[^,]+") do
         s = s..w
         i.v = u8(s)
         wait(300)
      end
      wait(600)
      s, act = '', false
   end)
end
 

why ega

РП игрок
Модератор
2,541
2,233
Описание: Увидел в терминале такую штуку ТЫК и сделал на имгуи ТЫК
Пример использования:
Lua:
if imgui.InputText('', input) then

else
    gotext(math.random(#texts),input)
end

Код:
Lua:
local texts = {
   'К,и,ї,в,с,т,а,р',
   'L,i,f,e,c,e,l,l',
   'V,a,d,a,f,o,n',
}

function gotext(num, i)
   if n == nil then n = 0 end
   if s == nil then s = '' end
   lua_thread.create(function()
      while act do wait(0) end
      if num == n then num = num - 1 if num <= 0 then num = 1 end end
      n, act = num, true
      for w in string.gmatch(texts[num],"[^,]+") do
         s = s..w
         i.v = u8(s)
         wait(300)
      end
      wait(600)
      s, act = '', false
   end)
end
не понял, типа эта штука выводит текст в инпут за тебя?
 

Vespan

loneliness
Проверенный
2,101
1,633
Описание: Когда инпут пустой то выводит в инпуте какой-то текст по одной букве( как тут )
Спасибо самому лучшему человеку @VRush за идею!!!💝
Lua:
function gotext(w,text,textinput,i)
    if GOTEXT == nil then GOTEXT = {} end
    if GOTEXT[textinput] == nil then GOTEXT[textinput] = {
        text = '',
        n = 0,
        edit = false,
        hovered = false,
        clock = os.clock()
    } end
    local p = GOTEXT[textinput]
    p.hovered = false
    imgui.InputText(textinput,i)
    if imgui.IsItemHovered() then p.hovered = true;    p.n = 0;    if p.text ~= '' then p.text = '';    i.v = '';    end end
    if p.text == '' and i.v ~= '' then p.edit = true end
    if p.text == '' and i.v == '' then p.edit = false end
    if not p.hovered and not p.edit then
        local DL = imgui.GetWindowDrawList()
        local pp = imgui.GetCursorScreenPos()
        DL:AddText(imgui.ImVec2(pp.x+1,pp.y-20),-1--[[ЦВЕТ]],u8(p.text))
        lua_thread.create(function()
            while (true) do wait(0)
                if p.hovered or p.edit then break end
                if os.clock()-p.clock > w--[[раз в одну секунду добавляем букву]] then
                    if not text:sub(p.n,p.n):find'%s+' then
                        p.clock = os.clock()
                    end
                    p.n = p.n + 1
                    p.text = p.text .. u8:decode(text):sub(p.n,p.n)
                    -- i.v = p.text
                end
                if #text == p.n then
                    break
                end
             end
        end)

    end
end


Lua:
input = imgui.ImBuffer('',256)
--
-- imgui >
gotext(0.5,u8'Я хочу питсы..','test2',input)
 

SADFI2259X

Участник
92
76
code:
function imgui.CustomButton(text, size)
    local op = imgui.GetCursorPos()
    
    imgui.PushStyleColor(imgui.Col.Border, imgui.ImVec4(0.00, 0.00, 0.00, 0.00))
    local result = imgui.Button(text, size)
    if imgui.IsItemHovered() then
        imgui.PushStyleColor(imgui.Col.Border, imgui.ImVec4(0.89, 0.85, 0.92, 1.00))
            imgui.SetCursorPosY(op.y)
            imgui.Button(text, size)
        imgui.PopStyleColor()
    end
    
    imgui.PopStyleColor()
    
    return result
end

function imgui.ToggleButton(str_id, bool, label)
    local rBool = false

    if LastActiveTime == nil then
        LastActiveTime = {}
    end
    if LastActive == nil then
        LastActive = {}
    end

    local function ImSaturate(f)
        return f < 0.0 and 0.0 or (f > 1.0 and 1.0 or f)
    end
    
    local p = imgui.GetCursorScreenPos()
    local draw_list = imgui.GetWindowDrawList()

    local height = 20--imgui.GetTextLineHeightWithSpacing()
    local width = 44--1.55
    local radius = 5*2--height * 0.50
    local rounding = 10.0
    local ANIM_SPEED = 0.15

    if imgui.InvisibleButton(str_id, imgui.ImVec2(width, height)) then
        bool.v = not bool.v
        rBool = true
        LastActiveTime[tostring(str_id)] = os.clock()
        LastActive[tostring(str_id)] = true
    end

    local t = bool.v and 1.0 or 0.0

    if LastActive[tostring(str_id)] then
        local time = os.clock() - LastActiveTime[tostring(str_id)]
        if time <= ANIM_SPEED then
            local t_anim = ImSaturate(time / ANIM_SPEED)
            t = bool.v and t_anim or 1.0 - t_anim
        else
            LastActive[tostring(str_id)] = false
        end
    end

    local col_bg
    local cir_bg
    if bool.v then
        col_bg = imgui.ImColor(204, 204, 204, 255):GetU32()
        cir_bg = imgui.ImColor(100, 100, 100, 255):GetU32()
    else
        col_bg = imgui.ImColor(100, 100, 100, 255):GetU32()
        cir_bg = imgui.ImColor(204, 204, 204, 255):GetU32()
    end
    if bool.v then
        draw_list:AddRectFilled(imgui.ImVec2(p.x, p.y), imgui.ImVec2(p.x + width, p.y + (height)), col_bg, rounding)
    else
        draw_list:AddRectFilled(imgui.ImVec2(p.x, p.y), imgui.ImVec2(p.x + width, p.y + (height)), cir_bg, rounding) --out lines
        draw_list:AddRectFilled(imgui.ImVec2(p.x + 2, p.y + 2), imgui.ImVec2((p.x + width) - 2, (p.y + height) - 2), col_bg, rounding)
    end
    
    draw_list:AddCircleFilled(imgui.ImVec2(p.x + radius + t * (width - radius * 2.0), p.y + radius), radius - ((height - radius)/2), imgui.GetColorU32(bool.v and cir_bg or cir_bg))
    
    if label then
        imgui.SameLine()
        imgui.PushStyleVar(imgui.StyleVar.ItemSpacing, imgui.ImVec2(0.0, 3.0))
        imgui.BeginGroup()
            imgui.Spacing()
            if bool.v then
                imgui.Text('On')
            else
                imgui.Text('Off')
            end
            imgui.Spacing()
        imgui.EndGroup()
        imgui.PopStyleVar()
    end
    
    return rBool
end

sa-mp-071 - Copy.png
 

Vespan

loneliness
Проверенный
2,101
1,633
Соортировка текста по алфавиту(ru/en)
(да выглядит хуйня..)
Lua:
function sortTable(t)
local function stringToLower(s)--lower() ru
    for i = 192, 223 do;    s = s:gsub(_G.string.char(i), _G.string.char(i + 32));  end
    s = s:gsub(_G.string.char(168), _G.string.char(184))
    return s:lower()
end
    local alf = {
        --ru
        ['а'] = 1,['б'] = 2,['в'] = 3,['г'] = 4,['д'] = 5,['е'] = 6,['ё'] = 7,['ж'] = 8,['з'] = 9,['и'] = 10,
        ['й'] = 11,['к'] = 12,['л'] = 13,['м'] = 14,['н'] = 15,['о'] = 16,['п'] = 17,['р'] = 18,['с'] = 19,
        ['т'] = 20,['у'] = 21,['ф'] = 22,['х'] = 20,['ц'] = 21,['ш'] = 22,['щ'] = 23,['ъ'] = 24,['ы'] = 25,
        ['ь'] = 26,['э'] = 27,['ю'] = 28,['я'] = 29,
        --en
        ['a'] = 1,['b'] = 2,['c'] = 3,['d'] = 4,['e'] = 5,['f'] = 6,['g'] = 7,['h'] = 8,['i'] = 9,['i'] = 10,
        ['j'] = 11,['k'] = 12,['l'] = 13,['m'] = 14,['n'] = 15,['о'] = 16,['p'] = 17,['q'] = 18,['r'] = 19,
        ['s'] = 20,['t'] = 21,['u'] = 22,['v'] = 20,['w'] = 21,['x'] = 22,['y'] = 23,['z'] = 24,
    }
    local b = {}
    local d  = {}
    for k,v in ipairs(t) do;    table.insert(b,{i=alf[stringToLower(string.sub(v,1,1))],vv=v}); end
    table.sort(b, function(a, b) return a['i'] < b['i'] end)
    for k,v in ipairs(b) do table.insert(d,v.vv) end
    return d
end
Lua:
    local g = {
        'лол',
        'абв',
        'ъаа',
        'КАВО',
        'ABC',
        'ghfg'
    }
    for k,v in ipairs(sortTable(g)) do
        print(v)
    end
--[[
абв
ABC
ghfg
КАВО
лол
ъаа]]
 

Musaigen

abobusnik
Проверенный
1,583
1,302
Соортировка текста по алфавиту(ru/en)
(да выглядит хуйня..)
Lua:
function sortTable(t)
local function stringToLower(s)--lower() ru
    for i = 192, 223 do;    s = s:gsub(_G.string.char(i), _G.string.char(i + 32));  end
    s = s:gsub(_G.string.char(168), _G.string.char(184))
    return s:lower()
end
    local alf = {
        --ru
        ['а'] = 1,['б'] = 2,['в'] = 3,['г'] = 4,['д'] = 5,['е'] = 6,['ё'] = 7,['ж'] = 8,['з'] = 9,['и'] = 10,
        ['й'] = 11,['к'] = 12,['л'] = 13,['м'] = 14,['н'] = 15,['о'] = 16,['п'] = 17,['р'] = 18,['с'] = 19,
        ['т'] = 20,['у'] = 21,['ф'] = 22,['х'] = 20,['ц'] = 21,['ш'] = 22,['щ'] = 23,['ъ'] = 24,['ы'] = 25,
        ['ь'] = 26,['э'] = 27,['ю'] = 28,['я'] = 29,
        --en
        ['a'] = 1,['b'] = 2,['c'] = 3,['d'] = 4,['e'] = 5,['f'] = 6,['g'] = 7,['h'] = 8,['i'] = 9,['i'] = 10,
        ['j'] = 11,['k'] = 12,['l'] = 13,['m'] = 14,['n'] = 15,['о'] = 16,['p'] = 17,['q'] = 18,['r'] = 19,
        ['s'] = 20,['t'] = 21,['u'] = 22,['v'] = 20,['w'] = 21,['x'] = 22,['y'] = 23,['z'] = 24,
    }
    local b = {}
    local d  = {}
    for k,v in ipairs(t) do;    table.insert(b,{i=alf[stringToLower(string.sub(v,1,1))],vv=v}); end
    table.sort(b, function(a, b) return a['i'] < b['i'] end)
    for k,v in ipairs(b) do table.insert(d,v.vv) end
    return d
end
Lua:
    local g = {
        'лол',
        'абв',
        'ъаа',
        'КАВО',
        'ABC',
        'ghfg'
    }
    for k,v in ipairs(sortTable(g)) do
        print(v)
    end
--[[
абв
ABC
ghfg
КАВО
лол
ъаа]]
Зачем это нужно если table.sort и так может сортировать строки в таблицах из коробки?
 

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Описание: добавляет текст в RecallBuffer ( Типо штука когда нажимаете стрелочки вверх/вниз и она показывает сообщения которые вы вводили )
( Требует ffi, memory )

Код:
Lua:
function AddRecall(str)
    local pInput = memory.getuint32(getModuleHandle("samp.dll") + 0x21A0E8, true) -- for R3: 0x26E8CC
    ffi.cast('void(__thiscall*)(void*, const char*)', getModuleHandle("samp.dll") + 0x65930)(ffi.cast('void*', pInput), str) -- for R3: 0x68E60
end

Пример использования:
1668372034446.png
 

Savchik Blazer

Но я, мечту свою лелея...
Проверенный
671
293
Описание: добавляет текст в RecallBuffer ( Типо штука когда нажимаете стрелочки вверх/вниз и она показывает сообщения которые вы вводили )
( Требует ffi, memory )

Код:
Lua:
function AddRecall(str)
    local pInput = memory.getuint32(getModuleHandle("samp.dll") + 0x21A0E8, true) -- for R3: 0x26E8CC
    ffi.cast('void(__thiscall*)(void*, const char*)', getModuleHandle("samp.dll") + 0x65930)(ffi.cast('void*', pInput), str) -- for R3: 0x68E60
end

Пример использования:
Посмотреть вложение 177579
Про R2 и R4 опять забыли
Код:
[pInput]
R2-> 0x21A0F0
R4-> 0x26E9FC
[addrecall]
R2-> 0x65A00
R4-> 0x69590
 
  • Нравится
Реакции: ARMOR

ARMOR

kjor32 is legend
Модератор
4,851
6,081
Описание: добавляет текст в RecallBuffer ( Типо штука когда нажимаете стрелочки вверх/вниз и она показывает сообщения которые вы вводили )
( Требует ffi, memory )

Код:
Lua:
function AddRecall(str)
    local pInput = memory.getuint32(getModuleHandle("samp.dll") + 0x21A0E8, true) -- for R3: 0x26E8CC
    ffi.cast('void(__thiscall*)(void*, const char*)', getModuleHandle("samp.dll") + 0x65930)(ffi.cast('void*', pInput), str) -- for R3: 0x68E60
end

Пример использования:
Посмотреть вложение 177579
Функция делает почти то же самое что и функция выше, но эта записывает значение напрямую в структуру CInput, и позволяет указать позицию в буффере.

Код:
Lua:
--[[
   Адреса для всех версий SAMP:
   R1: 0x21A0E8
   R2: 0x21A0F0
   R3: 0x26E8CC
   R4: 0x26E9FC
   DL: 0x2ACA14
]]

function AddRecall(value, possition)
    if possition > 0 and possition < 11 then
        local pInput = memory.getuint32(getModuleHandle("samp.dll") + 0x21A0E8, true)
        local m_szRecallBufffer = pInput + 0x14E4
        local str = value..("\x00"):rep(129-#value)
        memory.copy(m_szRecallBufffer + possition * 129, memory.strptr(str), #str, true)
    end
end

Пример использования:
Lua:
AddRecall("Строка", 3) -- Установит строку в 3 слот массива, ТОЛЬКО если 3 строка была уже инициализирована, т.е в 3 ячейку массива ранее уже было записано значение.
 
Последнее редактирование:
  • Нравится
Реакции: why ega и lorgon