не работает скрипт

hekka

Новичок
Автор темы
4
0
приветствую. не работает скрипт, пишет что ошибка в while на 7 лайне, но на 7 лайне у меня функция имгуи. ниже прилагаю лог мунлоадера (отрывок со скриптом) и табуляцию скрипта.

[02:03:54.694100] (debug) New script: 28C31A8C
[02:03:54.695100] (error) relogafterheal.lua: E:\ARIZONA GAMES\bin\Arizona\moonloader\relogafterheal.lua:11: ')' expected (to close '(' at line 7) near 'while'
[02:03:54.695100] (error) relogafterheal.lua: Script died due to an error. (28C31A8C)


ыы:
require "lib.moonloader"
local imgui = require 'imgui'
local key = require 'vkeys'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
function imgui.OnDrawFrame()
  if main_window_state.v then --
    imgui.SetNextWindowSize(imgui.ImVec2(650, 800), imgui.Cond.FirstUseEver)
 
    imgui.Begin('HHelper', main_window_state)
    imgui.Text('zxc')
    if imgui.Button('Релог после хила') then
      sampAddChatMessage("{FFD700}[HHelper]: {FFFFFF}Релог {FFFFFF}после {FFFFF}хила {FFFFFF} успешно {FFFFFF}активирован.", -1)
    end
      local events = requre('lib.samp.events')

function events.onServerMessage(color, text)
    if text == 'Вы закончили свое лечение.' then
        lua_thread.create(function()
            sampDisconnectWithReason(false)
            wait(20000)
            sampSetGamestate(1)
        end)
    end
end
  
    imgui.End()
  end
end

function main()
  while true do
    wait(0)
    if wasKeyPressed(key.VK_X) then
        main_window_state.v = not main_window_state.v
    end
    imgui.Process = main_window_state.v
  end
end


upd: если не трудно, то укажите на ошибки в коде, луа занимаюсь первый дент)
 
Последнее редактирование:

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,746
не копируй в тупую, а смотри, что копируешь.
1) табуляция сказала: пока
2) нет переменной main_window_state
3) не requre, а require
4) функция в другой функции, в твоем случае так вообще не нужно делать
5) require в потоке
6) нет проверки на самп
вроде ничего не забыл
если не трудно, то укажите на ошибки в коде, луа занимаюсь первый дент)
так ты изучи основы, а не лети вперед паровоза. я тоже бежал когда-то по C++ в 2017 году, в итоге забросил и только недавно осознал свои ошибки.

Lua:
local key = require 'vkeys'
local se = require 'samp.events'
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(true) -- вроде так, давно не юзал эту либу

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(650, 800), imgui.Cond.FirstUseEver)
        imgui.Begin('HHelper', main_window_state)
        imgui.Text('zxc')
        if imgui.Button('Релог после хила') then
            sampAddChatMessage("[HHelper]: {FFFFFF} Релог после хила  успешно активирован.", 0xFFD700)
        end
        imgui.End()
    end
end

function se.onServerMessage(color, text)
    if text == 'Вы закончили свое лечение.' then
        lua_thread.create(function()
            sampDisconnectWithReason(false)
            wait(20000)
            sampSetGamestate(1)
        end)
    end
end

function main()
    while not isSampAvailable() do wait(40) end
    while true do wait(0)
        if isKeyJustPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
        imgui.Process = main_window_state.v
    end
end
Вроде так. Можно конечно и лучше.
 
  • Нравится
Реакции: Nestle

hekka

Новичок
Автор темы
4
0
не копируй в тупую, а смотри, что копируешь.
1) табуляция сказала: пока
2) нет переменной main_window_state
3) не requre, а require
4) функция в другой функции, в твоем случае так вообще не нужно делать
5) require в потоке
6) нет проверки на самп
вроде ничего не забыл

так ты изучи основы, а не лети вперед паровоза. я тоже бежал когда-то по C++ в 2017 году, в итоге забросил и только недавно осознал свои ошибки.

Lua:
local key = require 'vkeys'
local se = require 'samp.events'
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

local main_window_state = imgui.ImBool(true) -- вроде так, давно не юзал эту либу

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(650, 800), imgui.Cond.FirstUseEver)
        imgui.Begin('HHelper', main_window_state)
        imgui.Text('zxc')
        if imgui.Button('Релог после хила') then
            sampAddChatMessage("[HHelper]: {FFFFFF} Релог после хила  успешно активирован.", 0xFFD700)
        end
        imgui.End()
    end
end

function se.onServerMessage(color, text)
    if text == 'Вы закончили свое лечение.' then
        lua_thread.create(function()
            sampDisconnectWithReason(false)
            wait(20000)
            sampSetGamestate(1)
        end)
    end
end

function main()
    while not isSampAvailable() do wait(40) end
    while true do wait(0)
        if isKeyJustPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
        imgui.Process = main_window_state.v
    end
end
Вроде так. Можно конечно и лучше.
спасибо, учту. не подскажете как сделать выключение на кнопку?
 

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,746
спасибо, учту. не подскажете как сделать выключение на кнопку?
Завести переменную и переключать ее
Lua:
local active = false

-- imgui
if imgui.Button("Active is " .. tostring(active)) then
    active = not active
    sampAddChatMessage("Script is " .. tostring(active), -1)
end
 
  • Нравится
Реакции: Nestle

hekka

Новичок
Автор темы
4
0
Завести переменную и переключать ее
Lua:
local active = false

-- imgui
if imgui.Button("Active is " .. tostring(active)) then
    active = not active
    sampAddChatMessage("Script is " .. tostring(active), -1)
end
чуть не понял куда вставить, попытался вставить и в начало и в конец cкрипта, даже в середину, не работает, имгуи меню тоже не открывется. ошибка абсолютно та же

[22:34:09.203642] (debug) New script: 2BD87ED4
[22:34:09.203642] (error) relogafterheal.lua: E:\ARIZONA GAMES\bin\Arizona\moonloader\relogafterheal.lua:11: ')' expected (to close '(' at line 7) near 'while'
[22:34:09.203642] (error) relogafterheal.lua: Script died due to an error. (2BD87ED4)
 

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,746
чуть не понял куда вставить, попытался вставить и в начало и в конец cкрипта, даже в середину, не работает, имгуи меню тоже не открывется. ошибка абсолютно та же

[22:34:09.203642] (debug) New script: 2BD87ED4
[22:34:09.203642] (error) relogafterheal.lua: E:\ARIZONA GAMES\bin\Arizona\moonloader\relogafterheal.lua:11: ')' expected (to close '(' at line 7) near 'while'
[22:34:09.203642] (error) relogafterheal.lua: Script died due to an error. (2BD87ED4)
Так?
Lua:
local key = require 'vkeys'
local se = require 'samp.events'
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

--> Vars
local active = false

--> Vars ImGui
local main_window_state = imgui.ImBool(true)

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(650, 800), imgui.Cond.FirstUseEver)
        imgui.Begin('HHelper', main_window_state)
        imgui.Text('zxc')
        if imgui.Button( ('Релог после хила: (%s)'):format(tostring(active)) ) then
            active = not active
            sampAddChatMessage("[HHelper]: {FFFFFF} Релог после хила  успешно активирован.", 0xFFD700)
        end
        imgui.End()
    end
end

function se.onServerMessage(color, text)
    if active and text == 'Вы закончили свое лечение.' then
        lua_thread.create(function()
            sampDisconnectWithReason(false)
            wait(20000)
            sampSetGamestate(1)
        end)
    end
end

function main()
    while not isSampAvailable() do wait(40) end
    while true do wait(0)
        if isKeyJustPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
        imgui.Process = main_window_state.v
    end
end
 

hekka

Новичок
Автор темы
4
0
Так?
Lua:
local key = require 'vkeys'
local se = require 'samp.events'
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8

--> Vars
local active = false

--> Vars ImGui
local main_window_state = imgui.ImBool(true)

function imgui.OnDrawFrame()
    if main_window_state.v then
        imgui.SetNextWindowSize(imgui.ImVec2(650, 800), imgui.Cond.FirstUseEver)
        imgui.Begin('HHelper', main_window_state)
        imgui.Text('zxc')
        if imgui.Button( ('Релог после хила: (%s)'):format(tostring(active)) ) then
            active = not active
            sampAddChatMessage("[HHelper]: {FFFFFF} Релог после хила  успешно активирован.", 0xFFD700)
        end
        imgui.End()
    end
end

function se.onServerMessage(color, text)
    if active and text == 'Вы закончили свое лечение.' then
        lua_thread.create(function()
            sampDisconnectWithReason(false)
            wait(20000)
            sampSetGamestate(1)
        end)
    end
end

function main()
    while not isSampAvailable() do wait(40) end
    while true do wait(0)
        if isKeyJustPressed(key.VK_X) then
            main_window_state.v = not main_window_state.v
        end
        imgui.Process = main_window_state.v
    end
end
скрипт вообще перестал работать, мб не так че то