Помогите, создание LUA возможно или невозможно?

eblastb

Новичок
Автор темы
2
0
Версия SA-MP
  1. 0.3.7 (R1)
  2. 0.3.7-R2
  3. 0.3.7-R3
  4. 0.3.7-R4
Привет. Что мне нужно знать, чтобы создать LUA, который позволяет, когда другой игрок стреляет в меня, его пуля проходит мимо меня? По сути, это отразило бы его удар. Возможно? Как?

Возможно ли также создать LUA, исключающий пули? То есть я со своей точки зрения вижу, как он стреляет, но не вижу пуль, вылетающих из его пистолета. Как можно было сделать что-то подобное?

---------------------------------------------

Hello. What do I have to know to make a LUA that makes it so that when another player shoots at me, his bullet passes by me? It would deflect his shot basically. It's possible? As?

Is it also possible to create a LUA which eliminates bullets? That is, from my perspective I see him shooting, but I don't see the bullets coming out of his gun. How could something like that be done?
 

zer0byt3.

Активный
160
49
I understand that you need a bullet mirror. If so, there will be an explanation of how to make it under the spoiler.
In order to make a bullet mirror, you need:
1. Make a check that you are being shot you:
2. Sending bullet data to attacker
3. Block bullet sync from attacker

At the bottom will be the finished code. (Partial)
Lua:
local sampevrequire, sampev = pcall(require, "lib.samp.events")
sampev.onBulletSync = function(playerId, data)
     if data.targetId == select(2, sampGetPlayerIdByCharHandle(PLAYER_PED)) then
        local bullet = samp_create_sync_data("bullet")
        bullet.bulletType = data.bulletType
        bullet.targetId = playerId
        bullet.origin = data.target
        bullet.target = data.origin
        bullet.center = data.center
        bullet.weaponId = data.weaponId
        bullet.send()
        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
 
  • Нравится
Реакции: хромиус)