помогите исправиь курсор + ошибку

bruskin

Участник
Автор темы
147
12
Версия MoonLoader
Другое
при заходе в игру вечно появляется курсор и при использовании происходит краш скрипта
Lua:
script_name("Hospital Tools by Bruskin")
script_author("Mark Bruskin")
script_description("Hospital Tools for Arizona RP")

require "lib.moonloader"

local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)
function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(600,400), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Команды скрипта', main_window_state)
        imgui.Text(u8'/svc - объявить о пропуске скорой помощи на сервере ВС')
        imgui.End()
    end
end

function main()

    while not isSampAvailable() do
        wait(0)
    end
    imgui.Process = true
    sampAddChatMessage("[Hospital Tools] Скрипт успешно загружен.", 0x00FF00)
    sampAddChatMessage("[Hospital Tools] Автор: Mark Bruskin", 0xFFFF00)
    sampAddChatMessage("[Hospital Tools] Версия: v. 1.0.0", 0xFFFF00)
    sampRegisterChatCommand("svc", svccb)
    sampRegisterChatCommand("hhelp", hhelpcb)
    sampRegisterChatCommand("sls", slscb)
    sampRegisterChatCommand("ssf", ssfcb)
    sampRegisterChatCommand("slv", slvcb)
    sampRegisterChatCommand("hilvc", hilvccb)
    sampRegisterChatCommand("cur", curcb)
    sampRegisterChatCommand("ihelp", function() main_window_state.v = not main_window_state.v end)

    wait(-1)
end

function svccb()
    sampSendChat("/m Медицинский Центр Vice City! Немедленно пропустите карету скорой помощи!")
end

function slscb()
    sampSendChat("/m Медицинский Центр г. Los Santos! Немедленно пропустите машину скорой помощи!")
end

function ssfcb()
    sampSendChat("/m Медицинский Центр г. San Fierro! Немедленно пропустите машину скорой помощи!")
end

function slvcb()
    sampSendChat("/m Медицинский Центр г. Los Santos! Немедленно пропустите машину скорой помощи!")
end

function hilvccb(arg)
    if tonumber(arg) then
        lua_thread.create(function()
        sampSendChat("/do Мед. сумка на поясе.")
        wait(1500)
        sampSendChat("/me открыл мед. сумку, после достал необходимые таблетки")
        wait(1500)
        sampSendChat("/do Таблетки в руках.")
        wait(1500)
        sampSendChat("/me передал таблетки человеку")
        wait(1500)
        sampSendChat("/heal "..arg.." 50")
        end)
    end
end

function curcb(arg)
    if tonumber(arg) then
        lua_thread.create(function()
        sampSendChat("/do Мед. сумка на поясе.")
        wait(1500)
        sampSendChat("/me открыл мед. сумку, после чего достал от туда укол адреналина")
        wait(1500)
        sampSendChat("/do Укол адреналина в руках.")
        wait(1500)
        sampSendChat("/me сделал укол в проблемное место")
        wait(1500)
        sampSendChat("/cure "..arg)
        end)
    end
end

moonlog:
[22:08:20.118182] (error) Hospital Tools by Bruskin: ...Games Launcher\bin\arizona\moonloader\Hospital Tools.lua:15: attempt to perform arithmetic on global 'scrX' (a nil value)
stack traceback:
...Games Launcher\bin\arizona\moonloader\Hospital Tools.lua:15: in function 'OnDrawFrame'
...zona Games Launcher\bin\arizona\moonloader\lib\imgui.lua:1378: in function <...zona Games Launcher\bin\arizona\moonloader\lib\imgui.lua:1367>
[22:08:20.128156] (error) Hospital Tools by Bruskin: Script died due to an error. (1066F9AC)
 
Решение
Lua:
script_name("Hospital Tools by Bruskin")
script_author("Mark Bruskin")
script_description("Hospital Tools for Arizona RP")

require "lib.moonloader"

local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)

function imgui.OnDrawFrame()
    if main_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(600, 400), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Команды скрипта', main_window_state)
        imgui.Text(u8'/svc - объявить о пропуске скорой помощи на...

bruskin

Участник
Автор темы
147
12
Наверное потому что у тебя imgui.Process всегда включен
не много не понимаю как это исправить

Так же у тебя нет переменных получения разрешения экрана - и переменные пустые
В начало кода

local scrX, scrY = getScreenResolution()
с избавлением от курсора помогло
 

bruskin

Участник
Автор темы
147
12
imgui.Process = main_window_state.v
Lua:
function main()

    while not isSampAvailable() do
        wait(0)
    end
    imgui.Process = main_window_state.v
    sampAddChatMessage("[Hospital Tools] Скрипт успешно загружен.", 0x00FF00)
    sampAddChatMessage("[Hospital Tools] Автор: Mark Bruskin", 0xFFFF00)
    sampAddChatMessage("[Hospital Tools] Версия: v. 1.0.0", 0xFFFF00)
    sampRegisterChatCommand("svc", svccb)
    sampRegisterChatCommand("hhelp", hhelpcb)
    sampRegisterChatCommand("sls", slscb)
    sampRegisterChatCommand("ssf", ssfcb)
    sampRegisterChatCommand("slv", slvcb)
    sampRegisterChatCommand("hilvc", hilvccb)
    sampRegisterChatCommand("cur", curcb)
    sampRegisterChatCommand("ihelp", function() main_window_state.v = not main_window_state.v end)

    wait(-1)
end
так?
 

Dmitriy Makarov

25.05.2021
Проверенный
2,478
1,113
Lua:
script_name("Hospital Tools by Bruskin")
script_author("Mark Bruskin")
script_description("Hospital Tools for Arizona RP")

require "lib.moonloader"

local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(false)

function imgui.OnDrawFrame()
    if main_window_state.v then
        local scrX, scrY = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(scrX / 2, scrY / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5));
        imgui.SetNextWindowSize(imgui.ImVec2(600, 400), imgui.Cond.FirstUseEver)
        imgui.Begin(u8'Команды скрипта', main_window_state)
        imgui.Text(u8'/svc - объявить о пропуске скорой помощи на сервере ВС')
        imgui.End()
    end
end

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage("[Hospital Tools] Скрипт успешно загружен.", 0x00FF00)
    sampAddChatMessage("[Hospital Tools] Автор: Mark Bruskin", 0xFFFF00)
    sampAddChatMessage("[Hospital Tools] Версия: v. 1.0.0", 0xFFFF00)
    sampRegisterChatCommand("svc", svccb)
    sampRegisterChatCommand("hhelp", hhelpcb)
    sampRegisterChatCommand("sls", slscb)
    sampRegisterChatCommand("ssf", ssfcb)
    sampRegisterChatCommand("slv", slvcb)
    sampRegisterChatCommand("hilvc", hilvccb)
    sampRegisterChatCommand("cur", curcb)
    sampRegisterChatCommand("ihelp", function() main_window_state.v = not main_window_state.v end)
    while true do wait(0)
        imgui.Process = main_window_state.v
    end
end

function svccb()
    sampSendChat("/m Медицинский Центр Vice City! Немедленно пропустите карету скорой помощи!")
end

function slscb()
    sampSendChat("/m Медицинский Центр г. Los Santos! Немедленно пропустите машину скорой помощи!")
end

function ssfcb()
    sampSendChat("/m Медицинский Центр г. San Fierro! Немедленно пропустите машину скорой помощи!")
end

function slvcb()
    sampSendChat("/m Медицинский Центр г. Los Santos! Немедленно пропустите машину скорой помощи!")
end

function hilvccb(arg)
    if tonumber(arg) then
        lua_thread.create(function()
        sampSendChat("/do Мед. сумка на поясе.")
        wait(1500)
        sampSendChat("/me открыл мед. сумку, после достал необходимые таблетки")
        wait(1500)
        sampSendChat("/do Таблетки в руках.")
        wait(1500)
        sampSendChat("/me передал таблетки человеку")
        wait(1500)
        sampSendChat("/heal "..arg.." 50")
        end)
    end
end

function curcb(arg)
    if tonumber(arg) then
        lua_thread.create(function()
        sampSendChat("/do Мед. сумка на поясе.")
        wait(1500)
        sampSendChat("/me открыл мед. сумку, после чего достал от туда укол адреналина")
        wait(1500)
        sampSendChat("/do Укол адреналина в руках.")
        wait(1500)
        sampSendChat("/me сделал укол в проблемное место")
        wait(1500)
        sampSendChat("/cure "..arg)
        end)
    end
end
 
  • Нравится
Реакции: bruskin и Lance_Sterling