- 63
- 4
как сделать ебучий калькулятор, я его давно делал, но чет сделал, потом забил, и щас незнаю в чём проблема
если надо вот код
или скиньте чистый обычный калькулятор, не тот которые в лаунчере аризоны и так далее
если надо вот код
Lua:
local ok = false
local result = ""
local number = 0
local help = false
function processChatCalculator()
if not vars1.chatcalc[0] then return end
local text = sampGetChatInputText()
if not text or text == "" then
ok = false
return
end
if text:find('%d[%d%.]*[%-%+%/%%%*%^]') and not text:find('%a') then
local func, err = loadstring('return '..text)
if func then
ok, number = pcall(func)
if ok then
result = 'Результат: '..tostring(number)
if not isKeyDown(0x08) then
setClipboardText(tostring(number))
end
end
end
end
help = (text == "calc")
end
function drawCalculatorWindows()
if not vars1.chatcalc[0] then return end
local input = sampGetInputInfoPtr()
if not input then return end
input = getStructElement(input, 0x8, 4)
local windowPosX = getStructElement(input, 0x8, 4) or 100
local windowPosY = getStructElement(input, 0xC, 4) or 100
if sampIsChatInputActive() and ok then
local text = u8(number_separator(result))
local text_size = imgui.CalcTextSize(text)
imgui.SetNextWindowPos(imgui.ImVec2(windowPosX, windowPosY + 45))
imgui.SetNextWindowSize(imgui.ImVec2(text_size.x + 40, 30))
imgui.Begin('CalcResult', nil,
imgui.WindowFlags.NoTitleBar +
imgui.WindowFlags.NoResize +
imgui.WindowFlags.NoMove +
imgui.WindowFlags.NoScrollbar
)
imgui.Text(text)
imgui.End()
end
if sampIsChatInputActive() and help then
imgui.SetNextWindowPos(imgui.ImVec2(windowPosX, windowPosY + 80))
imgui.SetNextWindowSize(imgui.ImVec2(300, 120))
imgui.Begin('CalcHelp', nil,
imgui.WindowFlags.NoTitleBar +
imgui.WindowFlags.NoResize +
imgui.WindowFlags.NoMove +
imgui.WindowFlags.NoScrollbar
)
imgui.TextWrapped(u8"Примеры:\n10+20*5\n25%*200\n100/50%\ncalc - справка")
imgui.End()
end
end
while true do
wait(0)
processBinders()
processChatCalculator()
if vars1.chatcalc[0] then
local text = sampGetChatInputText()
ok = false
if text ~= '' and not text:find('%a') then
if text:find('%d[%d%.]*[%-%+%/%%%*%^]') then
local func, err = loadstring('return '..text)
if func then
ok, number = pcall(func)
if ok then
result = 'Результат: '..tostring(number)
if not isKeyDown(0x08) then
setClipboardText(tostring(number))
end
end
end
end
if text:find('^%d+%%%*%d+$') then
local number1, number2 = text:match('(%d+)%%%*(%d+)')
number = tonumber(number1) * tonumber(number2) / 100
result = 'Результат: '..tostring(number)
ok = true
if not isKeyDown(0x08) then
setClipboardText(tostring(number))
end
end
if text:find('^%d+%%%/%d+$') then
local number1, number2 = text:match('(%d+)%%%/(%d+)')
number = tonumber(number2) / tonumber(number1) * 100
result = 'Результат: '..tostring(number)
ok = true
if not isKeyDown(0x08) then
setClipboardText(tostring(number))
end
end
if text:find('^%d+/%d+%%$') then
local number1, number2 = text:match('(%d+)/(%d+)%%')
number = tonumber(number1) * 100 / tonumber(number2)
result = 'Результат: '..string.format('%.2f%%', number)
ok = true
if not isKeyDown(0x08) then
setClipboardText(string.format('%.2f%%', number))
end
end
end
if text == 'calc' then
help = true
else
help = false
end
if text == '' then
ok = false
end
end
или скиньте чистый обычный калькулятор, не тот которые в лаунчере аризоны и так далее