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

CeSum

Участник
Автор темы
30
0
Версия MoonLoader
.027.0-preview
Скрипт:

sampAddChatMessage("{FF4500}[CarSearch]{FFFF00} use /cfind [id], Author: CeSum!")
local vkeys = require "vkeys"
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(0) end
sampRegisterChatCommand("cfind",function(arg)
if tonumber(arg) then
local id = tonumber(arg)
local result, handle = sampGetCarHandleBySampVehicleId(id)
if result then
placeWaypoint(x,y,z)
sampAddChatMessage("{FF4500}[CarSearch] {FFF101}Car is found! Waypoint is placed in coords - "..x.. ", "..y.. ", "..z)
sampAddChatMessage("{FFF4500}[CarSearch] {FFF101}Press Z to update waypoint")

while true do
wait(0)
if isKeyJustPressed(vkeys.VK_Z)then do
local result, handle = sampGetCarHandleBySampVehicleId(id)
if result then
placeWaypoint(x,y,z)
else
sampAddChatMessage("{FF4500}[CarSearch] {FFF101} Car is not in stream zone!")
end
end
end
end
sampAddChatMessage("Type id")
end
wait(-1)
end
end
)
end

В логах нету ошибки, но почему-то на сервере пишет что команда не найдена o_O
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,767
11,220
переставь строку как на скрине (тип первую строку после while not...)
1645621391976.png
 

SomaGnoma

Известный
442
152

qdIbp

Автор темы
Проверенный
1,386
1,139
Не порти людям глаза, нажми на кнопку и вставь код, не будь как нуб, будь как все
Снимок экрана (541).png


Скрипт:

sampAddChatMessage("{FF4500}[CarSearch]{FFFF00} use /cfind [id], Author: CeSum!")
local vkeys = require "vkeys"
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(0) end
sampRegisterChatCommand("cfind",function(arg)
if tonumber(arg) then
local id = tonumber(arg)
local result, handle = sampGetCarHandleBySampVehicleId(id)
if result then
placeWaypoint(x,y,z)
sampAddChatMessage("{FF4500}[CarSearch] {FFF101}Car is found! Waypoint is placed in coords - "..x.. ", "..y.. ", "..z)
sampAddChatMessage("{FFF4500}[CarSearch] {FFF101}Press Z to update waypoint")

while true do
wait(0)
if isKeyJustPressed(vkeys.VK_Z)then do
local result, handle = sampGetCarHandleBySampVehicleId(id)
if result then
placeWaypoint(x,y,z)
else
sampAddChatMessage("{FF4500}[CarSearch] {FFF101} Car is not in stream zone!")
end
end
end
end
sampAddChatMessage("Type id")
end
wait(-1)
end
end
)
end

В логах нету ошибки, но почему-то на сервере пишет что команда не найдена o_O
Господи по милуй, что ты творишь
 
  • Влюблен
Реакции: SomaGnoma

SomaGnoma

Известный
442
152
то есть тя не смущает что чел цикл в команду засунул и не поставил в конце main() ожидание wait(-1)?
Вот рабочий код
Автор слишком гениален для этого мира, берите с него пример!
Lua:
local vkeys = require "vkeys"

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("cfind", function(arg)
        if tonumber(arg) then
        local id = arg
        local result, handle = sampGetCarHandleBySampVehicleId(id)
            if result then
            placeWaypoint(x,y,z)
            sampAddChatMessage("{FF4500}[CarSearch] {FFF101}Car is found! Waypoint is placed in coords - "..x..","..y.. ","..z)
            sampAddChatMessage("{FFF4500}[CarSearch] {FFF101}Press Z to update waypoint")
            end
        end
    end)
    while true do
        wait(0)
        if isKeyJustPressed(vkeys.VK_Z) then
        local result, handle = sampGetCarHandleBySampVehicleId(id)
            if result then
            placeWaypoint(x,y,z)
            else
            sampAddChatMessage("{FF4500}[CarSearch] {FFF101} Car is not in stream zone!")
            end
        end
    end
end
 
  • Влюблен
Реакции: qdIbp

qdIbp

Автор темы
Проверенный
1,386
1,139
Вот рабочий код
Автор слишком гениален для этого мира, берите с него пример!
Lua:
        local result, handle = sampGetCarHandleBySampVehicleId(id)
            if result then
            placeWaypoint(x,y,z)
            else
            sampAddChatMessage("{FF4500}[CarSearch] {FFF101} Car is not in stream zone!")
            end
        end
ГДЕ ТАБУЛЯЦИЯ!?
 
  • Нравится
  • Грустно
Реакции: chapo и SomaGnoma

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,767
11,220
то есть тя не смущает что чел цикл в команду засунул и не поставил в конце main() ожидание wait(-1)?
я увидел первую ошибку и написал, нахуй мне тратить свое время и расставлять за него табуляцию для поиска других ошибок
 
  • Влюблен
Реакции: SomaGnoma

CeSum

Участник
Автор темы
30
0
Вот рабочий код
Автор слишком гениален для этого мира, берите с него пример!
Lua:
local vkeys = require "vkeys"

function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand("cfind", function(arg)
        if tonumber(arg) then
        local id = arg
        local result, handle = sampGetCarHandleBySampVehicleId(id)
            if result then
            placeWaypoint(x,y,z)
            sampAddChatMessage("{FF4500}[CarSearch] {FFF101}Car is found! Waypoint is placed in coords - "..x..","..y.. ","..z)
            sampAddChatMessage("{FFF4500}[CarSearch] {FFF101}Press Z to update waypoint")
            end
        end
    end)
    while true do
        wait(0)
        if isKeyJustPressed(vkeys.VK_Z) then
        local result, handle = sampGetCarHandleBySampVehicleId(id)
            if result then
            placeWaypoint(x,y,z)
            else
            sampAddChatMessage("{FF4500}[CarSearch] {FFF101} Car is not in stream zone!")
            end
        end
    end
end
[ML] (error) test.lua: D:\SAMP\moonloader\test.lua:12: attempt to concatenate global 'z' (a nil value)
stack traceback:
D:\SAMP\moonloader\test.lua:12: in function <D:\SAMP\moonloader\test.lua:6>
[ML] (error) test.lua: Script died due to an error. (01B031EC)
 

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,767
11,220
не проверял, но в теории должно работать
Lua:
require 'lib.moonloader'
local id = -1

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cfind', function(arg)
        if tonumber(arg) then
            id = tonumber(arg)
            local result, coords = getCarCoords(id)
            if result then
                placeWaypoint(coords[1], coords[2], coords[3])
            else
                sampAddChatMessage('Ошибка, машина вне зоны стрима', -1)
            end
        end
    end)
    while true do
        wait(0)
        if id ~= -1 then
            if wasKeyPressed(VK_Z) and not sampIsCursorActive() then
                local result, coords = getCarCoords(id)
                if result then
                    placeWaypoint(coords[1], coords[2], coords[3])
                else
                    sampAddChatMessage('Ошибка, машина вне зоны стрима', -1)
                end
            end
        end
    end
end

function getCarCoords(id)
    local coords = {0, 0, 0}
    local result, car = sampGetCarHandleBySampVehicleId(id)
    if result then
        coords = {getCarCoordinates(car)}
    end
    return result, coords
end
 

CeSum

Участник
Автор темы
30
0
не проверял, но в теории должно работать
Lua:
require 'lib.moonloader'
local id = -1

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cfind', function(arg)
        if tonumber(arg) then
            id = tonumber(arg)
            local result, coords = getCarCoords(id)
            if result then
                placeWaypoint(coords[1], coords[2], coords[3])
            else
                sampAddChatMessage('Ошибка, машина вне зоны стрима', -1)
            end
        end
    end)
    while true do
        wait(0)
        if id ~= -1 then
            if wasKeyPressed(VK_Z) and not sampIsCursorActive() then
                local result, coords = getCarCoords(id)
                if result then
                    placeWaypoint(coords[1], coords[2], coords[3])
                else
                    sampAddChatMessage('Ошибка, машина вне зоны стрима', -1)
                end
            end
        end
    end
end

function getCarCoords(id)
    local coords = {0, 0, 0}
    local result, car = sampGetCarHandleBySampVehicleId(id)
    if result then
        coords = {getCarCoordinates(car)}
    end
    return result, coords
end
работает, спасибо

Кстати, куда грамотно поставить вывод сообщения в чат, что скрипт загружен?
не проверял, но в теории должно работать
Lua:
require 'lib.moonloader'
local id = -1

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('cfind', function(arg)
        if tonumber(arg) then
            id = tonumber(arg)
            local result, coords = getCarCoords(id)
            if result then
                placeWaypoint(coords[1], coords[2], coords[3])
            else
                sampAddChatMessage('Ошибка, машина вне зоны стрима', -1)
            end
        end
    end)
    while true do
        wait(0)
        if id ~= -1 then
            if wasKeyPressed(VK_Z) and not sampIsCursorActive() then
                local result, coords = getCarCoords(id)
                if result then
                    placeWaypoint(coords[1], coords[2], coords[3])
                else
                    sampAddChatMessage('Ошибка, машина вне зоны стрима', -1)
                end
            end
        end
    end
end

function getCarCoords(id)
    local coords = {0, 0, 0}
    local result, car = sampGetCarHandleBySampVehicleId(id)
    if result then
        coords = {getCarCoordinates(car)}
    end
    return result, coords
end
 
Последнее редактирование: