Lua Character Counter ¡UPDATED!

ollydbg

Известный
Автор темы
163
113
Версия SA-MP
  1. 0.3.7 (R1)
Description: the script displays a text on the screen of the number of characters typed in the chat input

Config: /ctc

Requeriments:
moonloader, sampfuncs, imgui



14/05/2021 / version 1​

- Release

15/05/2021 / version 2​

-You can now add a background to the number of characters.
-Added adjust position and size of background
-Some fixes and improvements
Attention 2 different versions have been published, watch the video to understand.
it is possible that the other one will also be updated at a later
 

Вложения

  • character_counter.zip
    3.4 KB · Просмотры: 40
  • character_counter_V2.zip
    4.1 KB · Просмотры: 62
  • character_counter_A.zip
    3.4 KB · Просмотры: 41
Последнее редактирование:

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,763
11,198
1. why do you use "change position" button if you can get chat input position?
1621025818874.png

Lua:
local in1 = sampGetInputInfoPtr()
local in1 = getStructElement(in1, 0x8, 4)
local in2 = getStructElement(in1, 0x8, 4) -- posX
local in3 = getStructElement(in1, 0xC, 4) -- posY
renderFontDrawText(ctfont, vtext..' '..#text..'/128', in2 + 800, in3 + 13, cfg.Settings.color)

2. i think this is better :D
1621026940685.png

Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local window = imgui.ImBool(false)

local posList = {
    {0, 45}, --chat bottom
    {800, 5}, --left
}
local pos = 2

function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    window.v = true  --show window
    sampRegisterChatCommand('chlen', function(posid) --блять тут не член, а Ch Len
        pos = tonumber(posid)
    end)
    while true do
        wait(0)
        imgui.Process = window.v
        if sampIsChatInputActive() then window.v = true else window.v = false end
    end
end

function imgui.OnDrawFrame()
    if window.v then
        local in1 = sampGetInputInfoPtr()
        local in1 = getStructElement(in1, 0x8, 4)
        local in2 = getStructElement(in1, 0x8, 4) -- posX
        local in3 = getStructElement(in1, 0xC, 4) -- posY

        imgui.SetNextWindowPos(imgui.ImVec2(in2 + posList[pos][1], in3 + posList[pos][2]), imgui.Cond.Always)
        imgui.SetNextWindowSize(imgui.ImVec2(55.0, 25.0), imgui.Cond.FirstUseEver)
        imgui.Begin('hidden title', window, imgui.WindowFlags.NoMove + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar)
        imgui.CenterTextColoredRGB(string.len(sampGetChatInputText())..'/128')

        imgui.End()
    end
end

function imgui.CenterTextColoredRGB(text)
    local width = imgui.GetWindowWidth()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end

    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local textsize = w:gsub('{.-}', '')
            local text_width = imgui.CalcTextSize(u8(textsize))
            imgui.SetCursorPosX( width / 2 - text_width .x / 2 )
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else
                imgui.Text(u8(w))
            end
        end
    end
    render_text(text)
end
1621027246407.png

1621027232642.png
 
Последнее редактирование:

copypaste_scripter

Известный
1,218
223
Description: the script displays a text on the screen of the number of characters typed in the chat input
Config: /ctc
Requeriments: moonloader, sampfuncs, imgui
I do not speak Russian, but I think that the text entered in the menu will work well if it is written in Russian, if it is not you can edit the code:)

Описание: скрипт отображает количество сомволов введенных в поле ввода
активация /ctc
требования moonloader, sampfuncs, imgui
я не говорю по русский, но думал, что текст введенный на русском тоже будет работать. если не будет - вы сами можете поменять код
 

ollydbg

Известный
Автор темы
163
113
1. why do you use "change position" button if you can get chat input position?
Посмотреть вложение 97148
Lua:
local in1 = sampGetInputInfoPtr()
local in1 = getStructElement(in1, 0x8, 4)
local in2 = getStructElement(in1, 0x8, 4) -- posX
local in3 = getStructElement(in1, 0xC, 4) -- posY
renderFontDrawText(ctfont, vtext..' '..#text..'/128', in2 + 800, in3 + 13, cfg.Settings.color)

2. i think this is better :D
Посмотреть вложение 97152
Lua:
local imgui = require('imgui')
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local window = imgui.ImBool(false)

local posList = {
    {0, 45}, --chat bottom
    {800, 5}, --left
}
local pos = 2

function main()
    while not isSampAvailable() do wait(200) end
    imgui.Process = false
    window.v = true  --show window
    sampRegisterChatCommand('chlen', function(posid) --блять тут не член, а Ch Len
        pos = tonumber(posid)
    end)
    while true do
        wait(0)
        imgui.Process = window.v
        if sampIsChatInputActive() then window.v = true else window.v = false end
    end
end

function imgui.OnDrawFrame()
    if window.v then
        local in1 = sampGetInputInfoPtr()
        local in1 = getStructElement(in1, 0x8, 4)
        local in2 = getStructElement(in1, 0x8, 4) -- posX
        local in3 = getStructElement(in1, 0xC, 4) -- posY

        imgui.SetNextWindowPos(imgui.ImVec2(in2 + posList[pos][1], in3 + posList[pos][2]), imgui.Cond.Always)
        imgui.SetNextWindowSize(imgui.ImVec2(55.0, 25.0), imgui.Cond.FirstUseEver)
        imgui.Begin('hidden title', window, imgui.WindowFlags.NoMove + imgui.WindowFlags.NoResize + imgui.WindowFlags.NoTitleBar)
        imgui.CenterTextColoredRGB(string.len(sampGetChatInputText())..'/128')

        imgui.End()
    end
end

function imgui.CenterTextColoredRGB(text)
    local width = imgui.GetWindowWidth()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    local explode_argb = function(argb)
        local a = bit.band(bit.rshift(argb, 24), 0xFF)
        local r = bit.band(bit.rshift(argb, 16), 0xFF)
        local g = bit.band(bit.rshift(argb, 8), 0xFF)
        local b = bit.band(argb, 0xFF)
        return a, r, g, b
    end

    local getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) == 'string' and tonumber(color, 16) or color
        if type(color) ~= 'number' then return end
        local r, g, b, a = explode_argb(color)
        return imgui.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local textsize = w:gsub('{.-}', '')
            local text_width = imgui.CalcTextSize(u8(textsize))
            imgui.SetCursorPosX( width / 2 - text_width .x / 2 )
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], u8(text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else
                imgui.Text(u8(w))
            end
        end
    end
    render_text(text)
end
Посмотреть вложение 97156
Посмотреть вложение 97155
well, I'll update it later and correct some things I forgot how to wait. 0AFA:
thanks
 

hnnssy

Известный
Друг
2,684
2,746
Description: the script displays a text on the screen of the number of characters typed in the chat input
Config: /ctc
Requeriments: moonloader, sampfuncs, imgui
I do not speak Russian, but I think that the text entered in the menu will work well if it is written in Russian, if it is not you can edit the code:)

Описание: скрипт отображает количество сомволов введенных в поле ввода
активация /ctc
требования moonloader, sampfuncs, imgui
я не говорю по русский, но думал, что текст введенный на русском тоже будет работать. если не будет - вы сами можете поменять код
что бы мы без тебя делали, спасибо за вклад!
 

copypaste_scripter

Известный
1,218
223
how to make 0/128 text to turn into just 0 ? i dont need excess /128
как сделать чтобы убрать /128? чет не понял в коде где убрать надо