Walk To Coords | Pls Help Me

Hossi_Bad

Участник
Автор темы
68
23
Hello

Please give me a lua code so that my character can walk normally to the positions I specified. And let this walk continue

(-2390.457, -325.112, 65.499)
(-2385.841, -330.648, 65.813)
(-2392.046, -339.928, 65.930)

I really need this code.
Thankful
 

VanoKLR

Известный
644
373
Lua:
local coord = {
    {-2390.457, -325.112, 65.499},
    {-2385.841, -330.648, 65.813},
    {-2392.046, -339.928, 65.930}
} -- an array with the coordinates you need

function main()
    while not isSampAvailable() do wait(0) end
        sampRegisterChatCommand("runPoint", function()
            runPoint = not runPoint
        end)


    while true do
        wait(0)
        if runPoint then
            for i, v in ipairs(coord) do -- going through all the coordinates
                runToPoint(v[1],v[2], runPoint, true) -- we set our function with the X and Y coordinates
            end
        end
    end
end

function runToPoint(tox, toy, bool, useRun) -- tox - position X = toy - position Y = bool run - not ran = useRun - Should I use running or not
    local x, y, z = getCharCoordinates(PLAYER_PED)
    local angle = getHeadingFromVector2d(tox - x, toy - y)
    local xAngle = math.random(-50, 50)/100
    setCameraPositionUnfixed(xAngle, math.rad(angle - 90))
    stopRun = false
    while bool and getDistanceBetweenCoords2d(x, y, tox, toy) > 0.8 do
        setGameKeyState(1, -255)
        if useRun then
            setGameKeyState(16, 1)
        end
        wait(1)
        x, y, z = getCharCoordinates(PLAYER_PED)
        angle = getHeadingFromVector2d(tox - x, toy - y)
        setCameraPositionUnfixed(xAngle, math.rad(angle - 90))
        if stopRun then
            stopRun = false
            break
        end
    end
end