sampSendGiveDamage

Oki_Bern

Участник
Автор темы
240
6
Версия MoonLoader
Другое
Как сделать, чтобы с помощь функции sampSendGiveDamage() проходил урон с оружия, тестил и вот только с кулака урон идет, а когда ставлю дигл, то не робит, в чем проблемка может быть? код ниже
Код:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do wait(0)
        if isKeyDown(74) then
            local id = getNearPlayer()
            sampSendGiveDamage(id, 46.2, 24, 3)
        end
    end
end

function getNearPlayer()
    local id = -1
    local dist = 9999
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for k, v in ipairs(getAllChars()) do
        if v ~= PLAYER_PED then
            local px, py, pz = getCharCoordinates(v)
            local d = getDistanceBetweenCoords3d(x, y, z, px, py, pz)
            if isKeyDown(114) then
                setCharCoordinates(PLAYER_PED, px, py, pz)
            end
            if d < dist then
                dist, id = d, select(2,  sampGetPlayerIdByCharHandle(v))
            end
        end
    end
    return id
end
 
Последнее редактирование:
  • Нравится
Реакции: CastelloFAM
Решение
все работает, кроме этой строчки
человек с этим айди не в зоне стрима.
Делай вот так:
Lua:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do wait(0)
        if isKeyDown(74) then
            local id = getNearPlayer()
              sendBullet(id, 24)
            sampSendGiveDamage(id, 46.2, 24, 3)
        end
    end
end

function getNearPlayer()
    local id = -1
    local dist = 9999
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for k, v in ipairs(getAllChars()) do
        if v ~= PLAYER_PED then
            local px, py, pz = getCharCoordinates(v)
            local d = getDistanceBetweenCoords3d(x, y, z, px, py, pz)...

sazzas1978

Известный
133
125
Булет синхру отправь, перед отправкой демеджа.

Lua:
function sendBullet(playerId, weaponId)
    local data = samp_create_sync_data('bullet', false)
    data.targetType = 1
    data.targetId = playerId
    data.origin.x, data.origin.y, data.origin.z = getActiveCameraCoordinates()
    data.target.x, data.target.y, data.target.z = getCharCoordinates(select(2, sampGetCharHandleByPlayerId(playerId)))
    data.weaponId = weaponId
    data.send()
end
 
Последнее редактирование:

Oki_Bern

Участник
Автор темы
240
6
Булет синхру отправь, перед отправкой демеджа.

Lua:
function sendBullet(playerId, weaponId)
    local data = samp_create_sync_data('bullet', false)
    data.targetType = 1
    data.targetId = playerId
    data.origin.x, data.origin.y, data.origin.z = getActiveCameraCoordinates()
    data.target.x, data.target.y, data.target.z = getCharCoordinates(select(2, sampGetCharHandleByPlayerId(playerId)))
    data.weaponId = weaponId
    data.send()
end
типо вот так сделать?
Lua:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do wait(0)
        if isKeyDown(74) then
           sendBullet()
            local id = getNearPlayer()
            sampSendGiveDamage(id, 46.2, 24, 3)
        end
    end
end

function getNearPlayer()
    local id = -1
    local dist = 9999
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for k, v in ipairs(getAllChars()) do
        if v ~= PLAYER_PED then
            local px, py, pz = getCharCoordinates(v)
            local d = getDistanceBetweenCoords3d(x, y, z, px, py, pz)
            if isKeyDown(114) then
                setCharCoordinates(PLAYER_PED, px, py, pz)
            end
            if d < dist then
                dist, id = d, select(2,  sampGetPlayerIdByCharHandle(v))
            end
        end
    end
    return id
end
function sendBullet(playerId, weaponId)
    local data = samp_create_sync_data('bullet', false)
    data.targetType = 1
    data.targetId = playerId
    data.origin.x, data.origin.y, data.origin.z = getActiveCameraCoordinates()
    data.target.x, data.target.y, data.target.z = getCharCoordinates(select(2, sampGetCharHandleByPlayerId(playerId)))
    data.weaponId = weaponId
    data.send()
end
 

minxty

Известный
1,185
1,058
а можешь указать где именно нужно вставить аргументы, а то понять не могу
Когда вызываешь функцию, например вот так:
Lua:
sendBullet(123, 24) -- отправляем выстрел игроку с ид 123 оружием Deagle
а так же, тебе в скрипт нужно добавить данную функцию, без нее он будет крашится когда пытаешься ее вызвать
Lua:
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
 

sazzas1978

Известный
133
125
все работает, кроме этой строчки
человек с этим айди не в зоне стрима.
Делай вот так:
Lua:
function main()
    if not isSampLoaded() or not isSampfuncsLoaded() then return end
    while not isSampAvailable() do wait(100) end
    while true do wait(0)
        if isKeyDown(74) then
            local id = getNearPlayer()
              sendBullet(id, 24)
            sampSendGiveDamage(id, 46.2, 24, 3)
        end
    end
end

function getNearPlayer()
    local id = -1
    local dist = 9999
    local x, y, z = getCharCoordinates(PLAYER_PED)
    for k, v in ipairs(getAllChars()) do
        if v ~= PLAYER_PED then
            local px, py, pz = getCharCoordinates(v)
            local d = getDistanceBetweenCoords3d(x, y, z, px, py, pz)
            if isKeyDown(114) then
                setCharCoordinates(PLAYER_PED, px, py, pz)
            end
            if d < dist then
                dist, id = d, select(2,  sampGetPlayerIdByCharHandle(v))
            end
        end
    end
    return id
end
function sendBullet(playerId, weaponId)
    local data = samp_create_sync_data('bullet', false)
    data.targetType = 1
    data.targetId = playerId
    data.origin.x, data.origin.y, data.origin.z = getActiveCameraCoordinates()
    data.target.x, data.target.y, data.target.z = getCharCoordinates(select(2, sampGetCharHandleByPlayerId(playerId)))
    data.weaponId = weaponId
    data.send()
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