local moonloader = require 'moonloader'
local encoding = require 'encoding'
encoding.default = 'CP1251'
local u8 = encoding.UTF8
local cw_active = false
local font = nil
local COLOR_LINE = 0xFF00FF00
local COLOR_BOX = 0xFFFF0000
local COLOR_TEXT = 0xFFFFFFFF
local COLOR_BG = 0x80000000
local function toCP1251(str)
return u8:decode(str)
end
local function drawBoxBorder(x, y, w, h, thickness, color)
renderDrawBox(x, y, w, thickness, color)
renderDrawBox(x, y + h - thickness, w, thickness, color)
renderDrawBox(x, y, thickness, h, color)
renderDrawBox(x + w - thickness, y, thickness, h, color)
end
local function getTarget3DPos()
local mx, my = getCursorPos()
local camX, camY, camZ = getActiveCameraCoordinates()
local farX, farY, farZ = convert2DCoordsToWorld3D(mx, my, 700.0)
local hit, x, y, z, entity = processLineOfSight(camX, camY, camZ, farX, farY, farZ, true, true, true, true, true, false, false, false)
if hit then
return true, x, y, z
end
return false, farX, farY, farZ
end
local function teleportTo(x, y, z)
local ped = PLAYER_PED
if isCharInAnyCar(ped) then
local car = storeCarCharIsInNoSave(ped)
setCarCoordinates(car, x, y, z + 1.2)
else
setCharCoordinates(ped, x, y, z + 1.2)
end
end
local function toggleClickWarp()
cw_active = not cw_active
showCursor(cw_active, cw_active)
if cw_active then
sampAddChatMessage(toCP1251("[ClickWarp]: {00FF00}Активирован. {FFFFFF}ЛКМ - Телепорт | ПКМ/ESC - Отмена"), 0x0088FF)
else
sampAddChatMessage(toCP1251("[ClickWarp]: {FF0000}Деактивирован"), 0x0088FF)
end
end
function renderClickWarp()
if not cw_active then return end
local ped = PLAYER_PED
if not doesCharExist(ped) then return end
local px, py, pz = getCharCoordinates(ped)
local hit, tx, ty, tz = getTarget3DPos()
local distance = getDistanceBetweenCoords3d(px, py, pz, tx, ty, tz)
if isPointOnScreen(tx, ty, tz, 0.0) then
local sx, sy = convert3DCoordsToScreen(tx, ty, tz)
local px_screen, py_screen = convert3DCoordsToScreen(px, py, pz)
if sx and sy then
if px_screen and py_screen then
renderDrawLine(px_screen, py_screen, sx, sy, 1.5, COLOR_LINE)
end
local box_size = 12
drawBoxBorder(sx - (box_size / 2), sy - (box_size / 2), box_size, box_size, 1.5, COLOR_BOX)
local info_str = string.format("TP (%.1f%s)", distance, toCP1251("м"))
if font then
local text_len = renderGetFontDrawTextLength(font, info_str)
renderDrawBox(sx - (text_len / 2) - 3, sy + 10, text_len + 6, 15, COLOR_BG)
renderFontDrawText(font, info_str, sx - (text_len / 2), sy + 10, COLOR_TEXT)
end
end
end
if isKeyJustPressed(moonloader.VK_LBUTTON) then
teleportTo(tx, ty, tz)
toggleClickWarp()
elseif isKeyJustPressed(moonloader.VK_RBUTTON) or isKeyJustPressed(moonloader.VK_ESCAPE) then
toggleClickWarp()
end
end
function main()
while not isSampAvailable() do wait(100) end
font = renderCreateFont("Arial", 9, 5)
sampRegisterChatCommand("cw", toggleClickWarp)
sampRegisterChatCommand("clickwarp", toggleClickWarp)
sampAddChatMessage(toCP1251("[ClickWarp]: Загружен. Активация: /cw или СКМ (колесико)"), 0x0088FF)
while true do
wait(0)
if isKeyJustPressed(moonloader.VK_MBUTTON) and not sampIsChatInputActive() and not sampIsDialogActive() then
toggleClickWarp()
end
renderClickWarp()
end
end