Lua HQD

RoflanovOFF

Новичок
12
18
мама увидела, что я курю, обесточила мне комнату и отрезала оптоволокно
 
  • Нравится
Реакции: Rice.

Likonzak

Новичок
7
2
Здрасьте. Интересное решение зделать такое через raknet чтобы показывало у других игроков. А также использовать ffi чтобы показывало анимацию и еще зделать нормальную синхронизацию с сервером. Браво.
LUA:
script_name('HQD')
script_authors('Rice.', 'Neverlane')
script_version_number(1)
script_properties('work-in-pause')

local ffi = require('ffi')
local Vector3D = require('vector3d')
local getBonePosition = ffi.cast("int (__thiscall*)(void*, float*, int, bool)", 0x5E4280)
local as_action = require('moonloader').audiostream_state

local last_smoking = 0

function main()
    while not isSampAvailable() do wait(0) end
    sampAddChatMessage('« HQD » {ffffff}Активация: /hqd', 0x47cc85)
    sampRegisterChatCommand('hqd', create_hqd)
    wait(-1)
end

function create_hqd()
    math.randomseed(os.time())
    if last_smoking <= os.time() then
        sampSendChat("/me затянулся HQD'ой")
        create_notf('success', 'Успех', 'Вы затянулись')
        last_smoking = os.time() + 30
        lua_thread.create(function()
            attach_object(get_my_id(), 8, 19124, 6, Vector3D(0.075, 0.025, 0.025), 0.15)
            wait(1000)
            apply_animation(get_my_id(), 'GANGS', 'SMKCIG_PRTL')
            wait(1000)
            create_sound('smoke.mp3', 0.5)
            wait(3000)
            attach_object(get_my_id(), 9, 18710, 2, Vector3D(0, 0.5, -1.5), 1)
            wait(2000)
            if math.random(1, 10) == 1 then
                sampSendChat('/do Словил гарик.')
                create_notf('error', 'Неудача', 'Вы словили гарик')
                apply_animation(get_my_id(), 'CRACK', 'crckdeth2')
                create_sound('garik.mp3', 0.5)
            end
            wait(3000)
            remove_object(get_my_id(), 9)
            remove_object(get_my_id(), 8)
        end)
    else
        create_notf('info', 'Информация', 'Подождите ещё ' .. (last_smoking - os.time()) .. ' секунд(ы)')
    end
end

function create_sound(sound, volume)
    local path = getWorkingDirectory() .. '/HQD/' .. sound
    if doesFileExist(path) then
        local audio = loadAudioStream(path)
        setAudioStreamState(audio, as_action.PLAY)
        setAudioStreamVolume(audio, volume)
    end
end

function create_notf(type, title, text)
    local text ='window.executeEvent(\'event.notify.initialize\', `["' .. type .. '","' .. title ..'","' .. text ..'",3000]`);'

    local bs = raknetNewBitStream()

    raknetBitStreamWriteInt8(bs, 17)
    raknetBitStreamWriteInt32(bs, 0)

    raknetBitStreamWriteInt32(bs, #text)
    raknetBitStreamWriteString(bs, text)

    raknetBitStreamWriteInt32(bs, 255)

    raknetEmulPacketReceiveBitStream(220, bs)
    raknetDeleteBitStream(bs)
end

function get_my_id()
    return select(2, sampGetPlayerIdByCharHandle(PLAYER_PED))
end

function attach_object(player_id, index, object_model, bone, offset, scale)
    local bs = raknetNewBitStream()

    raknetBitStreamWriteInt16(bs, player_id) -- id player
    raknetBitStreamWriteInt32(bs, index) -- index
    raknetBitStreamWriteBool(bs, true) -- create
    raknetBitStreamWriteInt32(bs, object_model) -- model
    raknetBitStreamWriteInt32(bs, bone) -- bone

    -- offset
    raknetBitStreamWriteFloat(bs, offset.x)
    raknetBitStreamWriteFloat(bs, offset.y)
    raknetBitStreamWriteFloat(bs, offset.z)

    -- rotation
    for i = 1, 3 do raknetBitStreamWriteFloat(bs, 0) end

    -- scale
    for i = 1, 3 do raknetBitStreamWriteFloat(bs, scale) end

    -- color
    raknetBitStreamWriteInt32(bs, 0xFFFFFFFF)
    raknetBitStreamWriteInt32(bs, 0xFF8f8f8f)

    raknetEmulRpcReceiveBitStream(113, bs)
    raknetDeleteBitStream(bs)
end

function remove_object(player_id, slot)
    local bs = raknetNewBitStream()

    raknetBitStreamWriteInt16(bs, player_id) -- playerId
    raknetBitStreamWriteInt32(bs, slot) -- index
    raknetBitStreamWriteBool(bs,  false) -- create

    raknetEmulRpcReceiveBitStream(113, bs)
    raknetDeleteBitStream(bs)
end

function apply_animation(player_id, anim_lib, anim_name)
    local bs = raknetNewBitStream()

    raknetBitStreamWriteInt16(bs, player_id)
    
    raknetBitStreamWriteInt8(bs, #anim_lib)
    raknetBitStreamWriteString(bs, anim_lib)

    raknetBitStreamWriteInt8(bs, #anim_name)
    raknetBitStreamWriteString(bs, anim_name)

    raknetBitStreamWriteFloat(bs, 1.0)

    raknetBitStreamWriteBool(bs, false)

    raknetBitStreamWriteBool(bs, false)
    raknetBitStreamWriteBool(bs, false)

    raknetBitStreamWriteBool(bs, false)

    raknetBitStreamWriteInt32(bs, -1)

    raknetEmulRpcReceiveBitStream(86, bs)
    raknetDeleteBitStream(bs)
end

function clear_animation(player_id)
    local bs = raknetNewBitStream()

    raknetBitStreamWriteInt16(bs, player_id)

    raknetEmulRpcReceiveBitStream(87, bs)
    raknetDeleteBitStream(bs)
end

function onScriptTerminate(scr, quitGame)
    if scr == thisScript() then
        remove_object(get_my_id(), 9)
        remove_object(get_my_id(), 8)
        clear_animation(get_my_id())
    end
end
 
  • Влюблен
Реакции: MrCreepTon

exmoby

Миньон
706
460
А с каким вкусом жижка, и есть ли злоебучий холодок???
А так 10 раков лёгких из 10
 
  • Нравится
Реакции: NeverStu

chromiusj

Kommando-Leiteinheit Bioresonanztechnik-Replika
Модератор
5,510
3,840
Интересное решение зделать такое через raknet чтобы показывало у других игроков
1717612321817.png