ошибка в скрипте

kwzInside

Участник
Автор темы
67
7
Версия MoonLoader
.027.0-preview
здравствуйте, прошу помочь мне, написал скрипт который должен был биндить клавиши
например клавиша "B" - это команда "/mm", но скрипт не работает
подскажите пожалуйста, что необходимо изменить
Lua:
[/B]
script_author('kwzInside')
script_name('Keys bind')
require "lib.moonloader"
local keys = "vkeys"
function main()
if not isSampLoaded() or isSampfuncsLoaded()
then return
end
while not isSampAvaolable()
do wait(100)
end
    sampAddChatMessage(tag .. '{DC143C}Key bind{00FF00}successfully loaded.', -1)
    while true do
    wait(0)
    if isKeyJustPressed(VK_O)
    then
    sampSendChat("/gps")
    end
    if isKeyJustPressed(VK_M)
    sampSendChat("/usemed")
    end
    if isKeyJustPressed(VK_J)
    sampSendChat("/fillcar")
    end
    if isKeyJustPressed(VK_H)
    sampSendChat("/lock")
    end
    if isKeyJustPressed((VK_L)
    sampSendChat("/lock")
    end
    if isKeyJustPressed(VK_G)
    sampSendChat("/jlock")
    end
    if isKeyJustPressed(VK_B)
    sampSendChat("/mm")
    end
    if isKeyJustPressed(VK_;)
    sampSendChat("/park")
    end
end
[B]
 

MLycoris

На вид оружие массового семяизвержения
Проверенный
2,002
2,243
Lua:
script_author('kwzInside')
script_name('Keys bind')

require "lib.moonloader"
function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage('{DC143C}Key bind{00FF00}successfully loaded.', -1)
    while true do wait(0)
        if not sampIsCursorActive() then
            if isKeyJustPressed(VK_O) then
                sampSendChat("/gps")
            end
            if isKeyJustPressed(VK_M) then
                sampSendChat("/usemed")
            end
            if isKeyJustPressed(VK_J) then
                sampSendChat("/fillcar")
            end
            if isKeyJustPressed(VK_H) then
                sampSendChat("/lock")
            end
            if isKeyJustPressed(VK_L) then
                sampSendChat("/lock")
            end
            if isKeyJustPressed(VK_G) then
                sampSendChat("/jlock")
            end
            if isKeyJustPressed(VK_B) then
                sampSendChat("/mm")
            end
            if isKeyJustPressed(VK_E) then
                sampSendChat("/park")
            end
        end
    end
end
 
  • Нравится
Реакции: qdIbp и YarikVL

kwzInside

Участник
Автор темы
67
7
Lua:
script_author('kwzInside')
script_name('Keys bind')

require "lib.moonloader"
function main()
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage('{DC143C}Key bind{00FF00}successfully loaded.', -1)
    while true do wait(0)
        if not sampIsCursorActive() then
            if isKeyJustPressed(VK_O) then
                sampSendChat("/gps")
            end
            if isKeyJustPressed(VK_M) then
                sampSendChat("/usemed")
            end
            if isKeyJustPressed(VK_J) then
                sampSendChat("/fillcar")
            end
            if isKeyJustPressed(VK_H) then
                sampSendChat("/lock")
            end
            if isKeyJustPressed(VK_L) then
                sampSendChat("/lock")
            end
            if isKeyJustPressed(VK_G) then
                sampSendChat("/jlock")
            end
            if isKeyJustPressed(VK_B) then
                sampSendChat("/mm")
            end
            if isKeyJustPressed(VK_E) then
                sampSendChat("/park")
            end
        end
    end
end
благодарю
 

Sanurial

Участник
84
14
Исправленный код:
script_author('kwzInside')
script_name('Keys bind')

require "lib.moonloader"

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then
        return
    end
   
    while not isSampAvailable() do
        wait(100)
    end
   
    sampAddChatMessage('{DC143C}Key bind {00FF00}successfully loaded.', -1)
   
    while true do
        wait(0)
       
        if isKeyJustPressed(VK_O) then
            sampSendChat("/gps")
        end
       
        if isKeyJustPressed(VK_M) then
            sampSendChat("/usemed")
        end
       
        if isKeyJustPressed(VK_J) then
            sampSendChat("/fillcar")
        end
       
        if isKeyJustPressed(VK_H) then
            sampSendChat("/lock")
        end
       
        if isKeyJustPressed(VK_L) then
            sampSendChat("/lock")
        end
       
        if isKeyJustPressed(VK_G) then
            sampSendChat("/jlock")
        end
       
        if isKeyJustPressed(VK_B) then
            sampSendChat("/mm")
        end
       
        if isKeyJustPressed(VK_OEM_1) then
            sampSendChat("/park")
        end
    end
end

Какие ошибки были?
- В строках с 18 по 41 необходимо добавить then после условия видаif isKeyJustPressed(VK...)
перед вызовом функцииsampSendChat().
- Не хватает закрывающей скобки в строках 18, 21, 24, 27, 30, 33, 36, 39.
- В строке 6 опечатка в словеavailable.


Для изучения:
script_author('kwzInside')
script_name('Keys bind')
require "lib.moonloader"

local keys = {
    O = VK_O,
    M = VK_M,
    J = VK_J,
    H = VK_H,
    L = VK_L,
    G = VK_G,
    B = VK_B,
    [";"] = VK_SEMICOLON
}

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampAddChatMessage("{DC143C}Key bind {00FF00}successfully loaded.", -1)
    while true do
        wait(0)
        for key, vk in pairs(keys) do
            if isKeyJustPressed(vk) then
                local command = {
                    O = "/gps",
                    M = "/usemed",
                    J = "/fillcar",
                    H = "/lock",
                    L = "/lock",
                    G = "/jlock",
                    B = "/mm",
                    [";"] = "/park"
                }
                sampSendChat(command[key])
            end
        end
    end
end