- 12
- 0
Взгляните на скрипт, и назовите пару недочетов или просто отрефакторьте код
/killsound - [ON/OFF]
/killsoundvol - Громкость звука
/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
Вложения
Последнее редактирование: