-
Автор темы
- #1
Всем привет!!! Помогите, я хочу сделать чтобы кнопка привязывалась к действию. Например по нажатию кнопки что то происходило
Вот сама луа
апи кнопки в конце
Вот сама луа
апи кнопки в конце
Код:
ffi.cdef[[
short GetAsyncKeyState(int vKey);
unsigned short GetAsyncKeyState(int vKey);
]]
local function is_key_pressed(virtualKey)
return bit.band(ffi.C.GetAsyncKeyState(virtualKey), 32768) == 32768
end
local function is_key_clicked(key)
if ffi.C.GetAsyncKeyState(key) == -32767 then
return true
end
end
require "common"
local Font = {
TahomaBold = renderer.setup_font("C:/windows/fonts/tahomabd.ttf", 50, 0),
Calibri = renderer.setup_font("C:/windows/fonts/calibri.ttf", 50, 0),
Verdana = renderer.setup_font("C:/windows/fonts/verdana.ttf", 50, 0)
}
local Parameters = {
Pos = vec2_t.new(700, 100),
LineHeight = 18.5,
LuaName = "stoyack.lua",
Base = {
Indent = 10,
Tabs = {
Width = 120,
Height = 40,
Names = {
"legitbot",
"ragebot",
"antihit",
"visuals",
"misc"
}
},
Color = {
Accent = color_t.new(253, 105, 2, 255),
Main = color_t.new(25, 25, 25, 255),
Stroke = color_t.new(60, 60, 60, 255),
Name = color_t.new(255, 255, 255, 255),
Text = color_t.new(255, 255, 255, 255),
SubText = color_t.new(255, 255, 255, 150),
Active = color_t.new(100, 100, 100, 255),
InActive = color_t.new(60, 60, 60, 255),
Prompt = color_t.new(90, 90, 90, 255)
},
Font = {
LuaName = Font.Calibri,
TabText = Font.Calibri,
Text = Font.Verdana
}
},
Info = {}
}
Parameters.Base.Height = (#Parameters.Base.Tabs.Names + 3) * Parameters.Base.Indent + #Parameters.Base.Tabs.Names * Parameters.Base.Tabs.Height
Parameters.Base.Width = 8 * Parameters.Base.Indent + Parameters.Base.Tabs.Width + 2 * 170
local KeyClicked, KeyPressed, change = {}, {}, {}
local h, s, v, set, edit
local Keys = {
[4] = "M3",
[5] = "M4",
[6] = "M5",
[8] = "back",
[20] = "caps",
[32] = "spc",
[33] = "pgup",
[34] = "pgdn",
[36] = "home",
[37] = "left",
[38] = "up",
[39] = "right",
[40] = "down",
[48] = "0",
[49] = "1",
[50] = "2",
[51] = "3",
[52] = "4",
[53] = "5",
[54] = "6",
[55] = "7",
[56] = "8",
[57] = "9",
[65] = "A",
[66] = "B",
[67] = "C",
[68] = "D",
[69] = "E",
[70] = "F",
[71] = "G",
[72] = "H",
[73] = "I",
[74] = "J",
[75] = "K",
[76] = "L",
[77] = "M",
[78] = "N",
[79] = "O",
[80] = "P",
[81] = "Q",
[82] = "R",
[83] = "S",
[84] = "T",
[85] = "U",
[86] = "V",
[87] = "W",
[88] = "X",
[89] = "Y",
[90] = "Z",
[96] = "nm0",
[97] = "nm1",
[98] = "nm2",
[99] = "nm3",
[100] = "nm4",
[101] = "nm5",
[102] = "nm6",
[103] = "nm7",
[104] = "nm8",
[105] = "nm9",
[106] = "*",
[107] = "nm+",
[109] = "nm-",
[110] = ".",
[111] = "/",
[112] = "f1",
[113] = "f2",
[114] = "f3",
[115] = "f4",
[116] = "f5",
[117] = "f6",
[118] = "f7",
[119] = "f8",
[120] = "f9",
[121] = "f10",
[122] = "f11",
[123] = "f12",
[160] = "shift",
[161] = "shift",
[162] = "ctrl",
[163] = "ctrl",
[164] = "alt",
[165] = "alt"
}
local KeybindTypes = {
"(Always on)",
"(Hold)",
"(Toggle)",
"(Unhold)"
}
local ActiveTab = 1
local function AddCheckBox(Name, Condition, Type, PosX, PosY)
k = k + 1
local info = Parameters.Info[k] or {"checkbox", Name, Condition, {x = PosX, y = PosY}, Type, false, {nil, 2}, color_t.new(255, 255, 255, 255)}
info[3] = Condition
local active = info[6]
local key = info[7][1]
if Type == 1 and key then
local type = info[7][2]
if type == 1 then
active = true
elseif type == 2 then
active = KeyPressed[key][1]
elseif type == 3 then
if KeyClicked[key][1] then active = not active end
else
active = not KeyPressed[key][1]
end
end
info[6] = active
Parameters.Info[k] = info
return active, info[8]
end
local function AddSlider(Name, Condition, PosX, PosY, MinValue, MaxValue, Accuracy)
k = k + 1
local info = Parameters.Info[k] or {"slider", Name, Condition, {x = PosX, y = PosY}, MinValue, MinValue, MaxValue, Accuracy}
info[3] = Condition
Parameters.Info[k] = info
return info[5]
end
local function AddComboBox(Name, Condition, Values, PosX, PosY)
k = k + 1
local info = Parameters.Info[k] or {"combo", Name, Condition, {x = PosX, y = PosY}, 0, Values}
info[3] = Condition
info[6][0] = "None"
Parameters.Info[k] = info
return info[5]
end
local h, s, v, a
local function Draw()
local Mouse = renderer.get_cursor_pos()
local M1Clicked = is_key_clicked(1)
local M1Pressed = is_key_pressed(1)
local M2Clicked = is_key_clicked(2)
local param = Parameters
local startpos = param.Pos
local line = param.LineHeight
local luaname = param.LuaName
local info = param.Info
local param = param.Base
local width = param.Width
local height = param.Height
local color = param.Color
local fonts = param.Font
local indent = param.Indent
local minrect = MouseIntoRect
local Rect = DrawRect
if M1Clicked and minrect(startpos.x, startpos.y - 3, width, line + 3) then
change = {"startpos", 0}
dx, dy = Mouse.x - startpos.x, Mouse.y - startpos.y
end
if change[1] == "startpos" then
if not M1Pressed then change = {} end
startpos.x, startpos.y = Mouse.x - dx, Mouse.y - dy
end
Rect(startpos.x, startpos.y, width, line, color.Main, true)
Rect(startpos.x, startpos.y, width, -3, color.Accent, true)
local textsize = 17
local font = fonts.LuaName
local size = renderer.get_text_size(font, textsize, luaname)
renderer.text(luaname, font, vec2_t.new(startpos.x + (width - size.x)/2, startpos.y + (line - size.y)/2), textsize, color.Text)
local pos = {x = startpos.x, y = startpos.y + 25}
Rect(pos.x, pos.y, width, height, color.Main, true)
pos.x, pos.y = pos.x + indent, pos.y + indent
local tabs = param.Tabs
Rect(pos.x, pos.y, tabs.Width + 2 * indent, height - 2 * indent, color.Stroke)
pos.x, pos.y = pos.x + indent, pos.y - tabs.Height
local font = fonts.TabText
for key, value in pairs(tabs.Names) do
pos.y = pos.y + tabs.Height + indent
local prompt
if minrect(pos.x, pos.y, tabs.Width, tabs.Height) then prompt = true end
if prompt and M1Clicked then ActiveTab = key end
Rect(pos.x, pos.y, tabs.Width, tabs.Height, ActiveTab == key and color.Name or prompt and color.Prompt or color.Stroke)
local size = renderer.get_text_size(font, textsize, value)
renderer.text(value, font, vec2_t.new(pos.x + (tabs.Width - size.x)/2, pos.y + (tabs.Height - size.y)/2), textsize, color.Text)
end
pos.x, pos.y = pos.x + tabs.Width + 2 * indent, startpos.y + 25 + indent
local width = 370
local height = height - 2 * indent
Rect(pos.x, pos.y, width, height, color.Stroke)
pos.x, pos.y = pos.x + indent, pos.y + indent
local font = fonts.Text
local stroke = color.Stroke
local width = 170
for key, value in pairs(info) do
local condition = value[3]
if not value[3] then goto continue end
local textsize = 16
local type = value[1]
local name = value[2]
local pos = vec2_t.new(pos.x + (170 + indent) * value[4].x, pos.y + value[4].y * (indent + line))
if type == "checkbox" then --{"checkbox", Name, Condition, Type, {x = PosX, y = PosY}, false, {nil, 2}, color}
local cbtype = value[5]
local active = value[6]
local width = 170
local prompt = minrect(pos.x, pos.y, width, line)
local namesize = renderer.get_text_size(font, textsize, name)
renderer.text(name, font, vec2_t.new(pos.x + line + 4, pos.y + 2), textsize, color.Text)
if minrect(pos.x, pos.y, line + namesize.x, line) and value[7][1] == nil and M1Clicked then
active = not active
end
Rect(pos.x,pos.y,line,line, minrect(pos.x, pos.y, line, line) and color.Prompt or color.Stroke,active)
Parameters.Info[key][6] = active
if cbtype == 1 then
local bindkey, bindtype = value[7][1], value[7][2]
local text = change[2] == key and "..." or bindkey and Keys[bindkey] or ""
local text = "[".. text .. "]"
local size = renderer.get_text_size(font, textsize, text)
pos.x = pos.x + width - size.x
if not (prompt or change[2] == key) or (change[2] ~= nil and change[2] ~= key) then goto continue end
if M1Clicked and minrect(pos.x, pos.y, size.x, line) then
change = {"bindkey", key}
end
if change[2] == key then
if is_key_clicked(27) then
change = {}
Parameters.Info[key][7][1] = nil
goto continue1
end
for key1, value in pairs(KeyClicked) do
if value[1] then
Parameters.Info[key][7][1] = key1
change = {}
break
end
end
::continue1::
end
renderer.text(text, font, pos, textsize, color.Text)
local text = KeybindTypes[bindtype]
local textsize = 13
local size = renderer.get_text_size(font, textsize, text)
pos.x = pos.x - size.x - 4
pos.y = pos.y + 3
if M2Clicked and minrect(pos.x, pos.y, size.x, line) then
Parameters.Info[key][7][2] = bindtype < 4 and bindtype + 1 or 1
end
renderer.text(text, font, pos, textsize, color.SubText)
elseif cbtype == 2 and prompt or change[2] == key then
local color = value[8]
pos.x = pos.x + width - line
if M1Clicked and minrect(pos.x, pos.y, line, line) then
change = {"colorpicker", key}
end
Rect(pos.x, pos.y, line, line, color, true)
Rect(pos.x, pos.y, line, line, stroke)
end
elseif type == "slider" then --{"slider", Name, Condition, {x = PosX, y = PosY}, Value, MinValue, MaxValue, Accuracy}
local slvalue = value[5]
local slmin = value[6]
local slmax = value[7]
local accuracy = value[8]
if M1Clicked then
if minrect(pos.x,pos.y,line,line) then
slvalue = slvalue - 10 ^ (-accuracy)
slvalue = slvalue < slmin and slmin or slvalue
Parameters.Info[key][5] = slvalue
elseif minrect(pos.x + 170 - line, pos.y, line, line) then
slvalue = slvalue + 10 ^ (-accuracy)
slvalue = slvalue > slmax and slmax or slvalue
Parameters.Info[key][5] = slvalue
elseif minrect(pos.x, pos.y, width, line) then
change = {"slider", key}
end
end
if change[2] == key then
change = M1Pressed and change or {}
slvalue = (Mouse.x - pos.x)/170 * (slmax - slmin)
slvalue = slvalue > slmax and slmax or slvalue < slmin and slmin or slvalue
slvalue = math.floor(slvalue * 10 ^ accuracy + 0.5) / 10 ^ accuracy
Parameters.Info[key][5] = slvalue
end
local colors = minrect(pos.x, pos.y, width, line) and color.Prompt or stroke
Rect(pos.x, pos.y, width, line, colors)
Rect(pos.x, pos.y, width * (slvalue - slmin)/(slmax - slmin), line, colors, 1)
local text = name .. " " .. tostring(slvalue)
local size = renderer.get_text_size(font, textsize, text)
renderer.text(text, font, vec2_t.new(pos.x + (width - size.x)/2, pos.y + (line - size.y)/2), textsize, color.Text)
elseif type == "combo" then
local prompt = minrect(pos.x, pos.y, width, line) or change[2] == key
local colors = prompt and color.Prompt or stroke
Rect(pos.x, pos.y, width, line, colors)
if M1Clicked and prompt then
change = {"combo", key}
end
local text = Parameters.Info[key][6][Parameters.Info[key][5]]
local size = renderer.get_text_size(font, textsize, text)
renderer.text(text, font, vec2_t.new(pos.x + (width - size.x)/2, pos.y + (line - size.y)/2), textsize, color.Text)
if prompt or change[2] == key then
local posr = vec2_t.new(pos.x + width - line/2, pos.y + line/2)
renderer.circle(posr, 2, 0, true, color.Text)
end
end
::continue::
end
if change[1] == "colorpicker" then
local k = change[2]
local info = Parameters.Info[k]
local pos = vec2_t.new(pos.x + (170 + indent) * info[4].x, pos.y + (info[4].y + 1) * (indent + line))
local currentcolor = info[8]
local height = 120
local RectFade = renderer.rect_filled_fade
local size = height - 2 * indent
local r, g, b, a = ToRGBA(currentcolor)
if not set then h, s, v = RGBToHSV(r, g, b, a) set = true end
if M1Clicked and not minrect(pos.x, pos.y - (indent + line), width, height + (indent + line)) then
change = {}
set, edit = nil, nil
return
end
Rect(pos.x, pos.y, width, height, color.Main, true)
Rect(pos.x, pos.y, width, height, stroke)
local col_left, col_right = color_t.new(255, 255, 255, 255), color_t.new(HSVToRGB(h, 1, 1, 255))
local start_pos = vec2_t.new(pos.x + indent, pos.y + indent)
local end_pos = vec2_t.new(start_pos.x + size, start_pos.y + size)
RectFade(start_pos, end_pos, col_left, col_right, col_right, col_left)
local col_up, col_down = color_t.new(0, 0, 0, 0), color_t.new(0, 0, 0, 255)
RectFade(start_pos, end_pos, col_up, col_up, col_down, col_down)
Rect(start_pos.x, start_pos.y, size, size, stroke)
local crcl_pos = vec2_t.new(start_pos.x + size * s, end_pos.y - v * size)
local crcl_rad = 6
renderer.circle(crcl_pos, crcl_rad, 0, true, color_t.new(HSVToRGB(h, s, v, 255)))
renderer.circle(crcl_pos, crcl_rad, 0, false, stroke)
if M1Clicked and minrect(start_pos.x, start_pos.y, size, size) or edit == "sv" then
edit = "sv"
if not M1Pressed then edit = nil end
s = (Mouse.x - start_pos.x)/size
v = (end_pos.y - Mouse.y)/size
local min, max = 0, 1
if s > max then s = max elseif s < min then s = min end
if v > max then v = max elseif v < min then v = min end
end
local w = 15
start_pos.x = start_pos.x + 35 + size
end_pos.x = start_pos.x + w
local col_up, col_down = color_t.new(HSVToRGB(h, s, v, 255)), color_t.new(HSVToRGB(h, s, v, 0))
RectFade(start_pos, end_pos, col_up, col_up, col_down, col_down)
Rect(start_pos.x, start_pos.y, w, size, stroke)
if M1Clicked and minrect(start_pos.x, start_pos.y, w, size) or edit == "a" then
edit = "a"
if not M1Pressed then edit = nil end
a = (end_pos.y - Mouse.y)/size*255
local min, max = 0, 255
if a > max then a = max elseif a < min then a = min end
end
local tr_size = 3
local points = {
vec2_t.new(start_pos.x, end_pos.y - a/255*size - tr_size),
vec2_t.new(start_pos.x, end_pos.y - a/255*size + tr_size),
vec2_t.new(start_pos.x + tr_size, end_pos.y - a/255*size)
}
renderer.filled_polygon(points, color.Text)
local points = {
vec2_t.new(start_pos.x + w, end_pos.y - a/255*size - tr_size),
vec2_t.new(start_pos.x + w, end_pos.y - a/255*size + tr_size),
vec2_t.new(start_pos.x + w - tr_size, end_pos.y - a/255*size)
}
renderer.filled_polygon(points, color.Text)
end_pos.x = start_pos.x - 10
start_pos.x = end_pos.x - w
size = size/6
for i = 1, 6 do
local col_up, col_down = color_t.new(HSVToRGB(60 * i, 1, 1, 255)), color_t.new(HSVToRGB(60 * (i - 1), 1, 1, 255))
local pos = vec2_t.new(start_pos.x, start_pos.y + i * size)
RectFade(pos, vec2_t.new(pos.x + w, pos.y - size), col_up, col_up, col_down, col_down)
end
local size = 100
if M1Clicked and minrect(start_pos.x, start_pos.y, w, size) or edit == "h" then
edit = "h"
if not M1Pressed then edit = nil end
h = (Mouse.y - start_pos.y)/size*360
local min, max = 0, 360
if h > max then h = max elseif h < min then h = min end
end
Rect(start_pos.x, start_pos.y, w, size, stroke)
local points = {
vec2_t.new(start_pos.x, start_pos.y + h/360*size - tr_size),
vec2_t.new(start_pos.x, start_pos.y + h/360*size + tr_size),
vec2_t.new(start_pos.x + tr_size, start_pos.y + h/360*size)
}
renderer.filled_polygon(points, color.Text)
local points = {
vec2_t.new(start_pos.x + w, start_pos.y + h/360*size - tr_size),
vec2_t.new(start_pos.x + w, start_pos.y + h/360*size + tr_size),
vec2_t.new(start_pos.x + w - tr_size, start_pos.y + h/360*size)
}
renderer.filled_polygon(points, color.Text)
Parameters.Info[k][8] = color_t.new(HSVToRGB(h,s,v,a))
elseif change[1] == "combo" then
local k = change[2]
local info = Parameters.Info[k]
local pos = vec2_t.new(pos.x + (170 + indent) * info[4].x, pos.y + (info[4].y + 1) * (indent + line))
local active = Parameters.Info[k][5]
for key, value in pairs(Parameters.Info[k][6]) do
local prompt = minrect(pos.x, pos.y, width, line)
local colors = prompt and color.Prompt or color.Main
local textsize = 15
Rect(pos.x, pos.y, width, line, colors, true)
if prompt and M1Clicked then
change = {}
Parameters.Info[k][5] = key
end
local text = value
local size = renderer.get_text_size(font, textsize, text)
renderer.text(text, font, vec2_t.new(pos.x + (width - size.x)/2, pos.y + (line - size.y)/2), textsize, color.Text)
pos.y = pos.y + line
end
local h = line * (#Parameters.Info[k][6] + 1)
pos.y = pos.y - h
Rect(pos.x, pos.y, width, h, stroke)
if M1Clicked and not minrect(pos.x, pos.y - line * 1.5, width, h + line*2) then
change = {}
end
end
end
client.register_callback("paint", function()
k = 0
for key, value in pairs(Keys) do
KeyClicked[key] = {is_key_clicked(key), value}
KeyPressed[key] = {is_key_pressed(key), value}
end
--------------------------------------------------------------- Put your code here --------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
if ui.is_visible() then Draw() else change = {} end
end)
-------------------------------------------------------------------------------------------------------------------------------------------------
-- Functions return boolean value --
---------------------------------------------------------------------- API ----------------------------------------------------------------------
-- var = AddCheckBox(name:string, condtion_to_show:boolean, type:integer, row:integer, line:integer) --
-- type == 0 => default checkbox --
-- type == 1 => checkbox with keybind --
-- type == 2 => checkbox with color --
-- row == 0 or 1 --
-- --
-- var = AddSlider(name:string, condition_to_show:boolean, row:integer, line:integer, min_value:float, max_value:float, accuracy:integer) --
-- accuracy == 0 mean integer slider --
-- accuracy == 1 mean step = 0.1 --
-- accuracy == -1 mean step = 10 --
-- accuracy == 2 mean step = 0.2 --
-- var = AddComboBox(name:string, condition_to_show:boolean, combo_names:array of string, row:integer, line:integer) --
-- --
-- [[Examples:]] --
-- local cb2 = AddCheckBox("CBName1", ActiveTab == 1, 1, 1, 0) --
-- local cb3 = AddCheckBox("CBName2", ActiveTab == 1, 2, 0, 1) --
-- local sl = AddSlider("5l143r", ActiveTab == 1, 1, 1, 0, 120, 1) --
-- local combo = AddComboBox("Combo", ActiveTab == 1, {"xs", "s", "m", "l", "xl"}, 0, 2) ]] --
-- --
-------------------------------------------------------------------------------------------------------------------------------------------------