хочу чтобы скрипт тпхал меня на точку, откуда я тпшнулся

egorglebov

Участник
Автор темы
50
4
Версия MoonLoader
.026-beta
Вообщем, пишу скрипт рванку. так вот, я не могу тпшнуться на точку, откуда я тпхнулся. Вот код
1:
local go_BOOM = false

local mx, my, mz = 0, 0, 0
local cx, cy, cz = 0, 0, 0


function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('ctp', function()
        local handle = findCarRadius(15)
        if handle ~= nil then
            go_BOOM = true
            warpCharIntoCar(PLAYER_PED, handle)
        end
    end)
    while true do
        wait(0)
        if go_BOOM then
            if isCharInAnyCar(PLAYER_PED) then
                setCarHealth(storeCarCharIsInNoSave(PLAYER_PED), 0)
                setCharCoordinates(mx, my, mz)
                go_BOOM = false
            end
        end
    end
end
function findCarRadius(radius)
    local log = {}
    for k, v in pairs(getAllVehicles()) do
        if doesVehicleExist(v) then
            local mx, my, mz = getCharCoordinates(PLAYER_PED)
            local cx, cy, cz = getCarCoordinates(v)
            local dist = getDistanceBetweenCoords3d(mx, my, mz, cx, cy, cz)
            if dist <= radius then
                table.insert(log, {v, dist})
            end
        end
    end
    if #log > 0 then
        table.sort(log, function(a, b) return (a[2] < b[2]) end)
        return log[1][1]
    end
    return nil
end
 
Решение
Привет, лучше, такое с помощью пакета реализовать.
Следующий код тпнет тебя для сервера в машину, после чего установит ей 0 HP и тпнет тебя назад на ноги:

Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('ctp', function()
        local handle = findCarRadius(15)
        if handle ~= nil then
            local carId = select(2, sampGetVehicleIdByCarHandle(handle)
            local x, y, z = getCarCoordinates(handle)
            local sync = samp_create_sync_data("vehicle")
            sync.vehicleId = carId
            sync.vehicleHealth = 0
            sync.position = {x, y, z}
            sync.send()
            setCarHealth(handle, 0)
            printString("Boom!", 400)
        end...

Yuriy Code

Известный
754
927
Привет, лучше, такое с помощью пакета реализовать.
Следующий код тпнет тебя для сервера в машину, после чего установит ей 0 HP и тпнет тебя назад на ноги:

Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('ctp', function()
        local handle = findCarRadius(15)
        if handle ~= nil then
            local carId = select(2, sampGetVehicleIdByCarHandle(handle)
            local x, y, z = getCarCoordinates(handle)
            local sync = samp_create_sync_data("vehicle")
            sync.vehicleId = carId
            sync.vehicleHealth = 0
            sync.position = {x, y, z}
            sync.send()
            setCarHealth(handle, 0)
            printString("Boom!", 400)
        end
    end)
    wait(-1)
end

function findCarRadius(radius)
    local log = {}
    for k, v in pairs(getAllVehicles()) do
        if doesVehicleExist(v) then
            local mx, my, mz = getCharCoordinates(PLAYER_PED)
            local cx, cy, cz = getCarCoordinates(v)
            local dist = getDistanceBetweenCoords3d(mx, my, mz, cx, cy, cz)
            if dist <= radius then
                table.insert(log, {v, dist})
            end
        end
    end
    if #log > 0 then
        table.sort(log, function(a, b) return (a[2] < b[2]) end)
        return log[1][1]
    end
    return nil
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
 
  • Нравится
Реакции: egorglebov

F0RQU1N and

Известный
1,310
495
Привет, лучше, такое с помощью пакета реализовать.
Следующий код тпнет тебя для сервера в машину, после чего установит ей 0 HP и тпнет тебя назад на ноги:

Lua:
function main()
    while not isSampAvailable() do wait(0) end
    sampRegisterChatCommand('ctp', function()
        local handle = findCarRadius(15)
        if handle ~= nil then
            local carId = select(2, sampGetVehicleIdByCarHandle(handle)
            local x, y, z = getCarCoordinates(handle)
            local sync = samp_create_sync_data("vehicle")
            sync.vehicleId = carId
            sync.vehicleHealth = 0
            sync.position = {x, y, z}
            sync.send()
            setCarHealth(handle, 0)
            printString("Boom!", 400)
        end
    end)
    wait(-1)
end

function findCarRadius(radius)
    local log = {}
    for k, v in pairs(getAllVehicles()) do
        if doesVehicleExist(v) then
            local mx, my, mz = getCharCoordinates(PLAYER_PED)
            local cx, cy, cz = getCarCoordinates(v)
            local dist = getDistanceBetweenCoords3d(mx, my, mz, cx, cy, cz)
            if dist <= radius then
                table.insert(log, {v, dist})
            end
        end
    end
    if #log > 0 then
        table.sort(log, function(a, b) return (a[2] < b[2]) end)
        return log[1][1]
    end
    return nil
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
зачем ты и в синхре 0 хп ставишь и гта функой? оно при взрыве всё равно само отправит, и не стоит фулл код скидывать
 

Yuriy Code

Известный
754
927
зачем ты и в синхре 0 хп ставишь и гта функой? оно при взрыве всё равно само отправит, и не стоит фулл код скидывать
Чтобы визуально тоже было 0 HP у машины для игрока.
Фулл код - чтобы человеку легче было.
 
  • Нравится
Реакции: egorglebov