Получить объект lua

Fluffy1560

Активный
Автор темы
280
34
Версия MoonLoader
.027.0-preview
Пацаны, я не могу понять, как получить объекты при включении команды?
lua:
local veh = {}
act = false
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
        while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand("testt", function() act = not act end)
        if act then
        end
    wait(-1)
end


if act then
for _, obj in pairs(getAllObjects()) do
    if getObjectModel(obj) == 864 then
        sampAddChatMessage("ep", -1)
    end
end
end
 
Решение
Так?
Lua:
local veh = {}

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand("testt", function()
        for _, obj in pairs(getAllObjects()) do
            if getObjectModel(obj) == 864 then
                sampAddChatMessage("ep", -1)
            end
        end
    end)
    wait(-1)
end

qdIbp

Автор темы
Проверенный
1,390
1,146
Так?
Lua:
local veh = {}

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand("testt", function()
        for _, obj in pairs(getAllObjects()) do
            if getObjectModel(obj) == 864 then
                sampAddChatMessage("ep", -1)
            end
        end
    end)
    wait(-1)
end
 
  • Нравится
Реакции: Fluffy1560

Fluffy1560

Активный
Автор темы
280
34
Так?
Lua:
local veh = {}

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand("testt", function()
        for _, obj in pairs(getAllObjects()) do
            if getObjectModel(obj) == 864 then
                sampAddChatMessage("ep", -1)
            end
        end
    end)
    wait(-1)
end
Пасиба большое

Так?
Lua:
local veh = {}

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand("testt", function()
        for _, obj in pairs(getAllObjects()) do
            if getObjectModel(obj) == 864 then
                sampAddChatMessage("ep", -1)
            end
        end
    end)
    wait(-1)
end
А как можно вызывать ее несколько раз, не через команду а через функцию например?
 
Последнее редактирование:

qdIbp

Автор темы
Проверенный
1,390
1,146
Lua:
local veh = {}

function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    while not isSampAvailable() do wait(100) end
        sampRegisterChatCommand("testt", fori)
    wait(-1)
end

function fori(arg)
    if #arg == 0 then arg = 1 end
    for i = 1, tonumber(arg) do
        for _, obj in pairs(getAllObjects()) do
            if getObjectModel(obj) == 864 then
                sampAddChatMessage("ep", -1)
            end
        end
    end
end
 
  • Нравится
Реакции: Fluffy1560