Как сделать активацию скрипта по кнопке

Beutoloth

Новичок
Автор темы
3
1
Как сделать чтобы этот скрипт при нажатии на M тепнулся к ModelID 19624

Lua:
function getObjectCoordinatesByModelID(mID)
    for i = 1, 1000 do
        obj = sampGetObjectHandleBySampId(i)
        if doesObjectExist(obj) then
            objModel = getObjectModel(obj)
            if objModel == mID then
                return getObjectCoordinates(obj)
            end
        end
    end
end

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('otp', function(arg)
        if tonumber(arg:match('(%d+)')) then
            _, oX, oY, oZ = getObjectCoordinatesByModelID(tonumber(arg:match('(%d+)')))
            if _ and isCharOnFoot(PLAYER_PED) then
                setCharCoordinates(PLAYER_PED, oX, oY, oZ)
            end
        end
    end)
    wait(-1)
end
 
  • Грустно
Реакции: qdIbp

qdIbp

Автор темы
Проверенный
1,394
1,150
Lua:
local coord = {
    ['x'] = 0,
    ['y'] = 0,
    ['z'] = 0
}

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('otp', function(arg)
        if tonumber(arg) then
            res, coord.x, coord.y, coord.z = getObjectCoordinatesByModelID(tonumber(arg))
            if res and isCharOnFoot(PLAYER_PED) then
                setCharCoordinates(PLAYER_PED, coord.x, coord.y, coord.z)
            end
        end
    end)
    while true do
        wait(0)
        if wasKeyPressed(77) then
            setCharCoordinates(PLAYER_PED, coord.x, coord.y, coord.z)
        end
    end
end
 

Beutoloth

Новичок
Автор темы
3
1
Lua:
local coord = {
    ['x'] = 0,
    ['y'] = 0,
    ['z'] = 0
}

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('otp', function(arg)
        if tonumber(arg) then
            res, coord.x, coord.y, coord.z = getObjectCoordinatesByModelID(tonumber(arg))
            if res and isCharOnFoot(PLAYER_PED) then
                setCharCoordinates(PLAYER_PED, coord.x, coord.y, coord.z)
            end
        end
    end)
    while true do
        wait(0)
        if wasKeyPressed(77) then
            setCharCoordinates(PLAYER_PED, coord.x, coord.y, coord.z)
        end
    end
end
Не работает, она не телепортирует к 19624 обьекту, я к нему в притык даже подходил, а она просто откидывает тебя

Я хочу чтобы я нажал на кнопку, а в зоне стрима он тепнулся к 19624 обьекту
 
  • Вау
Реакции: qdIbp

fokichevskiy

Активный
146
32
Lua:
require('lib.moonloader')


function getObjectCoordinatesByModelID(mID)
    for i = 1, 1000 do
        obj = sampGetObjectHandleBySampId(i)
        if doesObjectExist(obj) then
            objModel = getObjectModel(obj)
            if objModel == mID then
                return getObjectCoordinates(obj)
            end
        end
    end
end

function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('otp', function(arg)
        local result, oX, oY, oZ = getObjectCoordinatesByModelID(tonumber(arg))
        if result then
            setCharCoordinates(PLAYER_PED, oX, oY, oZ + 4)
        else
            sampAddChatMessage('не вижу такого объекта', -1)
        end
    end)
    while true do
        if wasKeyPressed(VK_M) then
            local result, oX, oY, oZ = getObjectCoordinatesByModelID(19624)
            if result then
                setCharCoordinates(PLAYER_PED, oX, oY, oZ + 3)
            else
                sampAddChatMessage('не вижу такого объекта', -1)
            end
        end
        wait(0)
    end
end

короче в команде с объектом делаешь tonumber(arg) и всё, далее получаешь result и координаты объекта и проверяешь на существование в зоне стрима(result). если он есть, то ты тепнешься, если нету, то в чат выведется sampAddChatMessage('не вижу такого объекта', -1). с нажатием всё также, только можно вместо id клавиши писать название, но придется в начале скрипта писать require('lib.moonloader')