Телепорт

cort

Активный
Автор темы
243
94
Версия MoonLoader
.026-beta
вот есть код:
Lua:
script_author('Cort_Quwin')

require "lib.moonloader"
require "lib.sampfuncs"
local sp = require "lib.samp.events"
local mod = import 'notifications.lua'

local ffi = require "ffi"
ffi.cdef[[
     void keybd_event(int keycode, int scancode, int flags, int extra);
]]

local coord_master = false

function main()
    while not isSampAvailable() do wait(200) end
    wait(1000)


    sampAddChatMessage("{00FF00}[Teleport]{ffffff} - Успешно загружен! ", -1)
    sampAddChatMessage("{00FF00}[Teleport]{ffffff} - Автор: Cort_Quwin", -1)


    sampRegisterChatCommand('th', teleport)


    while true do
        wait(0)

    end
end

function teleport()
    local result, x, y, z = getTargetBlipCoordinates()
    if result and not coord_master then
      lua_thread.create(function()
        coord_master = true
        sampAddChatMessage('{00ff00}[Teleport]{ffffff} - Телепортация начата', -1)
        freezeCharPosition(PLAYER_PED, true)
        CoordMaster(x, y, z, 3, 80)
        freezeCharPosition(PLAYER_PED, false)
        coord_master = false
        sampAddChatMessage('{00ff00}[Teleport]{ffffff} - Телепортация закончена', -1)
      end)
    end
end

 
function CoordMaster(px, py, pz, step, time)
    local x, y, z = getCharCoordinates(PLAYER_PED)
    local d = getDistanceBetweenCoords3d(px, py, pz, x, y, z)
    if d <= step then
      setCharCoordinates(PLAYER_PED, px, py, pz)
    else
      local dx, dy, dz = px - x, py - y, pz - z
      x = x + step / d * dx
      y = y + step / d * dy
      z = z + step / d * dz
      setCharCoordinates(PLAYER_PED, x, y, z)
      wait(time)
      CoordMaster(px, py, pz, step, time)
    end
  end

Смотрите, персонаж телепортируется, а мне нужно чтобы он стоял на месте, а потом телепортировался туда, где метка.

Типа визуал
 
Последнее редактирование:

yung milonov

Известный
1,028
531
вроде работает хаха
Lua:
script_author('Cort_Quwin')

require "lib.moonloader"
require "lib.sampfuncs"
local sp = require "lib.samp.events"

local ffi = require "ffi"
ffi.cdef[[
     void keybd_event(int keycode, int scancode, int flags, int extra);
]]

local coord_master = false

function main()
    while not isSampAvailable() do wait(200) end
    wait(1000)


    sampAddChatMessage("{00FF00}[Teleport]{ffffff} - Успешно загружен! ", -1)
    sampAddChatMessage("{00FF00}[Teleport]{ffffff} - Автор: Cort_Quwin", -1)


    sampRegisterChatCommand('th', teleport)


    while true do
        wait(0)

    end
end

function teleport()
    local result, x1, y1, z1 = getTargetBlipCoordinates()
    if result and not coord_master then
      lua_thread.create(function()
        x, y, z = getCharCoordinates(PLAYER_PED)
        coord_master = true
        sampAddChatMessage('{00ff00}[Teleport]{ffffff} - Телепортация начата', -1)
        freezeCharPosition(PLAYER_PED, true)
        CoordMaster(x1, y1, z1, 3, 80)
        freezeCharPosition(PLAYER_PED, false)
        coord_master = false
        sampAddChatMessage('{00ff00}[Teleport]{ffffff} - Телепортация закончена', -1)
      end)
    end
end

 
function CoordMaster(px, py, pz, step, time)
    -- local x, y, z = getCharCoordinates(PLAYER_PED)
    local d = getDistanceBetweenCoords3d(px, py, pz, x, y, z)
    if d <= step then
      setCharCoordinates(PLAYER_PED, px, py, pz)
    else
      local dx, dy, dz = px - x, py - y, pz - z
      x = x + step / d * dx
      y = y + step / d * dy
      z = z + step / d * dz
      -- setCharCoordinates(PLAYER_PED, x, y, z)
      local data = samp_create_sync_data("player")
      data.position = {x, y, z}
      data.send()
      wait(time)
      CoordMaster(px, py, pz, step, time)
    end
end

function sp.onSendPlayerSync(data)
    if coord_master then
        return false
    end
end

function samp_create_sync_data(sync_type, copy_from_player)
    local ffi = require 'ffi'
    local sampfuncs = require 'sampfuncs'
    -- from SAMP.Lua
    local raknet = require 'samp.raknet'
    require 'samp.synchronization'

    copy_from_player = copy_from_player or true
    local sync_traits = {
        player = {'PlayerSyncData', raknet.PACKET.PLAYER_SYNC, sampStorePlayerOnfootData},
        vehicle = {'VehicleSyncData', raknet.PACKET.VEHICLE_SYNC, sampStorePlayerIncarData},
        passenger = {'PassengerSyncData', raknet.PACKET.PASSENGER_SYNC, sampStorePlayerPassengerData},
        aim = {'AimSyncData', raknet.PACKET.AIM_SYNC, sampStorePlayerAimData},
        trailer = {'TrailerSyncData', raknet.PACKET.TRAILER_SYNC, sampStorePlayerTrailerData},
        unoccupied = {'UnoccupiedSyncData', raknet.PACKET.UNOCCUPIED_SYNC, nil},
        bullet = {'BulletSyncData', raknet.PACKET.BULLET_SYNC, nil},
        spectator = {'SpectatorSyncData', raknet.PACKET.SPECTATOR_SYNC, nil}
    }
    local sync_info = sync_traits[sync_type]
    local data_type = 'struct ' .. sync_info[1]
    local data = ffi.new(data_type, {})
    local raw_data_ptr = tonumber(ffi.cast('uintptr_t', ffi.new(data_type .. '*', data)))
    -- copy player's sync data to the allocated memory
    if copy_from_player then
        local copy_func = sync_info[3]
        if copy_func then
            local _, player_id
            if copy_from_player == true then
                _, player_id = sampGetPlayerIdByCharHandle(PLAYER_PED)
            else
                player_id = tonumber(copy_from_player)
            end
            copy_func(player_id, raw_data_ptr)
        end
    end
    -- function to send packet
    local func_send = function()
        local bs = raknetNewBitStream()
        raknetBitStreamWriteInt8(bs, sync_info[2])
        raknetBitStreamWriteBuffer(bs, raw_data_ptr, ffi.sizeof(data))
        raknetSendBitStreamEx(bs, sampfuncs.HIGH_PRIORITY, sampfuncs.UNRELIABLE_SEQUENCED, 1)
        raknetDeleteBitStream(bs)
    end
    -- metatable to access sync data and 'send' function
    local mt = {
        __index = function(t, index)
            return data[index]
        end,
        __newindex = function(t, index, value)
            data[index] = value
        end
    }
    return setmetatable({send = func_send}, mt)
end
 
  • Нравится
Реакции: Defuill и cort