require "lib.moonloader"
local samp = require('samp.events')
function samp.onSendPlayerSync()
if teleport then return false end
end
local teleport = false
function main()
if not isSampLoaded() or not isSampfuncsLoaded() then return end
while not isSampAvailable() do wait(100) end
sampRegisterChatCommand('tpgo', ttp)
sampRegisterChatCommand('tpgc', tpc)
while true do
wait(0)
end
end
local carfortp = {
478, 430, 446, 452, 453, 473, 472, 454, 484, 493, 595, 543, 605, 538, 433, 408, 601, 582, 546, 578, 554, 413, 422, 407, 456, 407, 570
}
function samp.onSendPlayerSync()
if teleport then return false end
end
function tpc(arg)
if teleport then return end
local posX, posY, posZ = getCharCoordinates(PLAYER_PED)
local res, x, y, z = SearchMarker(posX, posY, posZ)
if not res then return sampAddChatMessage('{FF0000}[Ошибка] {FFFFFF}Чекпоинт не найден', -1) end
arg = tonumber(arg)
if arg ~= nil then
requestCollision(x, y)
loadScene(x, y, z)
teleport = true
lua_thread.create(tp_proccess_started, arg, x, y, z)
return
end
local veh = FindVehicleForTp()
if veh == -1 then return sampAddChatMessage('{FF0000}[Ошибка] {FFFFFF}Машина не найдена', -1) end
requestCollision(x, y)
loadScene(x, y, z)
teleport = true
lua_thread.create(tp_proccess_started, veh, x, y, z)
end
function ttp(arg)
if teleport then return end
local res, x, y, z = getTargetBlipCoordinates()
if not res then return sampAddChatMessage('{FF0000}[Ошибка] {FFFFFF}Метка не найдена', -1) end
arg = tonumber(arg)
if arg ~= nil then
requestCollision(x, y)
loadScene(x, y, z)
teleport = true
lua_thread.create(tp_proccess_started, arg, x, y, getGroundZFor3dCoord(x, y, 999.0))
return
end
local veh = FindVehicleForTp()
if veh == -1 then return sampAddChatMessage('{FF0000}[Ошибка] {FFFFFF}Машина не найдена', -1) end
requestCollision(x, y)
loadScene(x, y, z)
teleport = true
lua_thread.create(tp_proccess_started, veh, x, y, getGroundZFor3dCoord(x, y, 999.0))
end
function tp_proccess_started(veh, x, y, z)
local res, hand = sampGetCarHandleBySampVehicleId(veh)
if not res then
teleport = false
sampAddChatMessage('{FF0000}[Ошибка] {FFFFFF}Телепорт отменён', -1)
return
end
lockPlayerControl(true)
local cx, cy, cz = getCharCoordinates(PLAYER_PED)
wait(200)
sendOnfootSync(cx, cy, cz, veh)
setCharCoordinates(PLAYER_PED, x, y, z)
sampForceOnfootSync()
sendOnfootSync(x, y, z, veh)
wait(1500)
--sendPassengerSync(x, y, z)
sendOnfootSync(x, y, z, 0)
teleport = false
sampAddChatMessage('{FF0000}[TP] {FFFFFF}Успешный телепорт', -1)
lockPlayerControl(false)
end
function FindVehicleForTp()
local x, y, z = getCharCoordinates(PLAYER_PED)
for i = 0, 2000 do
local res, veh = sampGetCarHandleBySampVehicleId(i)
if res then
local cx, cy, cz = getCarCoordinates(veh)
if getDistanceBetweenCoords3d(x, y, z, cx, cy, cz) < 200.0 then
for j = 1, #carfortp do
if isCarModel(veh, carfortp[j]) then
return i
end
end
end
end
end
return -1
end
function sendPassengerSync(x, y, z)
local _, myId = sampGetPlayerIdByCharHandle(PLAYER_PED)
local data = allocateMemory(63)
sampStorePlayerPassengerData(myId, data)
setStructFloatElement(data, 12, x, false)
setStructFloatElement(data, 16, y, false)
setStructFloatElement(data, 20, z, false)
setStructElement(data, 2, 1, 1, false)
sampSendPassengerData(data)
freeMemory(data)
end
function sendOnfootSync(x, y, z, veh)
local _, myId = sampGetPlayerIdByCharHandle(PLAYER_PED)
local data = allocateMemory(68)
sampStorePlayerOnfootData(myId, data)
setStructElement(data, 37, 1, 3, false)
setStructFloatElement(data, 6, x, false)
setStructFloatElement(data, 10, y, false)
setStructFloatElement(data, 14, z, false)
setStructElement(data, 62, 2, veh, false)
sampSendOnfootData(data)
freeMemory(data)
end
function SearchMarker(posX, posY, posZ)
local ret_posX = 0.0
local ret_posY = 0.0
local ret_posZ = 0.0
local isFind = false
for id = 0, 31 do
local MarkerStruct = 0
MarkerStruct = 0xC7F168 + id * 56
local MarkerPosX = representIntAsFloat(readMemory(MarkerStruct + 0, 4, false))
local MarkerPosY = representIntAsFloat(readMemory(MarkerStruct + 4, 4, false))
local MarkerPosZ = representIntAsFloat(readMemory(MarkerStruct + 8, 4, false))
if MarkerPosX ~= 0.0 or MarkerPosY ~= 0.0 or MarkerPosZ ~= 0.0 then
ret_posX = MarkerPosX
ret_posY = MarkerPosY
ret_posZ = MarkerPosZ
isFind = true
end
end
return isFind, ret_posX, ret_posY, ret_posZ
end