Как решить?

Izoolusman

Новичок
Автор темы
17
0
Версия MoonLoader
.027.0-preview
В чём проблема моей написанной херни? Данный курд, работает как надо только до момента когда доходит по оси х до 0, потом дистанция просто увеличивается и персонаж улетает хер знает куда.
lua:
function cord()
    lua_thread.create(positions)

end

function positions()
    freezeCharPosition(PLAYER_PED, true)

    local posx,posy,posz = -2701.7392578125, 556.87579345703, 16.617694854736
    local x,y,z = getCharCoordinates(PLAYER_PED)
    setCharCoordinatesNoOffset(PLAYER_PED, x, y, z-2)
    

    repeat
        local x,y,z = getCharCoordinates(PLAYER_PED)
        z = z-0.4
        setCharCoordinatesNoOffset(PLAYER_PED, x, y, z)
        print(x,y,z)
        wait(75)
    until z<-20
  
    repeat
        local x,y,z = getCharCoordinates(PLAYER_PED)
        xxx = posx-x
        dis = getDistanceBetweenCoords2d(x,posx)
        local angle = getHeadingFromVector2d(xxx)
        setCharHeading(PLAYER_PED, angle)
    
        local x, y, z = getOffsetFromCharInWorldCoords(PLAYER_PED, 0.0, 2.0, 0.0)
        
        setCharCoordinatesNoOffset(PLAYER_PED, x, y, z)
        print(dis,angle)
        print(posx,x)
        wait(55)
    until dis<1



end
 
Решение
Lua:
local sampev = require('lib.samp.events')
local speed = 1
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('tpm', function() lua_thread.create(tpm) end)
    sampRegisterChatCommand('tpmc', function() lua_thread.create(tpmc) end)
    wait(-1)
end
function tpm()
    local res, x, y, z = getTargetBlipCoordinates()
    tp = not tp
    if not res then sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Метка не найдена', 0xFFC000) tp = false return end
    while tp do wait(0)
        local res, x, y, z = getTargetBlipCoordinates()
        if res then
            local mX, mY, mZ = getCharCoordinates(PLAYER_PED)...

|| NN - NoName ||

Известный
1,049
638
Lua:
local sampev = require('lib.samp.events')
local speed = 1
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('tpm', function() lua_thread.create(tpm) end)
    sampRegisterChatCommand('tpmc', function() lua_thread.create(tpmc) end)
    wait(-1)
end
function tpm()
    local res, x, y, z = getTargetBlipCoordinates()
    tp = not tp
    if not res then sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Метка не найдена', 0xFFC000) tp = false return end
    while tp do wait(0)
        local res, x, y, z = getTargetBlipCoordinates()
        if res then
            local mX, mY, mZ = getCharCoordinates(PLAYER_PED)
            var_float_x = x - mX
            var_float_y = y - mY
            local heading = getHeadingFromVector2d(var_float_x, var_float_y)
            setCharHeading(PLAYER_PED, heading)
            local dist = getDistanceBetweenCoords2d(mX, mY, x, y)
            if dist > speed then
                var_x = mX + speed * math.sin(-math.rad(heading))
                var_y = mY + speed * math.cos(-math.rad(heading))
                setCharCoordinates(PLAYER_PED, var_x, var_y, mZ - 1)
            elseif dist <= speed then
                setCharCoordinates(PLAYER_PED, x, y, mZ)
                up()
                sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Збс, мы на месте.', 0xFFC000)
                tp = false
            end
        else
            sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Метка пропала. Скрипт отключён.', 0xFFC000)
            tp = false
        end
    end
end
function up()
    while tp do wait(0)
        local mX, mY, mZ = getCharCoordinates(PLAYER_PED)
        local res, x, y, z = getTargetBlipCoordinates()
        if res then
            local dist = getDistanceBetweenCoords3d(mX, mY, z, mX, mY, mZ)
            if mZ > z then
                if dist <= 2.5 then
                    setCharCoordinates(PLAYER_PED, mX, mY, z)
                    break
                else
                    setCharCoordinates(PLAYER_PED, mX, mY, mZ - 2)
                end
            elseif mZ < z then
                if dist <= 2.5 then
                    setCharCoordinates(PLAYER_PED, mX, mY, z)
                    break
                else
                    setCharCoordinates(PLAYER_PED, mX, mY, mZ + 2)
                end
            end
        else
            sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Метка пропала. Скрипт отключён.', 0xFFC000)
            tp = false
        end
    end
end

Это мой курд, который я хотел дописать. Но я ленивая жопа. Можешь посмотреть как он работает :) Он ещё не дописан, но летать уже может.

А именно твоя проблема, как я понял. Ты не правильно делаешь getHeadingFromVector2d.
 
  • Нравится
Реакции: Izoolusman

Izoolusman

Новичок
Автор темы
17
0
Lua:
local sampev = require('lib.samp.events')
local speed = 1
function main()
    if not isSampfuncsLoaded() or not isSampLoaded() then return end
    repeat wait(0) until isSampAvailable()
    sampRegisterChatCommand('tpm', function() lua_thread.create(tpm) end)
    sampRegisterChatCommand('tpmc', function() lua_thread.create(tpmc) end)
    wait(-1)
end
function tpm()
    local res, x, y, z = getTargetBlipCoordinates()
    tp = not tp
    if not res then sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Метка не найдена', 0xFFC000) tp = false return end
    while tp do wait(0)
        local res, x, y, z = getTargetBlipCoordinates()
        if res then
            local mX, mY, mZ = getCharCoordinates(PLAYER_PED)
            var_float_x = x - mX
            var_float_y = y - mY
            local heading = getHeadingFromVector2d(var_float_x, var_float_y)
            setCharHeading(PLAYER_PED, heading)
            local dist = getDistanceBetweenCoords2d(mX, mY, x, y)
            if dist > speed then
                var_x = mX + speed * math.sin(-math.rad(heading))
                var_y = mY + speed * math.cos(-math.rad(heading))
                setCharCoordinates(PLAYER_PED, var_x, var_y, mZ - 1)
            elseif dist <= speed then
                setCharCoordinates(PLAYER_PED, x, y, mZ)
                up()
                sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Збс, мы на месте.', 0xFFC000)
                tp = false
            end
        else
            sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Метка пропала. Скрипт отключён.', 0xFFC000)
            tp = false
        end
    end
end
function up()
    while tp do wait(0)
        local mX, mY, mZ = getCharCoordinates(PLAYER_PED)
        local res, x, y, z = getTargetBlipCoordinates()
        if res then
            local dist = getDistanceBetweenCoords3d(mX, mY, z, mX, mY, mZ)
            if mZ > z then
                if dist <= 2.5 then
                    setCharCoordinates(PLAYER_PED, mX, mY, z)
                    break
                else
                    setCharCoordinates(PLAYER_PED, mX, mY, mZ - 2)
                end
            elseif mZ < z then
                if dist <= 2.5 then
                    setCharCoordinates(PLAYER_PED, mX, mY, z)
                    break
                else
                    setCharCoordinates(PLAYER_PED, mX, mY, mZ + 2)
                end
            end
        else
            sampAddChatMessage('{FFFFFF}[{00DD00}TPM{FFFFFF}] - {FFC000}Метка пропала. Скрипт отключён.', 0xFFC000)
            tp = false
        end
    end
end

Это мой курд, который я хотел дописать. Но я ленивая жопа. Можешь посмотреть как он работает :) Он ещё не дописан, но летать уже может.

А именно твоя проблема, как я понял. Ты не правильно делаешь getHeadingFromVector2d.
Попробывал переделать, и всё-же проблема была в

local x, y, z = getOffsetFromCharInWorldCoords(PLAYER_PED, 0.0, 2.0, 0.0)

setCharCoordinatesNoOffset(PLAYER_PED, x, y, z)
Заменил на
var_x = mX + speed * math.sin(-math.rad(heading))
var_y = mY + speed * math.cos(-math.rad(heading))
setCharCoordinates(PLAYER_PED, var_x, var_y, mZ - 1) и всё заработало.
Хотя, до сих пор не очень понял различие(
 

|| NN - NoName ||

Известный
1,049
638
Попробывал переделать, и всё-же проблема была в

local x, y, z = getOffsetFromCharInWorldCoords(PLAYER_PED, 0.0, 2.0, 0.0)

setCharCoordinatesNoOffset(PLAYER_PED, x, y, z)
Заменил на
var_x = mX + speed * math.sin(-math.rad(heading))
var_y = mY + speed * math.cos(-math.rad(heading))
setCharCoordinates(PLAYER_PED, var_x, var_y, mZ - 1) и всё заработало.
Хотя, до сих пор не очень понял различие(
Проблема в getheading после 0 коорды он не правильно вычисляет. Как я понял.