tp to checkpoint

Sam201

Известный
Автор темы
94
4
Версия MoonLoader
Другое
lua:
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("tpcp", function()
        teleport = not teleport
        if teleport then
            sampAddChatMessage("{2471A3}AutoCP{FFFFFF} has been {0FFF00}Enabled", -1)
        else
            sampAddChatMessage("{2471A3}AutoCP{FFFFFF} has been {FF0000}Disabled", -1)
        end
    end)
    while true do
        wait(1)
    end
end




function samp.onSendPlayerSync()
    if teleport then return false end
end


function tpcp(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}[Error] {FFFFFF}Checkpoint not found', -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

 requestCollision(x, y)
 loadScene(x, y, z)

 teleport = true and string.find(text, "Pickup the package at the marker (see checkpoint on radar).") then
 wait(120000)
 lua_thread.create(tp_proccess_started, x, y, z)
end


function tp_proccess_started(x, y, z)
        lockPlayerControl(true)

    local cx, cy, cz = getCharCoordinates(PLAYER_PED)
 
    wait(200)
 
    sendOnfootSync(cx, cy, cz)
    setCharCoordinates(PLAYER_PED, x, y, z)
    sampForceOnfootSync()
    sendOnfootSync(x, y, z)
    wait(1500)
    --sendPassengerSync(x, y, z)
    sendOnfootSync(x, y, z, 0)
 
    teleport=false
    sampAddChatMessage('{FF0000}[TP] {FFFFFF}Successful teleport', -1)
    lockPlayerControl(false)
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)
    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, 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
  localisFind=false
  for id = 0, 31 do
      localMarkerStruct = 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


can someone help me fix this? its supposed to teleport to checkpoint/red marker not race checkpoint only when string find wait 120000 msec then teleport -- teleport = true and string.find(text, "Pickup the package at the marker (see checkpoint on radar).")
then wait (120000)