Вопросы по Lua скриптингу

Общая тема для вопросов по разработке скриптов на языке программирования Lua, в частности под MoonLoader.
  • Задавая вопрос, убедитесь, что его нет в списке частых вопросов и что на него ещё не отвечали (воспользуйтесь поиском).
  • Поищите ответ в теме посвященной разработке Lua скриптов в MoonLoader
  • Отвечая, убедитесь, что ваш ответ корректен.
  • Старайтесь как можно точнее выразить мысль, а если проблема связана с кодом, то обязательно прикрепите его к сообщению, используя блок [code=lua]здесь мог бы быть ваш код[/code].
  • Если вопрос связан с MoonLoader-ом первым делом желательно поискать решение на wiki.

Частые вопросы

Как научиться писать скрипты? С чего начать?
Информация - Гайд - Всё о Lua скриптинге для MoonLoader(https://blast.hk/threads/22707/)
Как вывести текст на русском? Вместо русского текста у меня какие-то каракули.
Изменить кодировку файла скрипта на Windows-1251. В Atom: комбинация клавиш Ctrl+Shift+U, в Notepad++: меню Кодировки -> Кодировки -> Кириллица -> Windows-1251.
Как получить транспорт, в котором сидит игрок?
Lua:
local veh = storeCarCharIsInNoSave(PLAYER_PED)
Как получить свой id или id другого игрока?
Lua:
local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED) -- получить свой ид
local _, id = sampGetPlayerIdByCharHandle(ped) -- получить ид другого игрока. ped - это хендл персонажа
Как проверить, что строка содержит какой-то текст?
Lua:
if string.find(str, 'текст', 1, true) then
-- строка str содержит "текст"
end
Как эмулировать нажатие игровой клавиши?
Lua:
local game_keys = require 'game.keys' -- где-нибудь в начале скрипта вне функции main

setGameKeyState(game_keys.player.FIREWEAPON, -1) -- будет сэмулировано нажатие клавиши атаки
Все иды клавиш находятся в файле moonloader/lib/game/keys.lua.
Подробнее о функции setGameKeyState здесь: lua - setgamekeystate | BlastHack — DEV_WIKI(https://www.blast.hk/wiki/lua:setgamekeystate)
Как получить id другого игрока, в которого целюсь я?
Lua:
local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE) -- получить хендл персонажа, в которого целится игрок
if valid and doesCharExist(ped) then -- если цель есть и персонаж существует
  local result, id = sampGetPlayerIdByCharHandle(ped) -- получить samp-ид игрока по хендлу персонажа
  if result then -- проверить, прошло ли получение ида успешно
    -- здесь любые действия с полученным идом игрока
  end
end
Как зарегистрировать команду чата SAMP?
Lua:
-- До бесконечного цикла/задержки
sampRegisterChatCommand("mycommand", function (param)
     -- param будет содержать весь текст введенный после команды, чтобы разделить его на аргументы используйте string.match()
    sampAddChatMessage("MyCMD", -1)
end)
Крашит игру при вызове sampSendChat. Как это исправить?
Это происходит из-за бага в SAMPFUNCS, когда производится попытка отправки пакета определенными функциями изнутри события исходящих RPC и пакетов. Исправления для этого бага нет, но есть способ не провоцировать его. Вызов sampSendChat изнутри обработчика исходящих RPC/пакетов нужно обернуть в скриптовый поток с нулевой задержкой:
Lua:
function onSendRpc(id)
  -- крашит:
  -- sampSendChat('Send RPC: ' .. id)

  -- норм:
  lua_thread.create(function()
    wait(0)
    sampSendChat('Send RPC: ' .. id)
  end)
end
 
Последнее редактирование:

why ega

РП игрок
Модератор
2,548
2,241
а то ни видел такого ни разу

Уже пробовал math.max, мне надо другой способ чтобы сразу вывело с локальной
всм? шо значит "вывело с локальной"?
 

sosnov

Известный
331
115
куда угодно в коде
поставил,но цвет тот же,то есть голубой



всм? шо значит "вывело с локальной"
[14:19:02.128759] (error) fskin.lua: F:\Clear GTA SAMP low PC\moonloader\fskin.lua:404: attempt to index global 'mainIni' (a nil value)
stack traceback:
F:\Clear GTA SAMP low PC\moonloader\fskin.lua:404: in function 'Style'
F:\Clear GTA SAMP low PC\moonloader\fskin.lua:14: in function 'cb'
F:\Clear GTA SAMP low PC\moonloader\lib\mimgui\init.lua:86: in function 'InitializeRenderer'
F:\Clear GTA SAMP low PC\moonloader\lib\mimgui\init.lua:94: in function <F:\Clear GTA SAMP low PC\moonloader\lib\mimgui\init.lua:91>
[14:19:02.129759] (error) fskin.lua: Script died due to an error. (0CFE37FC)

что делать...
 

accord-

Потрачен
437
79
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.


всм? шо значит "вывело с локальной"?
есть список, значения в нем каждую добавляются либо отнимаются, я записываю их в локальную и мне надо с этой локальной выводить наибольшее число
 

siwage

Активный
188
65
поставил,но цвет тот же,то есть голубой


[14:19:02.128759] (error) fskin.lua: F:\Clear GTA SAMP low PC\moonloader\fskin.lua:404: attempt to index global 'mainIni' (a nil value)
stack traceback:
F:\Clear GTA SAMP low PC\moonloader\fskin.lua:404: in function 'Style'
F:\Clear GTA SAMP low PC\moonloader\fskin.lua:14: in function 'cb'
F:\Clear GTA SAMP low PC\moonloader\lib\mimgui\init.lua:86: in function 'InitializeRenderer'
F:\Clear GTA SAMP low PC\moonloader\lib\mimgui\init.lua:94: in function <F:\Clear GTA SAMP low PC\moonloader\lib\mimgui\init.lua:91>
[14:19:02.129759] (error) fskin.lua: Script died due to an error. (0CFE37FC)

что делать...
Покажи 404 строку и все к ней прилягающие
 

sosnov

Известный
331
115
Lua:
function Style()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
 
    style.WindowRounding = mainIni.style.rounding ~= 1 and 15 or 5 -- это скругление элементов, то что перед or - сглаженное, что после or - более резкое
    style.FrameRounding = mainIni.style.rounding ~= 1 and 7 or 3
    style.ScrollbarRounding =  mainIni.style.rounding ~= 1 and 9 or 3
    style.GrabRounding =  mainIni.style.rounding ~= 1 and 3 or 1
    style.ChildRounding =  mainIni.style.rounding ~= 1 and 10 or 3
    style.PopupRounding = mainIni.style.rounding ~= 1 and 10 or 3

    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.WindowPadding = imgui.ImVec2(15, 15)
    style.WindowBorderSize = 0
    imgui.PopupBorderSize = 10
    style.FramePadding = imgui.ImVec2(5, 5)
    style.ItemSpacing = imgui.ImVec2(12, 8)
    style.ItemInnerSpacing = imgui.ImVec2(8, 6)
    style.IndentSpacing = 25
    style.ScrollbarSize = 10
    style.GrabMinSize = 5   
    
    colors[clr.Text] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 1) or ImVec4(0.86, 0.93, 0.89, 0.78) -- что перед or - темная, что после or - берюзовое
    colors[clr.TextDisabled] = mainIni.style.theme ~= 1 and ImVec4(0.24, 0.23, 0.29, 1) or ImVec4(0.36, 0.42, 0.47, 1)
    colors[clr.WindowBg] =  mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.11, 0.15, 0.17, 1)
    colors[clr.ChildBg] = mainIni.style.theme ~= 1 and ImVec4(0, 0, 0, 0) or ImVec4(0, 0, 0, 0)
    colors[clr.PopupBg] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.FrameBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.20, 0.25, 0.29, 1)
    colors[clr.FrameBgHovered] = mainIni.style.theme ~= 1 and ImVec4(0.24, 0.23, 0.29, 1) or ImVec4(0.12, 0.20, 0.28, 1)
    colors[clr.FrameBgActive] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.09, 0.12, 0.14, 1)
    colors[clr.TitleBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.04, 0.04, 0.04, 1)
    colors[clr.TitleBgCollapsed] = mainIni.style.theme ~= 1 and ImVec4(1, 0.98, 0.95, 0.75) or ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.TitleBgActive] = mainIni.style.theme ~= 1 and ImVec4(0.07, 0.07, 0.09, 1) or ImVec4(0.16, 0.48, 0.42, 1)
    colors[clr.MenuBarBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.15, 0.18, 0.22, 1)
    colors[clr.ScrollbarBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.02, 0.02, 0.02, 0.39)
    colors[clr.ScrollbarGrab] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 0.31) or ImVec4(0.20, 0.25, 0.29, 1)
    colors[clr.ScrollbarGrabHovered] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.18, 0.22, 0.25, 1)
    colors[clr.ScrollbarGrabActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.09, 0.21, 0.31, 1)
    colors[clr.CheckMark] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 0.31) or ImVec4(0.26, 0.98, 0.85, 1)
    colors[clr.SliderGrab] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 0.31) or ImVec4(0.24, 0.88, 0.77, 1)
    colors[clr.SliderGrabActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.26, 0.98, 0.85, 1)
    colors[clr.Button] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.26, 0.98, 0.85, 0.30)
    colors[clr.ButtonHovered] = mainIni.style.theme ~= 1 and ImVec4(0.24, 0.23, 0.29, 1) or ImVec4(0.26, 0.98, 0.85, 0.50)
    colors[clr.ButtonActive] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.06, 0.98, 0.82, 0.50)
    colors[clr.Header] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.26, 0.98, 0.85, 0.31)
    colors[clr.HeaderHovered] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.26, 0.98, 0.85, 0.80)
    colors[clr.HeaderActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.26, 0.98, 0.85, 1)
    colors[clr.ResizeGrip] = mainIni.style.theme ~= 1 and ImVec4(0.00, 0.00, 0.00, 0.00) or ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.06, 0.05, 0.07, 1)
    colors[clr.PlotLines] = mainIni.style.theme ~= 1 and ImVec4(0.40, 0.39, 0.38, 0.63) or ImVec4(0.61, 0.61, 0.61, 1)
    colors[clr.PlotLinesHovered] = mainIni.style.theme ~= 1 and ImVec4(0.25, 1, 0.00, 1) or ImVec4(1, 0.43, 0.35, 1)
    colors[clr.PlotHistogram] =  mainIni.style.theme ~= 1 and ImVec4(0.40, 0.39, 0.38, 0.63) or ImVec4(0.90, 0.70, 0.00, 1)
    colors[clr.PlotHistogramHovered] = mainIni.style.theme ~= 1 and ImVec4(0.25, 1, 0.00, 1) or ImVec4(1, 0.60, 0.00, 1)
    colors[clr.TextSelectedBg] = mainIni.style.theme ~= 1 and ImVec4(0.25, 1, 0.00, 0.43) or ImVec4(0.25, 1, 0.00, 0.43)
end

вот весь код 404 строки,вот сама 404 строка:

style.WindowRounding = mainIni.style.rounding ~= 1 and 15 or 5 -- это скругление элементов, то что перед or - сглаженное, что после or - более резкое
 

why ega

РП игрок
Модератор
2,548
2,241
Lua:
function Style()
    local style = imgui.GetStyle()
    local colors = style.Colors
    local clr = imgui.Col
    local ImVec4 = imgui.ImVec4
 
   -- это скругление элементов, то что перед or - сглаженное, что после or - более резкое
    style.FrameRounding = mainIni.style.rounding ~= 1 and 7 or 3
    style.ScrollbarRounding =  mainIni.style.rounding ~= 1 and 9 or 3
    style.GrabRounding =  mainIni.style.rounding ~= 1 and 3 or 1
    style.ChildRounding =  mainIni.style.rounding ~= 1 and 10 or 3
    style.PopupRounding = mainIni.style.rounding ~= 1 and 10 or 3

    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
    style.WindowPadding = imgui.ImVec2(15, 15)
    style.WindowBorderSize = 0
    imgui.PopupBorderSize = 10
    style.FramePadding = imgui.ImVec2(5, 5)
    style.ItemSpacing = imgui.ImVec2(12, 8)
    style.ItemInnerSpacing = imgui.ImVec2(8, 6)
    style.IndentSpacing = 25
    style.ScrollbarSize = 10
    style.GrabMinSize = 5  
   
    colors[clr.Text] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 1) or ImVec4(0.86, 0.93, 0.89, 0.78) -- что перед or - темная, что после or - берюзовое
    colors[clr.TextDisabled] = mainIni.style.theme ~= 1 and ImVec4(0.24, 0.23, 0.29, 1) or ImVec4(0.36, 0.42, 0.47, 1)
    colors[clr.WindowBg] =  mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.11, 0.15, 0.17, 1)
    colors[clr.ChildBg] = mainIni.style.theme ~= 1 and ImVec4(0, 0, 0, 0) or ImVec4(0, 0, 0, 0)
    colors[clr.PopupBg] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.08, 0.08, 0.08, 0.94)
    colors[clr.FrameBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.20, 0.25, 0.29, 1)
    colors[clr.FrameBgHovered] = mainIni.style.theme ~= 1 and ImVec4(0.24, 0.23, 0.29, 1) or ImVec4(0.12, 0.20, 0.28, 1)
    colors[clr.FrameBgActive] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.09, 0.12, 0.14, 1)
    colors[clr.TitleBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.04, 0.04, 0.04, 1)
    colors[clr.TitleBgCollapsed] = mainIni.style.theme ~= 1 and ImVec4(1, 0.98, 0.95, 0.75) or ImVec4(0.00, 0.00, 0.00, 0.51)
    colors[clr.TitleBgActive] = mainIni.style.theme ~= 1 and ImVec4(0.07, 0.07, 0.09, 1) or ImVec4(0.16, 0.48, 0.42, 1)
    colors[clr.MenuBarBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.15, 0.18, 0.22, 1)
    colors[clr.ScrollbarBg] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.02, 0.02, 0.02, 0.39)
    colors[clr.ScrollbarGrab] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 0.31) or ImVec4(0.20, 0.25, 0.29, 1)
    colors[clr.ScrollbarGrabHovered] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.18, 0.22, 0.25, 1)
    colors[clr.ScrollbarGrabActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.09, 0.21, 0.31, 1)
    colors[clr.CheckMark] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 0.31) or ImVec4(0.26, 0.98, 0.85, 1)
    colors[clr.SliderGrab] = mainIni.style.theme ~= 1 and ImVec4(0.80, 0.80, 0.83, 0.31) or ImVec4(0.24, 0.88, 0.77, 1)
    colors[clr.SliderGrabActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.26, 0.98, 0.85, 1)
    colors[clr.Button] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.26, 0.98, 0.85, 0.30)
    colors[clr.ButtonHovered] = mainIni.style.theme ~= 1 and ImVec4(0.24, 0.23, 0.29, 1) or ImVec4(0.26, 0.98, 0.85, 0.50)
    colors[clr.ButtonActive] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.06, 0.98, 0.82, 0.50)
    colors[clr.Header] = mainIni.style.theme ~= 1 and ImVec4(0.10, 0.09, 0.12, 1) or ImVec4(0.26, 0.98, 0.85, 0.31)
    colors[clr.HeaderHovered] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.26, 0.98, 0.85, 0.80)
    colors[clr.HeaderActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.26, 0.98, 0.85, 1)
    colors[clr.ResizeGrip] = mainIni.style.theme ~= 1 and ImVec4(0.00, 0.00, 0.00, 0.00) or ImVec4(0.26, 0.59, 0.98, 0.25)
    colors[clr.ResizeGripHovered] = mainIni.style.theme ~= 1 and ImVec4(0.56, 0.56, 0.58, 1) or ImVec4(0.26, 0.59, 0.98, 0.67)
    colors[clr.ResizeGripActive] = mainIni.style.theme ~= 1 and ImVec4(0.06, 0.05, 0.07, 1) or ImVec4(0.06, 0.05, 0.07, 1)
    colors[clr.PlotLines] = mainIni.style.theme ~= 1 and ImVec4(0.40, 0.39, 0.38, 0.63) or ImVec4(0.61, 0.61, 0.61, 1)
    colors[clr.PlotLinesHovered] = mainIni.style.theme ~= 1 and ImVec4(0.25, 1, 0.00, 1) or ImVec4(1, 0.43, 0.35, 1)
    colors[clr.PlotHistogram] =  mainIni.style.theme ~= 1 and ImVec4(0.40, 0.39, 0.38, 0.63) or ImVec4(0.90, 0.70, 0.00, 1)
    colors[clr.PlotHistogramHovered] = mainIni.style.theme ~= 1 and ImVec4(0.25, 1, 0.00, 1) or ImVec4(1, 0.60, 0.00, 1)
    colors[clr.TextSelectedBg] = mainIni.style.theme ~= 1 and ImVec4(0.25, 1, 0.00, 0.43) or ImVec4(0.25, 1, 0.00, 0.43)
end

вот весь код 404 строки,вот сама 404 строка:

style.WindowRounding = mainIni.style.rounding ~= 1 and 15 or 5 -- это скругление элементов, то что перед or - сглаженное, что после or - более резкое
потому-что я тебе скинул отрывок из своего кода, в котором стоит выбор темы, в зависимости от значения в таблицы ini, ты должен каждую строку переделать в такой формат, выбрав одно значение из двух:
Lua:
 style.WindowRounding = 5

есть список, значения в нем каждую добавляются либо отнимаются, я записываю их в локальную и мне надо с этой локальной выводить наибольшее число
скинь код, посмотрим шо у тебя
 
  • Влюблен
Реакции: sosnov

YarikVL

Известный
Проверенный
4,798
1,814
[ML] (error) new.lua: C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:18: unexpected symbol near ')'
[ML] (error) new.lua: Script died due to an error. (3E96A14C)

Посмотреть вложение 194200
Подними end на строку выше
6CFB8740-50AE-42C3-BF7B-34BE5C22CB9B.jpeg
У тебя же end) со скобкой закрывает строку: sampRegisterChatCommand("gl", function(arg)
 

Dmitriy Makarov

25.05.2021
Проверенный
2,478
1,113
[ML] (error) new.lua: C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:18: unexpected symbol near ')'
[ML] (error) new.lua: Script died due to an error. (3E96A14C)

Посмотреть вложение 194200
Lua:
local arr = {
    "FLYING",
    "SAILING",
    "FISHING"
}

function main()
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand("gl", function(arg)
        local playerId, type = arg:match("(%d+)%s+(%d+)")
        if playerId and type then
            sampSendChat("/finish "..playerId.." "..arr[type])
        end
    end)
    wait(-1)
end
 

sssilvian

Активный
230
25
Подними end на строку выше
Посмотреть вложение 194205
У тебя же end) со скобкой закрывает строку: sampRegisterChatCommand("gl", function(arg)
Lua:
local samp = require 'samp.events'
local sampev = require("lib.samp.events")

function main()
      if not isSampfuncsLoaded() or not isSampLoaded() then return end
      while not isSampAvailable() do wait(100) end
c = {
"FLYING",
"SAILING",
"FISHING"
}

sampRegisterChatCommand("gl", function(arg)
    a, b = arg:match("(%d+)%s+(%d+)")
    if a and b then
        sampSendChat("/finish "..a.." "..c[b])
    end
end)
end
[ML] (error) new.lua: C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:17: attempt to concatenate a nil value
stack traceback:
C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:17: in function <C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:14>
[ML] (error) new.lua: Script died due to an error. (0F33E51C)
 

YarikVL

Известный
Проверенный
4,798
1,814
Lua:
local samp = require 'samp.events'
local sampev = require("lib.samp.events")

function main()
      if not isSampfuncsLoaded() or not isSampLoaded() then return end
      while not isSampAvailable() do wait(100) end
c = {
"FLYING",
"SAILING",
"FISHING"
}

sampRegisterChatCommand("gl", function(arg)
    a, b = arg:match("(%d+)%s+(%d+)")
    if a and b then
        sampSendChat("/finish "..a.." "..c[b])
    end
end)
end
[ML] (error) new.lua: C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:17: attempt to concatenate a nil value
stack traceback:
C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:17: in function <C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:14>
[ML] (error) new.lua: Script died due to an error. (0F33E51C)
И как ты вводишь команду? Покажи на примере при котором у тебя крашиться скрипт.

Типо:
/gl 228 2


Можешь ещё попробовать:
Lua:
local samp = require 'samp.events'
local sampev = require("lib.samp.events")

function main()
      if not isSampfuncsLoaded() or not isSampLoaded() then return end
      while not isSampAvailable() do wait(100) end
c = {
"FLYING",
"SAILING",
"FISHING"
}

sampRegisterChatCommand("gl", function(arg)
    a, b = arg:match("(%d+)%s+(%d+)")
    if a and b then
        sampSendChat("/finish "..tostring(a).." "..c[b])
    end
end)
end
 

DZONE

Известный
183
185
Lua:
local samp = require 'samp.events'
local sampev = require("lib.samp.events")

function main()
      if not isSampfuncsLoaded() or not isSampLoaded() then return end
      while not isSampAvailable() do wait(100) end
c = {
"FLYING",
"SAILING",
"FISHING"
}

sampRegisterChatCommand("gl", function(arg)
    a, b = arg:match("(%d+)%s+(%d+)")
    if a and b then
        sampSendChat("/finish "..a.." "..c[b])
    end
end)
end
[ML] (error) new.lua: C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:17: attempt to concatenate a nil value
stack traceback:
C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:17: in function <C:\Users\CRISTIAN\Desktop\samp clasik\moonloader\new.lua:14>
[ML] (error) new.lua: Script died due to an error. (0F33E51C)
Lua:
local samp = require 'samp.events'
local sampev = require("lib.samp.events")

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
    
    local c = {
        "FLYING",
        "SAILING",
        "FISHING"
    }
    sampRegisterChatCommand("gl", function(arg)
        a, b = arg:match("(%d+)%s+(%d+)")
        if a and b then
            sampSendChat("/finish "..a.." "..c[b])
        end
    end)

    wait(-1)
end
 
  • Нравится
Реакции: YarikVL

YarikVL

Известный
Проверенный
4,798
1,814
Из за чего может быть краш?

Краш:
[17:27:04.049000] (error)    ATools.lua: C:\Users\marke\Desktop\Моя сборка\moonloader\ATools.lua:2386: 'then' expected near 'do'

2386 строка:
if cfg.main.skinlogin then
                if isPauseMenuActive() do
                    if cursorEnabled then
                      showCursor(false)
                    end
                    wait(100)
                end
                if isKeyDown(keyToggle) then
                    cursorEnabled = not cursorEnabled
                    showCursor(cursorEnabled)
                    while isKeyDown(keyToggle) do wait(80) end
                end
         
                if cursorEnabled then
                    local mode = sampGetCursorMode()
                    if mode == 0 then
                      showCursor(true)
                    end
                    local sx, sy = getCursorPos()
                    local sw, sh = getScreenResolution()
                    -- is cursor in game window bounds?
                    if sx >= 0 and sy >= 0 and sx < sw and sy < sh then
                      local posX, posY, posZ = convertScreenCoordsToWorld3D(sx, sy, 700.0)
                      local camX, camY, camZ = getActiveCameraCoordinates()
                      -- search for the collision point
                      local result, colpoint = processLineOfSight(camX, camY, camZ, posX, posY, posZ, true, true, false, true, false, false, false)
                      if result and colpoint.entity ~= 0 then
                        local normal = colpoint.normal
                        local pos = Vector3D(colpoint.pos[1], colpoint.pos[2], colpoint.pos[3]) - (Vector3D(normal[1], normal[2], normal[3]) * 0.1)
                        local zOffset = 300
                        if normal[3] >= 0.5 then zOffset = 1 end
                        -- search for the ground position vertically down
                        local result, colpoint2 = processLineOfSight(pos.x, pos.y, pos.z + zOffset, pos.x, pos.y, pos.z - 0.3,
                          true, true, false, true, false, false, false)
                        if result then
                          pos = Vector3D(colpoint2.pos[1], colpoint2.pos[2], colpoint2.pos[3] + 1)
         
                          local curX, curY, curZ  = getCharCoordinates(playerPed)
                          local dist              = getDistanceBetweenCoords3d(curX, curY, curZ, pos.x, pos.y, pos.z)
                          local hoffs             = renderGetFontDrawHeight(font)
         
                          sy = sy - 2
                          sx = sx - 2
                          renderFontDrawText(font, string.format("%0.2fm", dist), sx, sy - hoffs, 0xEEEEEEEE)
         
                          local tpIntoCar = nil
                          if colpoint.entityType == 2 then
                            local car = getVehiclePointerHandle(colpoint.entity)
                            if doesVehicleExist(car) and (not isCharInAnyCar(playerPed) or storeCarCharIsInNoSave(playerPed) ~= car) then
                              displayVehicleName(sx, sy - hoffs * 2, getNameOfVehicleModel(getCarModel(car)))
                              local color = 0xAAFFFFFF
                              if isKeyDown(VK_RBUTTON) then
                                tpIntoCar = car
                                color = 0xFFFFFFFF
                              end
                              renderFontDrawText(font2, "Hold right mouse button to teleport into the car", sx, sy - hoffs * 3, color)
                            end
                          end
         
                          createPointMarker(pos.x, pos.y, pos.z)
         
                          -- teleport!
                          if isKeyDown(keyApply) then
                            if tpIntoCar then
                              if not jumpIntoCar(tpIntoCar) then
                                -- teleport to the car if there is no free seats
                                teleportPlayer(pos.x, pos.y, pos.z)
                              end
                            else
                              if isCharInAnyCar(playerPed) then
                                local norm = Vector3D(colpoint.normal[1], colpoint.normal[2], 0)
                                local norm2 = Vector3D(colpoint2.normal[1], colpoint2.normal[2], colpoint2.normal[3])
                                rotateCarAroundUpAxis(storeCarCharIsInNoSave(playerPed), norm2)
                                pos = pos - norm * 1.8
                                pos.z = pos.z - 0.8
                              end
                              teleportPlayer(pos.x, pos.y, pos.z)
                            end
                            removePointMarker()
         
                            while isKeyDown(keyApply) do wait(0) end
                            showCursor(false)
                          end
                        end
                      end
                    end
                end
            end
if isPauseMenuActive() then
А не do