rakbot bitstream проблема

profgold

Известный
Автор темы
30
1
Версия MoonLoader
.026-beta
Всем привет.
Пытаюсь переделать эту тему на VehicleSync, но почему-то изменения не вносятся в onSendVehicleSync(data)


Lua:
local vehicleSync = {
    read = function(bs, size)
        local bs = bitStreamInit(bs, size)
        local data = {quaternion = {}, position = {}, moveSpeed = {}}
        data.packedId = bitStreamReadByte(bs)
        data.vehicleID = bitStreamReadWord(bs)
        data.leftRightKeys = bitStreamReadWord(bs)
        data.upDownKeys = bitStreamReadWord(bs)
        data.keysData = bitStreamReadWord(bs)
        data.quaternion[1] = bitStreamReadFloat(bs)
        data.quaternion[2] = bitStreamReadFloat(bs)
        data.quaternion[3] = bitStreamReadFloat(bs)
        data.quaternion[4] = bitStreamReadFloat(bs)
        local position = {}
        data.position.x = bitStreamReadFloat(bs)
        data.position.y = bitStreamReadFloat(bs)
        data.position.z = bitStreamReadFloat(bs)
        local moveSpeed = {}
        data.moveSpeed.x = bitStreamReadFloat(bs)
        data.moveSpeed.y = bitStreamReadFloat(bs)
        data.moveSpeed.z = bitStreamReadFloat(bs)
        data.vehicleHealth = bitStreamReadFloat(bs)
        data.health = getHealth()
        data.weapon = getArmour()
        data.armor = getArmour()
        data.weapon = getWeapon()
        data.siren = bitStreamReadByte(bs)
        data.landing_gear_state = bitStreamReadByte(bs)
        data.trailer_id = bitStreamReadWord(bs)
        data.train_speed = bitStreamReadFloat(bs)
        return data
    end,
    write = function(bs, data,size)
        local bs = bitStreamNew()
        
        bitStreamWriteByte(bs, 200)
        bitStreamWriteWord(bs, getBotVehicle())
        bitStreamWriteWord(bs,data.leftRightKeys)
        bitStreamWriteWord(bs,data.upDownKeys)
        bitStreamWriteWord(bs,data.keys)
        bitStreamWriteFloat(bs,data.quaternion[1])
        bitStreamWriteFloat(bs,data.quaternion[2])
        bitStreamWriteFloat(bs, data.quaternion[3])
        bitStreamWriteFloat(bs,data.quaternion[4])
        bitStreamWriteFloat(bs,data.position.x)
        bitStreamWriteFloat(bs,data.position.y)
        bitStreamWriteFloat(bs,data.position.z)
        bitStreamWriteFloat(bs,data.moveSpeed.x)
        bitStreamWriteFloat(bs,data.moveSpeed.y)
        bitStreamWriteFloat(bs,data.moveSpeed.z)
        bitStreamWriteFloat(bs, getVehicle(getBotVehicle()).health)
        bitStreamWriteByte(bs, getHealth())
        bitStreamWriteByte(bs, getArmour())
        bitStreamWriteByte(bs, getWeapon())
        bitStreamWriteByte(bs, data.siren)
        bitStreamWriteByte(bs, data.landing_gear_state)
        bitStreamWriteWord(bs, data.trailer_id)
        bitStreamWriteFloat(bs, data.train_speed)
    end
}


function onSendPacket(pId, bs, size)
    if pId == 200 then
        if type(onSendVehicleSync) == 'function' then
            local data = vehicleSync.read(bs,size)
            local result = onSendVehicleSync(data)
            if result == nil then
                vehicleSync.write(bs,data,size)
            elseif result == false then
                return false
            else
                vehicleSync.write(bs,result,size)
            end
        end
    end
end

function onSendVehicleSync(data)

    if test_1 then
        data.keys = 87
        data.position.z = data.position.z + 15
        printLog('data.position.z '..data.position.z)
    end
    return data
end