SA:MP Arizona [LUA] Kill_sound.lua / знатаки LUA-скриптингу, дайте пару советов

rgnrz.

Новичок
Автор темы
12
0
Взгляните на скрипт, и назовите пару недочетов или просто отрефакторьте код
/killsound - [ON/OFF]
/killsoundvol - Громкость звука

Lua:
script_name('KillSound')
script_author('AI')
script_description('Plays a sound when you kill an opponent')
script_version('1.1')

local inicfg = require('inicfg')
local config_path = 'config_kill_sound.ini'

local config = inicfg.load(nil, config_path) or {
    settings = {
        enabled = true,
        volume = 1.0
    }
}
inicfg.save(config, config_path)

local soundFile = 'moonloader/kill_sound.wav'
local isEnabled = config.settings.enabled

function playKillSound()
    if doesFileExist(soundFile) then
        local audio = loadAudioStream(soundFile)
        setAudioStreamVolume(audio, tonumber(config.settings.volume))
        setAudioStreamState(audio, 1)
    end
end

function onReceiveRpc(id, bs)
    if not isEnabled then return end
    if id == 55 then
        local killerID = raknetBitStreamReadInt16(bs)
        raknetBitStreamReadInt16(bs) -- victimID
        raknetBitStreamReadInt8(bs)  -- reason
        local _, myID = sampGetPlayerIdByCharHandle(PLAYER_PED)
        if killerID == myID then playKillSound() end
    end
end

function main()
    repeat wait(0) until isSampAvailable()

    sampRegisterChatCommand("killsound", function()
        isEnabled = not isEnabled
        config.settings.enabled = isEnabled
        inicfg.save(config, config_path)
        local msg = isEnabled and "enabled" or "disabled"
        sampAddChatMessage("[KillSound] Script is now " .. msg, 0xAAAAAA)
    end)

    sampRegisterChatCommand("killsoundvol", function(param)
        local vol = tonumber(param)
        if vol and vol >= 0.0 and vol <= 1.0 then
            config.settings.volume = vol
            inicfg.save(config, config_path)
            sampAddChatMessage(string.format("[KillSound] Volume set to %.2f", vol), 0xAAAAAA)
        else
            sampAddChatMessage("[KillSound] Usage: /killsoundvol [0.0 - 1.0]", 0xAAAAAA)
        end
    end)
end
 

Вложения

  • kill_sound.lua
    1.9 KB · Просмотры: 1
  • sound.rar
    16.8 KB · Просмотры: 3
Последнее редактирование:

Black_Cow

Активный
207
74
Взгляните на скрипт, и назовите пару недочетов или просто отрефакторьте код
/killsound - [ON/OFF]
/killsoundvol - Громкость звука

Lua:
script_name('KillSound')
script_author('AI')
script_description('Plays a sound when you kill an opponent')
script_version('1.1')

local inicfg = require('inicfg')
local config_path = 'config_kill_sound.ini'

local config = inicfg.load(nil, config_path) or {
    settings = {
        enabled = true,
        volume = 1.0
    }
}
inicfg.save(config, config_path)

local soundFile = 'moonloader/kill_sound.wav'
local isEnabled = config.settings.enabled

function playKillSound()
    if doesFileExist(soundFile) then
        local audio = loadAudioStream(soundFile)
        setAudioStreamVolume(audio, tonumber(config.settings.volume))
        setAudioStreamState(audio, 1)
    end
end

function onReceiveRpc(id, bs)
    if not isEnabled then return end
    if id == 55 then
        local killerID = raknetBitStreamReadInt16(bs)
        raknetBitStreamReadInt16(bs) -- victimID
        raknetBitStreamReadInt8(bs)  -- reason
        local _, myID = sampGetPlayerIdByCharHandle(PLAYER_PED)
        if killerID == myID then playKillSound() end
    end
end

function main()
    repeat wait(0) until isSampAvailable()

    sampRegisterChatCommand("killsound", function()
        isEnabled = not isEnabled
        config.settings.enabled = isEnabled
        inicfg.save(config, config_path)
        local msg = isEnabled and "enabled" or "disabled"
        sampAddChatMessage("[KillSound] Script is now " .. msg, 0xAAAAAA)
    end)

    sampRegisterChatCommand("killsoundvol", function(param)
        local vol = tonumber(param)
        if vol and vol >= 0.0 and vol <= 1.0 then
            config.settings.volume = vol
            inicfg.save(config, config_path)
            sampAddChatMessage(string.format("[KillSound] Volume set to %.2f", vol), 0xAAAAAA)
        else
            sampAddChatMessage("[KillSound] Usage: /killsoundvol [0.0 - 1.0]", 0xAAAAAA)
        end
    end)
end
Советую скачать гейм твикер и там врубить ugs, чем делать что-то через ИИ, сейчас тебе ИИ нормальный, рабочий скрипт не сделает на луа
 

rgnrz.

Новичок
Автор темы
12
0
Советую скачать гейм твикер и там врубить ugs, чем делать что-то через ИИ, сейчас тебе ИИ нормальный, рабочий скрипт не сделает на луа
я столкнулся с проблемой что gametweaker не работает с тенями, нужно удалять всякие фиксы, и бывает его сложно поставить даже на обычную сборку == потсоянно крашит
меня, самого заинтересовал скрипт звука когда убиваешь противника
вот и сделал что-то проще и для тех кому мб нужно будет

сам скрипт рабочий

Советую скачать гейм твикер и там врубить ugs, чем делать что-то через ИИ, сейчас тебе ИИ нормальный, рабочий скрипт не сделает на луа
попробовать всеровно стоит)
 
Последнее редактирование: