script_author('JustFedot')
script_name('[JF][Legal] Insurance Helper')
script_version('1.0.0')
require("moonloader")
require ("sampfuncs")
local f = require 'moonloader'.font_flag
local font = renderCreateFont('Arial', 15, f.BOLD + f.SHADOW)
local bass = require 'lib.bass'
local sampev = require("samp.events")
function addChat(a)
sampAddChatMessage('{ffa500}'..thisScript().name..'{ffffff}: '..a, -1)
end
local audioHandle
function initAudio()
if not doesFileExist('moonloader/resource/audio/'..thisScript().name..'/alert.mp3') then
addChat('Unable to find file alert.mp3')
error('Unable to find file alert.mp3')
end
audioHandle = bass.BASS_StreamCreateFile(false, 'moonloader/resource/audio/'..thisScript().name..'/alert.mp3', 0, 0, 0)
bass.BASS_ChannelSetAttribute(audioHandle, BASS_ATTRIB_VOL, 0.5)
bass.BASS_ChannelFlags(audioHandle, BASS_SAMPLE_LOOP, BASS_SAMPLE_LOOP)
end
function alert(state)
if state then
bass.BASS_ChannelPlay(audioHandle, true)
else
bass.BASS_ChannelStop(audioHandle)
end
end
local state = {
active = false,
}
local helpText =
[[{ffffff}Описание работы скрипта:
- {FFA500}Оповещение:{ffffff} При наличии игрока на пикапах
оформления страховок скрипт активирует уведомление и
звонок колокольчика.
{ffffff}Автор: {ffa500}JustFedot{ffffff}
Специально для: {80A6FF}blast.hk
]]
function main()
repeat wait(0) until isSampAvailable()
while not isSampLoaded() do wait(0) end
initAudio()
sampRegisterChatCommand('ins',function()
state.active = not state.active
if state.active and not checkInsuranceInterior() then
state.active = false
return addChat('{ff0000} Ошибка. {ffffff} Вы должны быть в {ffa500}интерьере страховой{ffffff}.')
end
addChat('Скрипт'..(state.active and '{99ff99} запущен{ffffff}.' or '{ff0000} остановлен{ffffff}.'))
end)
sampRegisterChatCommand('inshelp',function()
sampShowDialog(65535, thisScript().name..': Помощь',helpText,'Ок',nil,0)
addChat('Окошко помощи {99ff99} показано{ffffff}.')
end)
addChat('Загружен. Команда: {ffc0cb}/ins{ffffff}.')
addChat('Помощь: {ffc0cb}/inshelp{ffffff}.')
while true do wait(0)
local alert_state = bass.BASS_ChannelIsActive(audioHandle)==1
if state.active then
local isAlertNeeded = false
for _, char in ipairs(getAllChars()) do
if checkInsurancePlayers(char) then
isAlertNeeded = true
break
end
end
if alert_state ~= isAlertNeeded then
alert(isAlertNeeded)
end
local input = sampGetInputInfoPtr()
local input = getStructElement(input, 0x8, 4)
local PosX = getStructElement(input, 0x8, 4)
local PosY = getStructElement(input, 0xC, 4)
renderFontDrawText(font, '<{ffa500}'..thisScript().name..'{ffffff}>'..(isAlertNeeded and '\n{99ff99}Страховка {ffffff}на подходе.' or ''), PosX, select(2, getScreenResolution())/2, 0xFFFFFFFF, 0x90000000)
if not checkInsuranceInterior() then
state.active = false
addChat('{ff0000} Ошибка. {ffffff} Вы должны быть в {ffa500}интерьере страховой{ffffff}.')
end
else
if alert_state then
alert(false)
end
end
end
end
function checkInsuranceInterior()
for id = 0, 2048 do
if sampIs3dTextDefined(id) then
local text2, color2, posX2, posY2, posZ2, distance2, ignoreWalls2, player2, vehicle2 = sampGet3dTextInfoById(id)
if text2:find('Страхование имущества') then return true end
end
end
return false
end
function checkInsurancePlayers(handle)
if not doesCharExist(handle) then
return false
end
if handle == playerPed then
return false
end
if select(2, sampGetPlayerIdByCharHandle(handle)) == -1 then
return false
end
local x, y, z = getCharCoordinates(handle)
for id = 0, 2048 do
if sampIs3dTextDefined(id) then
local text, _, posX, posY, posZ = sampGet3dTextInfoById(id)
if text:find('Страхование имущества') and getDistanceBetweenCoords3d(x, y, z, posX, posY, posZ) <= 1.5 then
return true
end
end
end
return false
end
function onScriptTerminate(script, quit)
if script == thisScript() then
bass.BASS_StreamFree(audioHandle)
end
end