Вопросы по Lua скриптингу

Общая тема для вопросов по разработке скриптов на языке программирования Lua, в частности под MoonLoader.
  • Задавая вопрос, убедитесь, что его нет в списке частых вопросов и что на него ещё не отвечали (воспользуйтесь поиском).
  • Поищите ответ в теме посвященной разработке Lua скриптов в MoonLoader
  • Отвечая, убедитесь, что ваш ответ корректен.
  • Старайтесь как можно точнее выразить мысль, а если проблема связана с кодом, то обязательно прикрепите его к сообщению, используя блок [code=lua]здесь мог бы быть ваш код[/code].
  • Если вопрос связан с MoonLoader-ом первым делом желательно поискать решение на wiki.

Частые вопросы

Как научиться писать скрипты? С чего начать?
Информация - Гайд - Всё о Lua скриптинге для MoonLoader(https://blast.hk/threads/22707/)
Как вывести текст на русском? Вместо русского текста у меня какие-то каракули.
Изменить кодировку файла скрипта на Windows-1251. В Atom: комбинация клавиш Ctrl+Shift+U, в Notepad++: меню Кодировки -> Кодировки -> Кириллица -> Windows-1251.
Как получить транспорт, в котором сидит игрок?
Lua:
local veh = storeCarCharIsInNoSave(PLAYER_PED)
Как получить свой id или id другого игрока?
Lua:
local _, id = sampGetPlayerIdByCharHandle(PLAYER_PED) -- получить свой ид
local _, id = sampGetPlayerIdByCharHandle(ped) -- получить ид другого игрока. ped - это хендл персонажа
Как проверить, что строка содержит какой-то текст?
Lua:
if string.find(str, 'текст', 1, true) then
-- строка str содержит "текст"
end
Как эмулировать нажатие игровой клавиши?
Lua:
local game_keys = require 'game.keys' -- где-нибудь в начале скрипта вне функции main

setGameKeyState(game_keys.player.FIREWEAPON, -1) -- будет сэмулировано нажатие клавиши атаки
Все иды клавиш находятся в файле moonloader/lib/game/keys.lua.
Подробнее о функции setGameKeyState здесь: lua - setgamekeystate | BlastHack — DEV_WIKI(https://www.blast.hk/wiki/lua:setgamekeystate)
Как получить id другого игрока, в которого целюсь я?
Lua:
local valid, ped = getCharPlayerIsTargeting(PLAYER_HANDLE) -- получить хендл персонажа, в которого целится игрок
if valid and doesCharExist(ped) then -- если цель есть и персонаж существует
  local result, id = sampGetPlayerIdByCharHandle(ped) -- получить samp-ид игрока по хендлу персонажа
  if result then -- проверить, прошло ли получение ида успешно
    -- здесь любые действия с полученным идом игрока
  end
end
Как зарегистрировать команду чата SAMP?
Lua:
-- До бесконечного цикла/задержки
sampRegisterChatCommand("mycommand", function (param)
     -- param будет содержать весь текст введенный после команды, чтобы разделить его на аргументы используйте string.match()
    sampAddChatMessage("MyCMD", -1)
end)
Крашит игру при вызове sampSendChat. Как это исправить?
Это происходит из-за бага в SAMPFUNCS, когда производится попытка отправки пакета определенными функциями изнутри события исходящих RPC и пакетов. Исправления для этого бага нет, но есть способ не провоцировать его. Вызов sampSendChat изнутри обработчика исходящих RPC/пакетов нужно обернуть в скриптовый поток с нулевой задержкой:
Lua:
function onSendRpc(id)
  -- крашит:
  -- sampSendChat('Send RPC: ' .. id)

  -- норм:
  lua_thread.create(function()
    wait(0)
    sampSendChat('Send RPC: ' .. id)
  end)
end
 
Последнее редактирование:

shadow80962

Известный
127
13
file:write(format("%s: /ban %s %d %s \n", admin, cheater_name, minute, reason))

Как можно записать еще это если с таким кодом я получаю

attempt to call global 'format' (a nil value)
 

deveeh

Новичок
22
6
Пожалуйста, подскажите адекватный и легкий в понимании гайд по автообновлению, пол вечера проебал на это обновление, ниче не сделал
 

Yatoro

Участник
74
30
как написать на lua отключение коллизии для машин (чтобы сквозь них проходить) по чат-команде для сампа
 

Dmitriy Makarov

25.05.2021
Проверенный
2,478
1,113
как написать на lua отключение коллизии для машин (чтобы сквозь них проходить) по чат-команде для сампа
Внизу код.

Пожалуйста, подскажите адекватный и легкий в понимании гайд по автообновлению, пол вечера проебал на это обновление, ниче не сделал
Это не подошло?
 

SpeN

Известный
139
27
как тут поменять клавишу на mouse5 вместо колеса?
 

Вложения

  • clickwarp.lua
    8.4 KB · Просмотры: 13
  • Влюблен
Реакции: GAMEBUS

NoName_001

Участник
152
20
Ты че тупой? чамп гуесса меньше смотреть надо и тестировать больше
Если установить imgui.Process = true, то все окна можно будет включать/выключать при помощи true/false соответственно
you are clown?
сделай это вне цикла бесконечного
также будет работать
+ постоянно запущенный процесс не есть хорошо
у меня были траблы с мышью при таком

как тут поменять клавишу на mouse5 вместо колеса?
1662021340856.png

вместо MBUTTON(средняя кнопка мыши) или LBUTTON(левая кнопка мыши) - XBUTTON1
1 - первая доп. клавиша мыши, ищи свою, пока не заработает
скорее всего 3 или 5
тестируй
 
Последнее редактирование:
  • Нравится
Реакции: SpeN

Smeruxa

Известный
1,301
682
у меня были траблы с мышью при таком
выключать курсор надо
+ постоянно запущенный процесс не есть хорошо
У тебя много фпс упадет от этого??

сделай это вне цикла бесконечного
также будет работать
Тогда к чему ты доебался? гений..

1662023792401.png
 

lorgon

Известный
657
268
Как это можно оптимизировать или заменить?
Это штука рисует что-то типо круга с радиальным градиентом
Lua:
function getPointOnCircle(x, y, radius, n, i)
    local x = math.cos(2 * math.pi * i / n) * radius + x
    local y = math.sin(2 * math.pi * i / n) * radius + y
    return x, y
end

function im.AddTriangleMulticolor(a, b, c, colorA, colorB, colorC)
    local draw = im.GetWindowDrawList()
    local uv = im.GetFontTexUvWhitePixel()
    draw:PrimReserve(3, 3)
    draw:PrimVtx(a, uv, colorA)
    draw:PrimVtx(b, uv, colorB)
    draw:PrimVtx(c, uv, colorC)
end

function im.AddRadialGradient(center, radius, n, col_in, col_out)
    for i = 0, n - 1 do
        local x, y = getPointOnCircle(center.x, center.y, radius, n, i)
        local x1, y1 = getPointOnCircle(center.x, center.y, radius, n, i + 1)
        im.AddTriangleMulticolor(im.ImVec2(x, y), im.ImVec2(x1, y1), center, col_out, col_out, col_in)
    end
end
f3f21875dba48806255a16e4f6994d7d.png
 

Ononimus

Потрачен
60
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Ребя т спасайте я непонимаю почему не работает имгуи хочу написать свой хелпер для имгуи но когда я пишу все правильно то ничего не происходит но если я качаю чейто зелпер с имгуи то все работает сейчас я кину код того что я делал а вы если сможите киньте мне тоже код но с исправлеными ошибками

ВОТ ДУМАЮ ВСЕМ ИЗВЕСТНО ИМГУИ:
require "lib.moonloader"

local keys = require "lib.vkeys"
local imgui1 = require 'imgui'

function imgui.OnDrawFrame()
    imgui.Begin("Start Imgui")
    imgui.Text("samp")
    imgui.End
end

function main()
    imgui.Process = true
end
 

XRLM

Известный
2,540
859
почему такая хуйня с кликварпом происходит и как пофиксить?
код:
Lua:
require "lib.moonloader"
require"lib.sampfuncs"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local Matrix3X3 = require "matrix3x3"
local Vector3D = require "vector3d"
key = require("vkeys")
ev = require("lib.samp.events")
main_window_state = imgui.ImBool(false)
clickwarp = imgui.ImBool(false)
keyToggle = VK_MBUTTON
keyApply = VK_LBUTTON
MAX_DISTANCE = 20.0
function ev.onClearPlayerAnimation(id)
    local _, id = sampGetPlayerIdByCharHandle(1)
    if _ and thread_tp then
        thread_tp:terminate()
        thread_tp = false
    end
end
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('test', test)
    imgui.Process = false
    initializeRender()
    while true do wait(0)
        if clickwarp.v then

            while isPauseMenuActive() do
                if cursorEnabled then
                  showCursor(false)
                end
                wait(100)
              end

            if isKeyDown(keyToggle) then
                cursorEnabled = not cursorEnabled
                showCursor(cursorEnabled)
                while isKeyDown(keyToggle) do wait(80) end
              end
                  
              if cursorEnabled then
                local mode = sampGetCursorMode()
                if mode == 0 then
                  showCursor(true)
                end
                local sx, sy = getCursorPos()
                local sw, sh = getScreenResolution()
                -- is cursor in game window bounds?
                if sx >= 0 and sy >= 0 and sx < sw and sy < sh then
                  local posX, posY, posZ = convertScreenCoordsToWorld3D(sx, sy, 700.0)
                  local camX, camY, camZ = getActiveCameraCoordinates()
                  -- search for the collision point
                  local result, colpoint = processLineOfSight(camX, camY, camZ, posX, posY, posZ, true, true, false, true, false, false, false)
                  if result and colpoint.entity ~= 0 then
                    local normal = colpoint.normal
                    local pos = Vector3D(colpoint.pos[1], colpoint.pos[2], colpoint.pos[3]) - (Vector3D(normal[1], normal[2], normal[3]) * 0.1)
                    local zOffset = 300
                    if normal[3] >= 0.5 then zOffset = 1 end
                    -- search for the ground position vertically down
                    local result, colpoint2 = processLineOfSight(pos.x, pos.y, pos.z + zOffset, pos.x, pos.y, pos.z - 0.3,
                      true, true, false, true, false, false, false)
                    if result then
                      pos = Vector3D(colpoint2.pos[1], colpoint2.pos[2], colpoint2.pos[3] + 1)
        
                      local curX, curY, curZ  = getCharCoordinates(playerPed)
                      local dist              = getDistanceBetweenCoords3d(curX, curY, curZ, pos.x, pos.y, pos.z)
                      local hoffs             = renderGetFontDrawHeight(font)
        
                      sy = sy - 2
                      sx = sx - 2
                      renderFontDrawText(font, string.format("%0.2fm", dist), sx, sy - hoffs, 0xEEEEEEEE)
        
                      local tpIntoCar = nil
                      if colpoint.entityType == 2 then
                        local car = getVehiclePointerHandle(colpoint.entity)
                        if doesVehicleExist(car) and (not isCharInAnyCar(playerPed) or storeCarCharIsInNoSave(playerPed) ~= car) then
                          displayVehicleName(sx, sy - hoffs * 2, getNameOfVehicleModel(getCarModel(car)))
                          local color = 0xAAFFFFFF
                          if isKeyDown(VK_RBUTTON) then
                            tpIntoCar = car
                            color = 0xFFFFFFFF
                          end
                          renderFontDrawText(font2, "Hold right mouse button to teleport into the car", sx, sy - hoffs * 3, color)
                        end
                      end
        
                      createPointMarker(pos.x, pos.y, pos.z)
        
                      -- teleport!
                      if isKeyDown(keyApply) then
                        if tpIntoCar then
                          if not jumpIntoCar(tpIntoCar) then
                            -- teleport to the car if there is no free seats
                            teleportPlayer(pos.x, pos.y, pos.z)
                          end
                        else
                          if isCharInAnyCar(playerPed) then
                            local norm = Vector3D(colpoint.normal[1], colpoint.normal[2], 0)
                            local norm2 = Vector3D(colpoint2.normal[1], colpoint2.normal[2], colpoint2.normal[3])
                            rotateCarAroundUpAxis(storeCarCharIsInNoSave(playerPed), norm2)
                            pos = pos - norm * 1.8
                            pos.z = pos.z - 0.8
                          end
                          teleportPlayer(pos.x, pos.y, pos.z)
                        end
                        removePointMarker()
        
                        while isKeyDown(keyApply) do wait(0) end
                        showCursor(false)
                      end
                    end
                  end
                end
              end
              wait(0)
              removePointMarker()
            
        end
    end
end
function test()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end
function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(100, 50), imgui.Cond.FirstUseEver)
        
        imgui.Begin('Test', main_window_state)
            if imgui.Checkbox(u8'Clickwarp', clickwarp) then end
        imgui.End()
    end
end

function initializeRender()
  font = renderCreateFont("Tahoma", 10, FCR_BOLD + FCR_BORDER)
  font2 = renderCreateFont("Arial", 8, FCR_ITALICS + FCR_BORDER)
end


--- Functions
function rotateCarAroundUpAxis(car, vec)
  local mat = Matrix3X3(getVehicleRotationMatrix(car))
  local rotAxis = Vector3D(mat.up:get())
  vec:normalize()
  rotAxis:normalize()
  local theta = math.acos(rotAxis:dotProduct(vec))
  if theta ~= 0 then
    rotAxis:crossProduct(vec)
    rotAxis:normalize()
    rotAxis:zeroNearZero()
    mat = mat:rotate(rotAxis, -theta)
  end
  setVehicleRotationMatrix(car, mat:get())
end

function readFloatArray(ptr, idx)
  return representIntAsFloat(readMemory(ptr + idx * 4, 4, false))
end

function writeFloatArray(ptr, idx, value)
  writeMemory(ptr + idx * 4, 4, representFloatAsInt(value), false)
end

function getVehicleRotationMatrix(car)
  local entityPtr = getCarPointer(car)
  if entityPtr ~= 0 then
    local mat = readMemory(entityPtr + 0x14, 4, false)
    if mat ~= 0 then
      local rx, ry, rz, fx, fy, fz, ux, uy, uz
      rx = readFloatArray(mat, 0)
      ry = readFloatArray(mat, 1)
      rz = readFloatArray(mat, 2)

      fx = readFloatArray(mat, 4)
      fy = readFloatArray(mat, 5)
      fz = readFloatArray(mat, 6)

      ux = readFloatArray(mat, 8)
      uy = readFloatArray(mat, 9)
      uz = readFloatArray(mat, 10)
      return rx, ry, rz, fx, fy, fz, ux, uy, uz
    end
  end
end

function setVehicleRotationMatrix(car, rx, ry, rz, fx, fy, fz, ux, uy, uz)
  local entityPtr = getCarPointer(car)
  if entityPtr ~= 0 then
    local mat = readMemory(entityPtr + 0x14, 4, false)
    if mat ~= 0 then
      writeFloatArray(mat, 0, rx)
      writeFloatArray(mat, 1, ry)
      writeFloatArray(mat, 2, rz)

      writeFloatArray(mat, 4, fx)
      writeFloatArray(mat, 5, fy)
      writeFloatArray(mat, 6, fz)

      writeFloatArray(mat, 8, ux)
      writeFloatArray(mat, 9, uy)
      writeFloatArray(mat, 10, uz)
    end
  end
end

function displayVehicleName(x, y, gxt)
  x, y = convertWindowScreenCoordsToGameScreenCoords(x, y)
  useRenderCommands(true)
  setTextWrapx(640.0)
  setTextProportional(true)
  setTextJustify(false)
  setTextScale(0.33, 0.8)
  setTextDropshadow(0, 0, 0, 0, 0)
  setTextColour(255, 255, 255, 230)
  setTextEdge(1, 0, 0, 0, 100)
  setTextFont(1)
  displayText(x, y, gxt)
end

function createPointMarker(x, y, z)
  pointMarker = createUser3dMarker(x, y, z + 0.3, 4)
end

function removePointMarker()
  if pointMarker then
    removeUser3dMarker(pointMarker)
    pointMarker = nil
  end
end

function getCarFreeSeat(car)
  if doesCharExist(getDriverOfCar(car)) then
    local maxPassengers = getMaximumNumberOfPassengers(car)
    for i = 0, maxPassengers do
      if isCarPassengerSeatFree(car, i) then
        return i
      end
      i = i+1
    end
    return nil -- no free seats
  else
    return nil -- driver seat
  end
end

function jumpIntoCar(car)
  if not isKeyDown(key.VK_LCONTROL) then
    for i=0,1999 do
        local _, c = sampGetCarHandleBySampVehicleId(i)
        if _ and car == c then
            thread_tp = lua_thread.create(function()
                sampSendEnterVehicle(i,false)
                wait(1000)
                if doesVehicleExist(car) then
                    warpCharIntoCar(playerPed, car)
                    thread_tp = nil
                end
            end)
            break
        end
    end -- driver seat
  else
  local seat = -1
  for i=0, getMaximumNumberOfPassengers(car) do
    if isCarPassengerSeatFree(car, i) then
        seat = i
    end
  end
    if seat == -1 then return false end   
    for i=0,1999 do
        local _, c = sampGetCarHandleBySampVehicleId(i)
        if _ and car == c then
            thread_tp = lua_thread.create(function()
                sampSendEnterVehicle(i,true)
                wait(1000)
                if doesVehicleExist(car) then
                    if seat ~= nil then
                        warpCharIntoCarAsPassenger(playerPed, car, seat) -- passenger seat
                        thread_tp = nil
                    end
                end
            end)
            break
        end
    end
  end
  --restoreCameraJumpcut()
  return true
end

function teleportPlayer(x, y, z)
  if isCharInAnyCar(playerPed) then
    setCharCoordinates(playerPed, x, y, z)
  end
  setCharCoordinatesDontResetAnim(playerPed, x, y, z)
end

function setCharCoordinatesDontResetAnim(char, x, y, z)
  if doesCharExist(char) then
    local ptr = getCharPointer(char)
    setEntityCoordinates(ptr, x, y, z)
  end
end

function setEntityCoordinates(entityPtr, x, y, z)
  if entityPtr ~= 0 then
    local matrixPtr = readMemory(entityPtr + 0x14, 4, false)
    if matrixPtr ~= 0 then
      local posPtr = matrixPtr + 0x30
      writeMemory(posPtr + 0, 4, representFloatAsInt(x), false) -- X
      writeMemory(posPtr + 4, 4, representFloatAsInt(y), false) -- Y
      writeMemory(posPtr + 8, 4, representFloatAsInt(z), false) -- Z
    end
  end
end

function showCursor(toggle)
  if toggle then
    sampSetCursorMode(CMODE_LOCKCAM)
  else
    sampToggleCursor(false)
  end
  cursorEnabled = toggle
end
 

Smeruxa

Известный
1,301
682
почему такая хуйня с кликварпом происходит и как пофиксить?
код:
Lua:
require "lib.moonloader"
require"lib.sampfuncs"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local Matrix3X3 = require "matrix3x3"
local Vector3D = require "vector3d"
key = require("vkeys")
ev = require("lib.samp.events")
main_window_state = imgui.ImBool(false)
clickwarp = imgui.ImBool(false)
keyToggle = VK_MBUTTON
keyApply = VK_LBUTTON
MAX_DISTANCE = 20.0
function ev.onClearPlayerAnimation(id)
    local _, id = sampGetPlayerIdByCharHandle(1)
    if _ and thread_tp then
        thread_tp:terminate()
        thread_tp = false
    end
end
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('test', test)
    imgui.Process = false
    initializeRender()
    while true do wait(0)
        if clickwarp.v then

            while isPauseMenuActive() do
                if cursorEnabled then
                  showCursor(false)
                end
                wait(100)
              end

            if isKeyDown(keyToggle) then
                cursorEnabled = not cursorEnabled
                showCursor(cursorEnabled)
                while isKeyDown(keyToggle) do wait(80) end
              end
             
              if cursorEnabled then
                local mode = sampGetCursorMode()
                if mode == 0 then
                  showCursor(true)
                end
                local sx, sy = getCursorPos()
                local sw, sh = getScreenResolution()
                -- is cursor in game window bounds?
                if sx >= 0 and sy >= 0 and sx < sw and sy < sh then
                  local posX, posY, posZ = convertScreenCoordsToWorld3D(sx, sy, 700.0)
                  local camX, camY, camZ = getActiveCameraCoordinates()
                  -- search for the collision point
                  local result, colpoint = processLineOfSight(camX, camY, camZ, posX, posY, posZ, true, true, false, true, false, false, false)
                  if result and colpoint.entity ~= 0 then
                    local normal = colpoint.normal
                    local pos = Vector3D(colpoint.pos[1], colpoint.pos[2], colpoint.pos[3]) - (Vector3D(normal[1], normal[2], normal[3]) * 0.1)
                    local zOffset = 300
                    if normal[3] >= 0.5 then zOffset = 1 end
                    -- search for the ground position vertically down
                    local result, colpoint2 = processLineOfSight(pos.x, pos.y, pos.z + zOffset, pos.x, pos.y, pos.z - 0.3,
                      true, true, false, true, false, false, false)
                    if result then
                      pos = Vector3D(colpoint2.pos[1], colpoint2.pos[2], colpoint2.pos[3] + 1)
   
                      local curX, curY, curZ  = getCharCoordinates(playerPed)
                      local dist              = getDistanceBetweenCoords3d(curX, curY, curZ, pos.x, pos.y, pos.z)
                      local hoffs             = renderGetFontDrawHeight(font)
   
                      sy = sy - 2
                      sx = sx - 2
                      renderFontDrawText(font, string.format("%0.2fm", dist), sx, sy - hoffs, 0xEEEEEEEE)
   
                      local tpIntoCar = nil
                      if colpoint.entityType == 2 then
                        local car = getVehiclePointerHandle(colpoint.entity)
                        if doesVehicleExist(car) and (not isCharInAnyCar(playerPed) or storeCarCharIsInNoSave(playerPed) ~= car) then
                          displayVehicleName(sx, sy - hoffs * 2, getNameOfVehicleModel(getCarModel(car)))
                          local color = 0xAAFFFFFF
                          if isKeyDown(VK_RBUTTON) then
                            tpIntoCar = car
                            color = 0xFFFFFFFF
                          end
                          renderFontDrawText(font2, "Hold right mouse button to teleport into the car", sx, sy - hoffs * 3, color)
                        end
                      end
   
                      createPointMarker(pos.x, pos.y, pos.z)
   
                      -- teleport!
                      if isKeyDown(keyApply) then
                        if tpIntoCar then
                          if not jumpIntoCar(tpIntoCar) then
                            -- teleport to the car if there is no free seats
                            teleportPlayer(pos.x, pos.y, pos.z)
                          end
                        else
                          if isCharInAnyCar(playerPed) then
                            local norm = Vector3D(colpoint.normal[1], colpoint.normal[2], 0)
                            local norm2 = Vector3D(colpoint2.normal[1], colpoint2.normal[2], colpoint2.normal[3])
                            rotateCarAroundUpAxis(storeCarCharIsInNoSave(playerPed), norm2)
                            pos = pos - norm * 1.8
                            pos.z = pos.z - 0.8
                          end
                          teleportPlayer(pos.x, pos.y, pos.z)
                        end
                        removePointMarker()
   
                        while isKeyDown(keyApply) do wait(0) end
                        showCursor(false)
                      end
                    end
                  end
                end
              end
              wait(0)
              removePointMarker()
       
        end
    end
end
function test()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end
function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(100, 50), imgui.Cond.FirstUseEver)
   
        imgui.Begin('Test', main_window_state)
            if imgui.Checkbox(u8'Clickwarp', clickwarp) then end
        imgui.End()
    end
end

function initializeRender()
  font = renderCreateFont("Tahoma", 10, FCR_BOLD + FCR_BORDER)
  font2 = renderCreateFont("Arial", 8, FCR_ITALICS + FCR_BORDER)
end


--- Functions
function rotateCarAroundUpAxis(car, vec)
  local mat = Matrix3X3(getVehicleRotationMatrix(car))
  local rotAxis = Vector3D(mat.up:get())
  vec:normalize()
  rotAxis:normalize()
  local theta = math.acos(rotAxis:dotProduct(vec))
  if theta ~= 0 then
    rotAxis:crossProduct(vec)
    rotAxis:normalize()
    rotAxis:zeroNearZero()
    mat = mat:rotate(rotAxis, -theta)
  end
  setVehicleRotationMatrix(car, mat:get())
end

function readFloatArray(ptr, idx)
  return representIntAsFloat(readMemory(ptr + idx * 4, 4, false))
end

function writeFloatArray(ptr, idx, value)
  writeMemory(ptr + idx * 4, 4, representFloatAsInt(value), false)
end

function getVehicleRotationMatrix(car)
  local entityPtr = getCarPointer(car)
  if entityPtr ~= 0 then
    local mat = readMemory(entityPtr + 0x14, 4, false)
    if mat ~= 0 then
      local rx, ry, rz, fx, fy, fz, ux, uy, uz
      rx = readFloatArray(mat, 0)
      ry = readFloatArray(mat, 1)
      rz = readFloatArray(mat, 2)

      fx = readFloatArray(mat, 4)
      fy = readFloatArray(mat, 5)
      fz = readFloatArray(mat, 6)

      ux = readFloatArray(mat, 8)
      uy = readFloatArray(mat, 9)
      uz = readFloatArray(mat, 10)
      return rx, ry, rz, fx, fy, fz, ux, uy, uz
    end
  end
end

function setVehicleRotationMatrix(car, rx, ry, rz, fx, fy, fz, ux, uy, uz)
  local entityPtr = getCarPointer(car)
  if entityPtr ~= 0 then
    local mat = readMemory(entityPtr + 0x14, 4, false)
    if mat ~= 0 then
      writeFloatArray(mat, 0, rx)
      writeFloatArray(mat, 1, ry)
      writeFloatArray(mat, 2, rz)

      writeFloatArray(mat, 4, fx)
      writeFloatArray(mat, 5, fy)
      writeFloatArray(mat, 6, fz)

      writeFloatArray(mat, 8, ux)
      writeFloatArray(mat, 9, uy)
      writeFloatArray(mat, 10, uz)
    end
  end
end

function displayVehicleName(x, y, gxt)
  x, y = convertWindowScreenCoordsToGameScreenCoords(x, y)
  useRenderCommands(true)
  setTextWrapx(640.0)
  setTextProportional(true)
  setTextJustify(false)
  setTextScale(0.33, 0.8)
  setTextDropshadow(0, 0, 0, 0, 0)
  setTextColour(255, 255, 255, 230)
  setTextEdge(1, 0, 0, 0, 100)
  setTextFont(1)
  displayText(x, y, gxt)
end

function createPointMarker(x, y, z)
  pointMarker = createUser3dMarker(x, y, z + 0.3, 4)
end

function removePointMarker()
  if pointMarker then
    removeUser3dMarker(pointMarker)
    pointMarker = nil
  end
end

function getCarFreeSeat(car)
  if doesCharExist(getDriverOfCar(car)) then
    local maxPassengers = getMaximumNumberOfPassengers(car)
    for i = 0, maxPassengers do
      if isCarPassengerSeatFree(car, i) then
        return i
      end
      i = i+1
    end
    return nil -- no free seats
  else
    return nil -- driver seat
  end
end

function jumpIntoCar(car)
  if not isKeyDown(key.VK_LCONTROL) then
    for i=0,1999 do
        local _, c = sampGetCarHandleBySampVehicleId(i)
        if _ and car == c then
            thread_tp = lua_thread.create(function()
                sampSendEnterVehicle(i,false)
                wait(1000)
                if doesVehicleExist(car) then
                    warpCharIntoCar(playerPed, car)
                    thread_tp = nil
                end
            end)
            break
        end
    end -- driver seat
  else
  local seat = -1
  for i=0, getMaximumNumberOfPassengers(car) do
    if isCarPassengerSeatFree(car, i) then
        seat = i
    end
  end
    if seat == -1 then return false end
    for i=0,1999 do
        local _, c = sampGetCarHandleBySampVehicleId(i)
        if _ and car == c then
            thread_tp = lua_thread.create(function()
                sampSendEnterVehicle(i,true)
                wait(1000)
                if doesVehicleExist(car) then
                    if seat ~= nil then
                        warpCharIntoCarAsPassenger(playerPed, car, seat) -- passenger seat
                        thread_tp = nil
                    end
                end
            end)
            break
        end
    end
  end
  --restoreCameraJumpcut()
  return true
end

function teleportPlayer(x, y, z)
  if isCharInAnyCar(playerPed) then
    setCharCoordinates(playerPed, x, y, z)
  end
  setCharCoordinatesDontResetAnim(playerPed, x, y, z)
end

function setCharCoordinatesDontResetAnim(char, x, y, z)
  if doesCharExist(char) then
    local ptr = getCharPointer(char)
    setEntityCoordinates(ptr, x, y, z)
  end
end

function setEntityCoordinates(entityPtr, x, y, z)
  if entityPtr ~= 0 then
    local matrixPtr = readMemory(entityPtr + 0x14, 4, false)
    if matrixPtr ~= 0 then
      local posPtr = matrixPtr + 0x30
      writeMemory(posPtr + 0, 4, representFloatAsInt(x), false) -- X
      writeMemory(posPtr + 4, 4, representFloatAsInt(y), false) -- Y
      writeMemory(posPtr + 8, 4, representFloatAsInt(z), false) -- Z
    end
  end
end

function showCursor(toggle)
  if toggle then
    sampSetCursorMode(CMODE_LOCKCAM)
  else
    sampToggleCursor(false)
  end
  cursorEnabled = toggle
end
попробуй заменить на мою функцию, проверь поможет ли, у меня там блок чтоб друг на друга не накладывалось.
P.s. цвета просто на 255 замени, а sw и sh - просто расширение экрана, getScreenResolution()
Lua:
function clickWarp()
    lua_thread.create(function()
        while true do
            if cursorEnabled then
                local mode = sampGetCursorMode()
                if mode == 0 then
                    showCursor(true)
                end
                local sx, sy = getCursorPos()
                local sw, sh = windowCoordinates[1], windowCoordinates[2]
                local color = join_argb(255, elements.colors.colorClickWarpText.r, elements.colors.colorClickWarpText.g, elements.colors.colorClickWarpText.b)
                if sx >= 0 and sy >= 0 and sx < sw and sy < sh then
                    local posX, posY, posZ = convertScreenCoordsToWorld3D(sx, sy, 700.0)
                    local camX, camY, camZ = getActiveCameraCoordinates()
                    local result, colpoint = processLineOfSight(camX, camY, camZ, posX, posY, posZ, true, true, false, true, false, false, false)
                    if result and colpoint.entity ~= 0 then
                        local normal = colpoint.normal
                        local pos = Vector3D(colpoint.pos[1], colpoint.pos[2], colpoint.pos[3]) - (Vector3D(normal[1], normal[2], normal[3]) * 0.1)
                        local zOffset = 300
                        if normal[3] >= 0.5 then zOffset = 1 end
                        local result, colpoint2 = processLineOfSight(pos.x, pos.y, pos.z + zOffset, pos.x, pos.y, pos.z - 0.3, true, true, false, true, false, false, false)
                        if result then
                            pos = Vector3D(colpoint2.pos[1], colpoint2.pos[2], colpoint2.pos[3] + 1)
                            local curX, curY, curZ  = getCharCoordinates(playerPed)
                            local dist              = getDistanceBetweenCoords3d(curX, curY, curZ, pos.x, pos.y, pos.z)
                            local hoffs             = renderGetFontDrawHeight(fonts.clickWarp)
                            sy = sy - 2
                            sx = sx - 2
                            renderFontDrawText(fonts.clickWarp, string.format("%0.2fm", dist), sx, sy - hoffs, color)
                            local tpIntoCar = nil
                            if colpoint.entityType == 2 then
                                local car = getVehiclePointerHandle(colpoint.entity)
                                if doesVehicleExist(car) and (not isCharInAnyCar(playerPed) or storeCarCharIsInNoSave(playerPed) ~= car) then
                                    displayVehicleName(sx, sy - hoffs * 2, getNameOfVehicleModel(getCarModel(car)))
                                    if isKeyDown(VK_RBUTTON) then
                                        tpIntoCar = car
                                    end
                                    renderFontDrawText(fonts.clickWarp, "Hold right mouse button to teleport into the car", sx, sy - hoffs * 3, color)
                                end
                            end
                            createPointMarker(pos.x, pos.y, pos.z)
                            if isKeyDown(VK_LBUTTON) then
                                if tpIntoCar then
                                    if not jumpIntoCar(tpIntoCar) then
                                        teleportPlayer(pos.x, pos.y, pos.z)
                                        local veh = storeCarCharIsInNoSave(playerPed)
                                        local cordsVeh = {getCarCoordinates(veh)}
                                        setCarCoordinates(veh, cordsVeh[1], cordsVeh[2], cordsVeh[3])
                                        cursorEnabled = false
                                        showCursor(false)
                                        removePointMarker()
                                        break
                                    end
                                else
                                    if isCharInAnyCar(playerPed) then
                                        local norm = Vector3D(colpoint.normal[1], colpoint.normal[2], 0)
                                        local norm2 = Vector3D(colpoint2.normal[1], colpoint2.normal[2], colpoint2.normal[3])
                                        rotateCarAroundUpAxis(storeCarCharIsInNoSave(playerPed), norm2)
                                        pos = pos - norm * 1.8
                                        pos.z = pos.z - 1.1
                                    end
                                    teleportPlayer(pos.x, pos.y, pos.z)
                                    cursorEnabled = false
                                    showCursor(false)
                                    removePointMarker()
                                    break
                                end
                                while isKeyDown(VK_LBUTTON) do wait(0) end
                                cursorEnabled = false
                                showCursor(false)
                                removePointMarker()
                                break
                            end
                        end
                    end
                end
            end
            wait(0)
            removePointMarker()
        end
        cursorEnabled = false
        showCursor(false)
        removePointMarker()
    end)
end
Функцию showCursor замени на эту
Lua:
function showCursor(toggle)
    if toggle then
        sampSetCursorMode(CMODE_LOCKCAM)
    else
        sampToggleCursor(false)
    end
end
Дефолтный вызов функции:
Lua:
  while isPauseMenuActive() do
                        if cursorEnabled then
                            showCursor(false)
                        end
                        wait(100)
                    end
                    if isKeyDown(VK_MBUTTON) then
                        cursorEnabled = not cursorEnabled
                        if elements.checkbox.setCursorInCenter.v then
                            ffi.C.SetCursorPos(windowCoordinates[1] / 2, windowCoordinates[2] / 2)
                        end
                        clickWarp()
                        showCursor(cursorEnabled)
                        while isKeyDown(VK_MBUTTON) do wait(80) end
                    end
 

XRLM

Известный
2,540
859
попробуй заменить на мою функцию, проверь поможет ли, у меня там блок чтоб друг на друга не накладывалось.
P.s. цвета просто на 255 замени, а sw и sh - просто расширение экрана, getScreenResolution()
Lua:
function clickWarp()
    lua_thread.create(function()
        while true do
            if cursorEnabled then
                local mode = sampGetCursorMode()
                if mode == 0 then
                    showCursor(true)
                end
                local sx, sy = getCursorPos()
                local sw, sh = windowCoordinates[1], windowCoordinates[2]
                local color = join_argb(255, elements.colors.colorClickWarpText.r, elements.colors.colorClickWarpText.g, elements.colors.colorClickWarpText.b)
                if sx >= 0 and sy >= 0 and sx < sw and sy < sh then
                    local posX, posY, posZ = convertScreenCoordsToWorld3D(sx, sy, 700.0)
                    local camX, camY, camZ = getActiveCameraCoordinates()
                    local result, colpoint = processLineOfSight(camX, camY, camZ, posX, posY, posZ, true, true, false, true, false, false, false)
                    if result and colpoint.entity ~= 0 then
                        local normal = colpoint.normal
                        local pos = Vector3D(colpoint.pos[1], colpoint.pos[2], colpoint.pos[3]) - (Vector3D(normal[1], normal[2], normal[3]) * 0.1)
                        local zOffset = 300
                        if normal[3] >= 0.5 then zOffset = 1 end
                        local result, colpoint2 = processLineOfSight(pos.x, pos.y, pos.z + zOffset, pos.x, pos.y, pos.z - 0.3, true, true, false, true, false, false, false)
                        if result then
                            pos = Vector3D(colpoint2.pos[1], colpoint2.pos[2], colpoint2.pos[3] + 1)
                            local curX, curY, curZ  = getCharCoordinates(playerPed)
                            local dist              = getDistanceBetweenCoords3d(curX, curY, curZ, pos.x, pos.y, pos.z)
                            local hoffs             = renderGetFontDrawHeight(fonts.clickWarp)
                            sy = sy - 2
                            sx = sx - 2
                            renderFontDrawText(fonts.clickWarp, string.format("%0.2fm", dist), sx, sy - hoffs, color)
                            local tpIntoCar = nil
                            if colpoint.entityType == 2 then
                                local car = getVehiclePointerHandle(colpoint.entity)
                                if doesVehicleExist(car) and (not isCharInAnyCar(playerPed) or storeCarCharIsInNoSave(playerPed) ~= car) then
                                    displayVehicleName(sx, sy - hoffs * 2, getNameOfVehicleModel(getCarModel(car)))
                                    if isKeyDown(VK_RBUTTON) then
                                        tpIntoCar = car
                                    end
                                    renderFontDrawText(fonts.clickWarp, "Hold right mouse button to teleport into the car", sx, sy - hoffs * 3, color)
                                end
                            end
                            createPointMarker(pos.x, pos.y, pos.z)
                            if isKeyDown(VK_LBUTTON) then
                                if tpIntoCar then
                                    if not jumpIntoCar(tpIntoCar) then
                                        teleportPlayer(pos.x, pos.y, pos.z)
                                        local veh = storeCarCharIsInNoSave(playerPed)
                                        local cordsVeh = {getCarCoordinates(veh)}
                                        setCarCoordinates(veh, cordsVeh[1], cordsVeh[2], cordsVeh[3])
                                        cursorEnabled = false
                                        showCursor(false)
                                        removePointMarker()
                                        break
                                    end
                                else
                                    if isCharInAnyCar(playerPed) then
                                        local norm = Vector3D(colpoint.normal[1], colpoint.normal[2], 0)
                                        local norm2 = Vector3D(colpoint2.normal[1], colpoint2.normal[2], colpoint2.normal[3])
                                        rotateCarAroundUpAxis(storeCarCharIsInNoSave(playerPed), norm2)
                                        pos = pos - norm * 1.8
                                        pos.z = pos.z - 1.1
                                    end
                                    teleportPlayer(pos.x, pos.y, pos.z)
                                    cursorEnabled = false
                                    showCursor(false)
                                    removePointMarker()
                                    break
                                end
                                while isKeyDown(VK_LBUTTON) do wait(0) end
                                cursorEnabled = false
                                showCursor(false)
                                removePointMarker()
                                break
                            end
                        end
                    end
                end
            end
            wait(0)
            removePointMarker()
        end
        cursorEnabled = false
        showCursor(false)
        removePointMarker()
    end)
end
Функцию showCursor замени на эту
Lua:
function showCursor(toggle)
    if toggle then
        sampSetCursorMode(CMODE_LOCKCAM)
    else
        sampToggleCursor(false)
    end
end
Дефолтный вызов функции:
Lua:
  while isPauseMenuActive() do
                        if cursorEnabled then
                            showCursor(false)
                        end
                        wait(100)
                    end
                    if isKeyDown(VK_MBUTTON) then
                        cursorEnabled = not cursorEnabled
                        if elements.checkbox.setCursorInCenter.v then
                            ffi.C.SetCursorPos(windowCoordinates[1] / 2, windowCoordinates[2] / 2)
                        end
                        clickWarp()
                        showCursor(cursorEnabled)
                        while isKeyDown(VK_MBUTTON) do wait(80) end
                    end
что за переменная elements? её нет, поэтому крашит скрипт
 

Uzkon

Участник
23
14
почему такая хуйня с кликварпом происходит и как пофиксить?
код:
Lua:
require "lib.moonloader"
require"lib.sampfuncs"
local imgui = require 'imgui'
local encoding = require 'encoding'
encoding.default = 'CP1251'
u8 = encoding.UTF8
local Matrix3X3 = require "matrix3x3"
local Vector3D = require "vector3d"
key = require("vkeys")
ev = require("lib.samp.events")
main_window_state = imgui.ImBool(false)
clickwarp = imgui.ImBool(false)
keyToggle = VK_MBUTTON
keyApply = VK_LBUTTON
MAX_DISTANCE = 20.0
function ev.onClearPlayerAnimation(id)
    local _, id = sampGetPlayerIdByCharHandle(1)
    if _ and thread_tp then
        thread_tp:terminate()
        thread_tp = false
    end
end
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    sampRegisterChatCommand('test', test)
    imgui.Process = false
    initializeRender()
    while true do wait(0)
        if clickwarp.v then

            while isPauseMenuActive() do
                if cursorEnabled then
                  showCursor(false)
                end
                wait(100)
              end

            if isKeyDown(keyToggle) then
                cursorEnabled = not cursorEnabled
                showCursor(cursorEnabled)
                while isKeyDown(keyToggle) do wait(80) end
              end
               
              if cursorEnabled then
                local mode = sampGetCursorMode()
                if mode == 0 then
                  showCursor(true)
                end
                local sx, sy = getCursorPos()
                local sw, sh = getScreenResolution()
                -- is cursor in game window bounds?
                if sx >= 0 and sy >= 0 and sx < sw and sy < sh then
                  local posX, posY, posZ = convertScreenCoordsToWorld3D(sx, sy, 700.0)
                  local camX, camY, camZ = getActiveCameraCoordinates()
                  -- search for the collision point
                  local result, colpoint = processLineOfSight(camX, camY, camZ, posX, posY, posZ, true, true, false, true, false, false, false)
                  if result and colpoint.entity ~= 0 then
                    local normal = colpoint.normal
                    local pos = Vector3D(colpoint.pos[1], colpoint.pos[2], colpoint.pos[3]) - (Vector3D(normal[1], normal[2], normal[3]) * 0.1)
                    local zOffset = 300
                    if normal[3] >= 0.5 then zOffset = 1 end
                    -- search for the ground position vertically down
                    local result, colpoint2 = processLineOfSight(pos.x, pos.y, pos.z + zOffset, pos.x, pos.y, pos.z - 0.3,
                      true, true, false, true, false, false, false)
                    if result then
                      pos = Vector3D(colpoint2.pos[1], colpoint2.pos[2], colpoint2.pos[3] + 1)
     
                      local curX, curY, curZ  = getCharCoordinates(playerPed)
                      local dist              = getDistanceBetweenCoords3d(curX, curY, curZ, pos.x, pos.y, pos.z)
                      local hoffs             = renderGetFontDrawHeight(font)
     
                      sy = sy - 2
                      sx = sx - 2
                      renderFontDrawText(font, string.format("%0.2fm", dist), sx, sy - hoffs, 0xEEEEEEEE)
     
                      local tpIntoCar = nil
                      if colpoint.entityType == 2 then
                        local car = getVehiclePointerHandle(colpoint.entity)
                        if doesVehicleExist(car) and (not isCharInAnyCar(playerPed) or storeCarCharIsInNoSave(playerPed) ~= car) then
                          displayVehicleName(sx, sy - hoffs * 2, getNameOfVehicleModel(getCarModel(car)))
                          local color = 0xAAFFFFFF
                          if isKeyDown(VK_RBUTTON) then
                            tpIntoCar = car
                            color = 0xFFFFFFFF
                          end
                          renderFontDrawText(font2, "Hold right mouse button to teleport into the car", sx, sy - hoffs * 3, color)
                        end
                      end
     
                      createPointMarker(pos.x, pos.y, pos.z)
     
                      -- teleport!
                      if isKeyDown(keyApply) then
                        if tpIntoCar then
                          if not jumpIntoCar(tpIntoCar) then
                            -- teleport to the car if there is no free seats
                            teleportPlayer(pos.x, pos.y, pos.z)
                          end
                        else
                          if isCharInAnyCar(playerPed) then
                            local norm = Vector3D(colpoint.normal[1], colpoint.normal[2], 0)
                            local norm2 = Vector3D(colpoint2.normal[1], colpoint2.normal[2], colpoint2.normal[3])
                            rotateCarAroundUpAxis(storeCarCharIsInNoSave(playerPed), norm2)
                            pos = pos - norm * 1.8
                            pos.z = pos.z - 0.8
                          end
                          teleportPlayer(pos.x, pos.y, pos.z)
                        end
                        removePointMarker()
     
                        while isKeyDown(keyApply) do wait(0) end
                        showCursor(false)
                      end
                    end
                  end
                end
              end
              wait(0)
              removePointMarker()
         
        end
    end
end
function test()
    main_window_state.v = not main_window_state.v
    imgui.Process = main_window_state.v
end
function imgui.OnDrawFrame()
    if not main_window_state.v then
        imgui.Process = false
    end
    if main_window_state.v then
        local sw, sh = getScreenResolution()
        imgui.SetNextWindowPos(imgui.ImVec2(sw / 2, sh / 2), imgui.Cond.FirstUseEver, imgui.ImVec2(0.5, 0.5))
        imgui.SetNextWindowSize(imgui.ImVec2(100, 50), imgui.Cond.FirstUseEver)
     
        imgui.Begin('Test', main_window_state)
            if imgui.Checkbox(u8'Clickwarp', clickwarp) then end
        imgui.End()
    end
end

function initializeRender()
  font = renderCreateFont("Tahoma", 10, FCR_BOLD + FCR_BORDER)
  font2 = renderCreateFont("Arial", 8, FCR_ITALICS + FCR_BORDER)
end


--- Functions
function rotateCarAroundUpAxis(car, vec)
  local mat = Matrix3X3(getVehicleRotationMatrix(car))
  local rotAxis = Vector3D(mat.up:get())
  vec:normalize()
  rotAxis:normalize()
  local theta = math.acos(rotAxis:dotProduct(vec))
  if theta ~= 0 then
    rotAxis:crossProduct(vec)
    rotAxis:normalize()
    rotAxis:zeroNearZero()
    mat = mat:rotate(rotAxis, -theta)
  end
  setVehicleRotationMatrix(car, mat:get())
end

function readFloatArray(ptr, idx)
  return representIntAsFloat(readMemory(ptr + idx * 4, 4, false))
end

function writeFloatArray(ptr, idx, value)
  writeMemory(ptr + idx * 4, 4, representFloatAsInt(value), false)
end

function getVehicleRotationMatrix(car)
  local entityPtr = getCarPointer(car)
  if entityPtr ~= 0 then
    local mat = readMemory(entityPtr + 0x14, 4, false)
    if mat ~= 0 then
      local rx, ry, rz, fx, fy, fz, ux, uy, uz
      rx = readFloatArray(mat, 0)
      ry = readFloatArray(mat, 1)
      rz = readFloatArray(mat, 2)

      fx = readFloatArray(mat, 4)
      fy = readFloatArray(mat, 5)
      fz = readFloatArray(mat, 6)

      ux = readFloatArray(mat, 8)
      uy = readFloatArray(mat, 9)
      uz = readFloatArray(mat, 10)
      return rx, ry, rz, fx, fy, fz, ux, uy, uz
    end
  end
end

function setVehicleRotationMatrix(car, rx, ry, rz, fx, fy, fz, ux, uy, uz)
  local entityPtr = getCarPointer(car)
  if entityPtr ~= 0 then
    local mat = readMemory(entityPtr + 0x14, 4, false)
    if mat ~= 0 then
      writeFloatArray(mat, 0, rx)
      writeFloatArray(mat, 1, ry)
      writeFloatArray(mat, 2, rz)

      writeFloatArray(mat, 4, fx)
      writeFloatArray(mat, 5, fy)
      writeFloatArray(mat, 6, fz)

      writeFloatArray(mat, 8, ux)
      writeFloatArray(mat, 9, uy)
      writeFloatArray(mat, 10, uz)
    end
  end
end

function displayVehicleName(x, y, gxt)
  x, y = convertWindowScreenCoordsToGameScreenCoords(x, y)
  useRenderCommands(true)
  setTextWrapx(640.0)
  setTextProportional(true)
  setTextJustify(false)
  setTextScale(0.33, 0.8)
  setTextDropshadow(0, 0, 0, 0, 0)
  setTextColour(255, 255, 255, 230)
  setTextEdge(1, 0, 0, 0, 100)
  setTextFont(1)
  displayText(x, y, gxt)
end

function createPointMarker(x, y, z)
  pointMarker = createUser3dMarker(x, y, z + 0.3, 4)
end

function removePointMarker()
  if pointMarker then
    removeUser3dMarker(pointMarker)
    pointMarker = nil
  end
end

function getCarFreeSeat(car)
  if doesCharExist(getDriverOfCar(car)) then
    local maxPassengers = getMaximumNumberOfPassengers(car)
    for i = 0, maxPassengers do
      if isCarPassengerSeatFree(car, i) then
        return i
      end
      i = i+1
    end
    return nil -- no free seats
  else
    return nil -- driver seat
  end
end

function jumpIntoCar(car)
  if not isKeyDown(key.VK_LCONTROL) then
    for i=0,1999 do
        local _, c = sampGetCarHandleBySampVehicleId(i)
        if _ and car == c then
            thread_tp = lua_thread.create(function()
                sampSendEnterVehicle(i,false)
                wait(1000)
                if doesVehicleExist(car) then
                    warpCharIntoCar(playerPed, car)
                    thread_tp = nil
                end
            end)
            break
        end
    end -- driver seat
  else
  local seat = -1
  for i=0, getMaximumNumberOfPassengers(car) do
    if isCarPassengerSeatFree(car, i) then
        seat = i
    end
  end
    if seat == -1 then return false end
    for i=0,1999 do
        local _, c = sampGetCarHandleBySampVehicleId(i)
        if _ and car == c then
            thread_tp = lua_thread.create(function()
                sampSendEnterVehicle(i,true)
                wait(1000)
                if doesVehicleExist(car) then
                    if seat ~= nil then
                        warpCharIntoCarAsPassenger(playerPed, car, seat) -- passenger seat
                        thread_tp = nil
                    end
                end
            end)
            break
        end
    end
  end
  --restoreCameraJumpcut()
  return true
end

function teleportPlayer(x, y, z)
  if isCharInAnyCar(playerPed) then
    setCharCoordinates(playerPed, x, y, z)
  end
  setCharCoordinatesDontResetAnim(playerPed, x, y, z)
end

function setCharCoordinatesDontResetAnim(char, x, y, z)
  if doesCharExist(char) then
    local ptr = getCharPointer(char)
    setEntityCoordinates(ptr, x, y, z)
  end
end

function setEntityCoordinates(entityPtr, x, y, z)
  if entityPtr ~= 0 then
    local matrixPtr = readMemory(entityPtr + 0x14, 4, false)
    if matrixPtr ~= 0 then
      local posPtr = matrixPtr + 0x30
      writeMemory(posPtr + 0, 4, representFloatAsInt(x), false) -- X
      writeMemory(posPtr + 4, 4, representFloatAsInt(y), false) -- Y
      writeMemory(posPtr + 8, 4, representFloatAsInt(z), false) -- Z
    end
  end
end

function showCursor(toggle)
  if toggle then
    sampSetCursorMode(CMODE_LOCKCAM)
  else
    sampToggleCursor(false)
  end
  cursorEnabled = toggle
end
Как я понял, проблема в мерцании текста и самого маркера?
У тебя же два раза wait(0) вначале цикла и до removePointMarker()
Если не решит проблему то хз, это единственное, наверно, что вызывает это.