Помогите с багом в скрипте

Sct.L

Новичок
Автор темы
7
1
Пытался сделать скрипт по тиму ctime только с позицией, всё верно написано, но когда ввожу команду активации ничего не происходит
Код:
require 'lib.moonloader'
local imgui = require('imgui')
local inicfg = require ('inicfg')
local tag = '{0000FF}[NavodHelp]: {FFFFFF}'
local i = 1200000
local dialog = false
local mov = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
font = renderCreateFont("Arial", 12, 5)
dx, dy, dz = getCharCoordinates(PLAYER_PED)
local dialogStr = "Установить позицию\nАктивировать?"

local f_ini         = getGameDirectory().."\\moonloader\\config\\psettings.ini"
ini = {
    settings = {
        activate = false,
        x = 300,
        y = 300,
    }
}
local config = inicfg.load(nil, f_ini)

if config == nil then
        createDirectory(getGameDirectory().."\\moonloader\\config")
        local f = io.open(f_ini, "w")
        f:close()
        if inicfg.save(ini, f_ini) then
            config = inicfg.load(nil, f_ini)
        end
        print("Created default settings.ini")
    end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. u8'Script loaded!', -1)
    sampRegisterChatCommand('posc', function()
    dialog = true
    end)
   
   
    while true do
        wait(0)
        if config.settings.activate or mov then
            if mov then
            sampToggleCursor(true)
                local x, y = getCursorPos()
                config.settings.x = x
                config.settings.y = y
                if isKeyJustPressed(0x01) then
                    moving = false
                    sampToggleCursor(false)
                    inicfg.save(config, f_ini)
                end
            end
            renderFontDrawText(font, "X " .. math.floor(dx) .. "Y " .. math.floor(dy) .. "Z " .. math.floor(dz), config.settings.x, config.settings.y, "0xFFFFFF")
        end
    end
end

if dialog == true then
    sampShowDialog(10, "Позиция позиции", dialogStr, "Ок", "Закрыть", 2)
end

local result, button, list, input = sampHasDialogRespond(10)

if result then --если диалог активен
    if button == 1 then --если нажата кнопка 1 "Ок"
        if list == 0 then --если выбрана 1 строка
            mov = true
            sampAddChatMessage('ЛКМ чтобы сохранить', -1)
        end
        if list == 1 then
            config.settings.activate = not config.settings.activate
                inicfg.save(config, f_ini)
                return true
        end
    else
       
    end
end
 
Последнее редактирование:

YarikVL

Известный
Проверенный
4,796
1,814
Пытался сделать скрипт по тиму ctime только с позицией, всё верно написано, но когда ввожу команду активации ничего не происходит
Код:
require 'lib.moonloader'
local imgui = require('imgui')
local inicfg = require ('inicfg')
local tag = '{0000FF}[NavodHelp]: {FFFFFF}'
local i = 1200000
local dialog = false
local mov = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
font = renderCreateFont("Arial", 12, 5)
dx, dy, dz = getCharCoordinates(PLAYER_PED)
local dialogStr = "Установить позицию\nАктивировать?"

local f_ini         = getGameDirectory().."\\moonloader\\config\\psettings.ini"
ini = {
    settings = {
        activate = false,
        x = 300,
        y = 300,
    }
}
local config = inicfg.load(nil, f_ini)

if config == nil then
        createDirectory(getGameDirectory().."\\moonloader\\config")
        local f = io.open(f_ini, "w")
        f:close()
        if inicfg.save(ini, f_ini) then
            config = inicfg.load(nil, f_ini)
        end
        print("Created default settings.ini")
    end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. u8'Script loaded!', -1)
    sampRegisterChatCommand('posc', function()
    dialog = true
    end)
  
  
    while true do
        wait(0)
        if config.settings.activate or mov then
            if mov then
            sampToggleCursor(true)
                local x, y = getCursorPos()
                config.settings.x = x
                config.settings.y = y
                if isKeyJustPressed(0x01) then
                    moving = false
                    sampToggleCursor(false)
                    inicfg.save(config, f_ini)
                end
            end
            renderFontDrawText(font, "X " .. math.floor(dx) .. "Y " .. math.floor(dy) .. "Z " .. math.floor(dz), config.settings.x, config.settings.y, "0xFFFFFF")
        end
    end
end

if dialog == true then
    sampShowDialog(10, "Позиция позиции", dialogStr, "Ок", "Закрыть", 2)
end

local result, button, list, input = sampHasDialogRespond(10)

if result then --если диалог активен
    if button == 1 then --если нажата кнопка 1 "Ок"
        if list == 0 then --если выбрана 1 строка
            mov = true
            sampAddChatMessage('ЛКМ чтобы сохранить', -1)
        end
        if list == 1 then
            config.settings.activate = not config.settings.activate
                inicfg.save(config, f_ini)
                return true
        end
    else
      
    end
end
Думаю что 64 строка не в беск цикле, поэтому оно проверяет один раз за твою сессию ( игру на сервере ), а не вечно.
Иди посмотри лучше ролики the champ guess все и по несколько раз каждый на ютубе. Или скачай:
 

Sct.L

Новичок
Автор темы
7
1
Думаю что 64 строка не в беск цикле, поэтому оно проверяет один раз за твою сессию ( игру на сервере ), а не вечно.
Иди посмотри лучше ролики the champ guess все и по несколько раз каждый на ютубе. Или скачай:
Это я уже решил, теперь появляется диалог но при взаимодействие ничего не происходит
Код:
require 'lib.moonloader'
local imgui = require('imgui')
local inicfg = require ('inicfg')
local tag = '{0000FF}[NavodHelp]: {FFFFFF}'
local i = 1200000
local dialog = false
local mov = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
font = renderCreateFont("Arial", 12, 5)
dx, dy, dz = getCharCoordinates(PLAYER_PED)
local dialogStr = "Установить позицию\nАктивировать?"

local f_ini         = getGameDirectory().."\\moonloader\\config\\psettings.ini"
ini = {
    settings = {
        activate = false,
        x = 300,
        y = 300,
    }
}
local config = inicfg.load(nil, f_ini)

if config == nil then
        createDirectory(getGameDirectory().."\\moonloader\\config")
        local f = io.open(f_ini, "w")
        f:close()
        if inicfg.save(ini, f_ini) then 
            config = inicfg.load(nil, f_ini)
        end
        print("Created default settings.ini") 
    end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. u8'Script loaded!', -1)
    sampRegisterChatCommand('posc', function()
    sampShowDialog(10, "Позиция позиции", dialogStr, "Ок", "Закрыть", 2)
    end)
    
    
    while true do
        wait(0)
        if config.settings.activate or mov then
            if mov then
            sampToggleCursor(true)
                local x, y = getCursorPos()
                config.settings.x = x
                config.settings.y = y
                if isKeyJustPressed(0x01) then
                    moving = false
                    sampToggleCursor(false)
                    inicfg.save(config, f_ini)
                end
            end
            renderFontDrawText(font, "X " .. math.floor(dx) .. "Y " .. math.floor(dy) .. "Z " .. math.floor(dz), config.settings.x, config.settings.y, "0xFFFFFF")
        end
    end
end



local result, button, list, input = sampHasDialogRespond(10)

if result then --если диалог активен
    if button == 1 then --если нажата кнопка 1 "Ок"
        if list == 0 then --если выбрана 1 строка
            mov = true
            sampAddChatMessage('ЛКМ чтобы сохранить', -1)
        end
        if list == 1 then
            config.settings.activate = not config.settings.activate
                inicfg.save(config, f_ini)
                return true
        end
    else
        
    end
end
 

YarikVL

Известный
Проверенный
4,796
1,814
Это я уже решил, теперь появляется диалог но при взаимодействие ничего не происходит
Код:
require 'lib.moonloader'
local imgui = require('imgui')
local inicfg = require ('inicfg')
local tag = '{0000FF}[NavodHelp]: {FFFFFF}'
local i = 1200000
local dialog = false
local mov = false
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local main_window_state = imgui.ImBool(false)
font = renderCreateFont("Arial", 12, 5)
dx, dy, dz = getCharCoordinates(PLAYER_PED)
local dialogStr = "Установить позицию\nАктивировать?"

local f_ini         = getGameDirectory().."\\moonloader\\config\\psettings.ini"
ini = {
    settings = {
        activate = false,
        x = 300,
        y = 300,
    }
}
local config = inicfg.load(nil, f_ini)

if config == nil then
        createDirectory(getGameDirectory().."\\moonloader\\config")
        local f = io.open(f_ini, "w")
        f:close()
        if inicfg.save(ini, f_ini) then
            config = inicfg.load(nil, f_ini)
        end
        print("Created default settings.ini")
    end

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage(tag .. u8'Script loaded!', -1)
    sampRegisterChatCommand('posc', function()
    sampShowDialog(10, "Позиция позиции", dialogStr, "Ок", "Закрыть", 2)
    end)
   
   
    while true do
        wait(0)
        if config.settings.activate or mov then
            if mov then
            sampToggleCursor(true)
                local x, y = getCursorPos()
                config.settings.x = x
                config.settings.y = y
                if isKeyJustPressed(0x01) then
                    moving = false
                    sampToggleCursor(false)
                    inicfg.save(config, f_ini)
                end
            end
            renderFontDrawText(font, "X " .. math.floor(dx) .. "Y " .. math.floor(dy) .. "Z " .. math.floor(dz), config.settings.x, config.settings.y, "0xFFFFFF")
        end
    end
end



local result, button, list, input = sampHasDialogRespond(10)

if result then --если диалог активен
    if button == 1 then --если нажата кнопка 1 "Ок"
        if list == 0 then --если выбрана 1 строка
            mov = true
            sampAddChatMessage('ЛКМ чтобы сохранить', -1)
        end
        if list == 1 then
            config.settings.activate = not config.settings.activate
                inicfg.save(config, f_ini)
                return true
        end
    else
       
    end
end
В гугле есть куча примеров, нужно только загуглить