Изменить активацию скрипта с команды на кнопку

Kaktyc007

Известный
Автор темы
166
11
Версия MoonLoader
.026-beta
Добрый день, подскажите как изменить активацию скрипта с команды на кнопку. Код ниже. Спасибо.
Lua:
script_name("Shpora")
script_author("4el0ve4ik")
script_version("v1.1")
require "lib.moonloader"
local tweaks = require "lib.mgtweaks"

local resultat = false
local text = {}
function main()
  if not isSampLoaded() then return end
  if doesDirectoryExist("moonloader/config") then
    _ = createDirectory("moonloader/config")
  end
  local f = io.open("moonloader/config/shpora.txt","r+")
  if f == nil then
    f = io.open("moonloader/config/shpora.txt","w")
    f:close()
    f = io.open("moonloader/config/shpora.txt", "r+")
    f:write("\nТекст можно задать в {ff0000}'moonloader/config/shpora.txt'\nby 4el0ve4ik for {0000ff}BlastHack")
    f:flush()
  end
  f:close()
  local fi = io.open("moonloader/config/shporasetting.lua","r+")
  if fi == nil then
    fi = io.open("moonloader/config/shporasetting.lua","w")
    fi:close()
    fi = io.open("moonloader/config/shporasetting.lua", "r+")
    fi:write("cmd = 'shp'-- комманда активации(писать БЕЗ '/')\n fsize = 11 --размер шрифта, минимальный - 8, максимальный - 11")
    fi:flush()
  end
  require "config.shporasetting"
  fi:close()
  local resX, resY = getScreenResolution()
  local resX, resY = 1200, 320
  sampRegisterChatCommand("shp", shpora)
  sampRegisterChatCommand("shpr", rshpora)
  sampRegisterChatCommand("shpfsize", fosize)
  local h = resY - 135
  local font = renderCreateFont("Arial", fsize, 5)
  local wei = 200
  local hei = 200
  local mh = tweaks.mouseHandler:new()
  local scrollBar = tweaks.scrollBar:new(resX+wei, resY-150+15, 20, hei+5, 1000)
  if fsize < 8 or 11 < fsize then
    fsize = 11
  end
  if fsize == 8 then
    scrollBar.visibleLines = 14
  end
  if fsize == 9 or fsize == 10 then
    scrollBar.visibleLines = 11
  end
  if fsize == 11 then
    scrollBar.visibleLines = 10
  end
  local colori = 0xff969696
  while true do
    wait(0)
    if resultat and not isPauseMenuActive() then
      delta = getMousewheelDelta()
      if delta < 0 then
        scrollBar.currLine = scrollBar.currLine - delta
      end
      if 0 < delta then
        scrollBar.currLine = scrollBar.currLine - delta
      end
      if isKeyJustPressed(38) then
        scrollBar.currLine = scrollBar.currLine - 15
      end
      if isKeyJustPressed(40) then
        scrollBar.currLine = scrollBar.currLine + 15
      end
      local f = io.open("moonloader/config/shpora.txt", "r+")
      for line in f:lines() do
        text[#text+1] = line
      end
      f:close()
      renderDrawBox(resX - 350, resY - 150, wei, hei+20, 0xff161616)
      renderDrawBox(resX - 350, resY - 150, wei+20, hei - 185, 0xff262626)
      local flags = mh:isKeyPressed(VK_LBUTTON, resX-350, resY-150, wei+20, hei-185)
      if flags.isWnd == true then
        if flags.isDownWnd == true then
          resX, resY = getCursorPos()
          scrollBar.x = resX+wei - 250
          scrollBar.y = resY+10
          resX = resX + 100
          resY = resY+145
        end
      end
      scrollBar:draw()
      sampSetCursorMode(3)
      scrollBar.maxLines = #text
      for k , v in ipairs(text) do
        if k > (scrollBar.currLine ) and k <= (scrollBar.currLine + scrollBar.visibleLines) then
          local flags1 = mh:isKeyPressed(VK_LBUTTON, resX-345, h, renderGetFontDrawTextLength(font, v), renderGetFontDrawHeight(font))
          if flags1.isWnd == true then
            colori = 0xffc6c6c6
            if isKeyJustPressed(VK_LBUTTON) then
              sampSetCurrentDialogEditboxText(v)
            end
            if isKeyJustPressed(VK_RBUTTON) then
              sampSetChatInputText(v)
              sampSetChatInputEnabled(true)
            end
          else
            colori = 0xff969696
          end
          renderFontDrawText(font, string.format("%s", v), resX-345, h, colori)
          len = renderGetFontDrawTextLength(font, v)
          if len > wei then
            wei = len + 5
          end
          if 300 > wei then
            wei = 300
          end
          h = h + renderGetFontDrawHeight(font)+3
        end
      end
      scrollBar.x = resX+wei-350
      h = resY - 135
      for a = 0, 10000 do
        text[#text] = nil
      end
    end
  end
end

function fosize(fise)
  fsize = tonumber(fise)
end

function rshpora()
  print("shpora reloaded")
  local script = thisScript()
  script:reload()
end

function shpora()
  if resultat then
    resultat = false
  else
    resultat = true
  end
end
 

whyhardlyz

Известный
120
90
прикол:
script_name("Shpora")
script_author("4el0ve4ik")
script_version("v1.1")
require "lib.moonloader"
local tweaks = require "lib.mgtweaks"

local resultat = false
local text = {}
function main()
  if not isSampLoaded() then return end
  if doesDirectoryExist("moonloader/config") then
    _ = createDirectory("moonloader/config")
  end
  local f = io.open("moonloader/config/shpora.txt","r+")
  if f == nil then
    f = io.open("moonloader/config/shpora.txt","w")
    f:close()
    f = io.open("moonloader/config/shpora.txt", "r+")
    f:write("\nТекст можно задать в {ff0000}'moonloader/config/shpora.txt'\nby 4el0ve4ik for {0000ff}BlastHack")
    f:flush()
  end
  f:close()
  local fi = io.open("moonloader/config/shporasetting.lua","r+")
  if fi == nil then
    fi = io.open("moonloader/config/shporasetting.lua","w")
    fi:close()
    fi = io.open("moonloader/config/shporasetting.lua", "r+")
    fi:write("cmd = 'shp'-- комманда активации(писать БЕЗ '/')\n fsize = 11 --размер шрифта, минимальный - 8, максимальный - 11")
    fi:flush()
  end
  require "config.shporasetting"
  fi:close()
  local resX, resY = getScreenResolution()
  local resX, resY = 1200, 320
  sampRegisterChatCommand("shpr", rshpora)
  sampRegisterChatCommand("shpfsize", fosize)
  local h = resY - 135
  local font = renderCreateFont("Arial", fsize, 5)
  local wei = 200
  local hei = 200
  local mh = tweaks.mouseHandler:new()
  local scrollBar = tweaks.scrollBar:new(resX+wei, resY-150+15, 20, hei+5, 1000)
  if fsize < 8 or 11 < fsize then
    fsize = 11
  end
  if fsize == 8 then
    scrollBar.visibleLines = 14
  end
  if fsize == 9 or fsize == 10 then
    scrollBar.visibleLines = 11
  end
  if fsize == 11 then
    scrollBar.visibleLines = 10
  end
  local colori = 0xff969696
  while true do
    wait(0)
    if isKeyJustPressed(VK_INSERT) then -- VK_INSERT <- Клавиша
      if resultat then
        resultat = false
        sampToggleCursor(false) -- скрытие курсора после закрытия окна
      else
        resultat = true
      end
    end
    if resultat and not isPauseMenuActive() then
      delta = getMousewheelDelta()
      if delta < 0 then
        scrollBar.currLine = scrollBar.currLine - delta
      end
      if 0 < delta then
        scrollBar.currLine = scrollBar.currLine - delta
      end
      if isKeyJustPressed(38) then
        scrollBar.currLine = scrollBar.currLine - 15
      end
      if isKeyJustPressed(40) then
        scrollBar.currLine = scrollBar.currLine + 15
      end
      local f = io.open("moonloader/config/shpora.txt", "r+")
      for line in f:lines() do
        text[#text+1] = line
      end
      f:close()
      renderDrawBox(resX - 350, resY - 150, wei, hei+20, 0xff161616)
      renderDrawBox(resX - 350, resY - 150, wei+20, hei - 185, 0xff262626)
      local flags = mh:isKeyPressed(VK_LBUTTON, resX-350, resY-150, wei+20, hei-185)
      if flags.isWnd == true then
        if flags.isDownWnd == true then
          resX, resY = getCursorPos()
          scrollBar.x = resX+wei - 250
          scrollBar.y = resY+10
          resX = resX + 100
          resY = resY+145
        end
      end
      scrollBar:draw()
      sampSetCursorMode(3)
      scrollBar.maxLines = #text
      for k , v in ipairs(text) do
        if k > (scrollBar.currLine ) and k <= (scrollBar.currLine + scrollBar.visibleLines) then
          local flags1 = mh:isKeyPressed(VK_LBUTTON, resX-345, h, renderGetFontDrawTextLength(font, v), renderGetFontDrawHeight(font))
          if flags1.isWnd == true then
            colori = 0xffc6c6c6
            if isKeyJustPressed(VK_LBUTTON) then
              sampSetCurrentDialogEditboxText(v)
            end
            if isKeyJustPressed(VK_RBUTTON) then
              sampSetChatInputText(v)
              sampSetChatInputEnabled(true)
            end
          else
            colori = 0xff969696
          end
          renderFontDrawText(font, string.format("%s", v), resX-345, h, colori)
          len = renderGetFontDrawTextLength(font, v)
          if len > wei then
            wei = len + 5
          end
          if 300 > wei then
            wei = 300
          end
          h = h + renderGetFontDrawHeight(font)+3
        end
      end
      scrollBar.x = resX+wei-350
      h = resY - 135
      for a = 0, 10000 do
        text[#text] = nil
      end
    end
  end
end

function fosize(fise)
  fsize = tonumber(fise)
end

function rshpora()
  print("shpora reloaded")
  local script = thisScript()
  script:reload()
end