add sborka
This commit is contained in:
205
garrysmod/gamemodes/militaryrp/plugins/radio/cl_plugin.lua
Normal file
205
garrysmod/gamemodes/militaryrp/plugins/radio/cl_plugin.lua
Normal file
@@ -0,0 +1,205 @@
|
||||
local PLUGIN = PLUGIN
|
||||
|
||||
function PLUGIN:CreateRadioMenu()
|
||||
if (IsValid(self.radioMenu)) then
|
||||
self.radioMenu:Remove()
|
||||
end
|
||||
|
||||
local scrW, scrH = ScrW(), ScrH()
|
||||
|
||||
local frame = vgui.Create("DFrame")
|
||||
frame:SetSize(500, 200)
|
||||
frame:SetPos(scrW/2 - 250, scrH/2 - 100)
|
||||
frame:SetTitle("")
|
||||
frame:SetDraggable(false)
|
||||
frame:ShowCloseButton(false)
|
||||
frame:MakePopup()
|
||||
frame.Paint = function(panel, w, h)
|
||||
-- Фон
|
||||
surface.SetDrawColor(Color(13, 13, 13, 240))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
|
||||
-- Обводка
|
||||
surface.SetDrawColor(Color(1, 67, 29))
|
||||
surface.DrawOutlinedRect(0, 0, w, h, 2)
|
||||
|
||||
-- Верхняя панель
|
||||
surface.SetDrawColor(Color(1, 67, 29))
|
||||
surface.DrawRect(0, 0, w, 40)
|
||||
|
||||
-- Заголовок
|
||||
draw.SimpleText("НАСТРОЙКИ РАЦИИ", "ixMenuButtonFont", w/2, 20, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
end
|
||||
|
||||
self.radioMenu = frame
|
||||
|
||||
local currentFreq = self:GetFrequency(LocalPlayer())
|
||||
|
||||
local freqLabel = frame:Add("DLabel")
|
||||
freqLabel:SetPos(50, 60)
|
||||
freqLabel:SetSize(400, 25)
|
||||
freqLabel:SetText("Текущая частота: " .. currentFreq)
|
||||
freqLabel:SetFont("ixSmallFont")
|
||||
freqLabel:SetTextColor(color_white)
|
||||
|
||||
local freqSlider = frame:Add("DNumSlider")
|
||||
freqSlider:SetPos(-231, 90)
|
||||
freqSlider:SetSize(680, 40)
|
||||
freqSlider:SetText("")
|
||||
freqSlider:SetMin(self.minFrequency)
|
||||
freqSlider:SetMax(self.maxFrequency)
|
||||
freqSlider:SetDecimals(self.frequencyPrecision)
|
||||
freqSlider:SetValue(currentFreq)
|
||||
|
||||
-- Стилизация слайдера
|
||||
freqSlider.Slider.Paint = function(panel, w, h)
|
||||
surface.SetDrawColor(Color(23, 23, 23))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
surface.SetDrawColor(Color(1, 67, 29))
|
||||
surface.DrawOutlinedRect(0, 0, w, h, 1)
|
||||
|
||||
local progress = (freqSlider:GetValue() - freqSlider:GetMin()) / (freqSlider:GetMax() - freqSlider:GetMin())
|
||||
local barWidth = w * progress
|
||||
|
||||
surface.SetDrawColor(Color(1, 67, 29))
|
||||
surface.DrawRect(0, 0, barWidth, h)
|
||||
end
|
||||
|
||||
freqSlider.Label:SetTextColor(color_white)
|
||||
freqSlider.Label:SetFont("ixSmallFont")
|
||||
freqSlider.TextArea:SetTextColor(color_white)
|
||||
freqSlider.TextArea:SetFont("ixSmallFont")
|
||||
freqSlider.TextArea.Paint = function(panel, w, h)
|
||||
surface.SetDrawColor(Color(23, 23, 23))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
surface.SetDrawColor(Color(1, 67, 29))
|
||||
surface.DrawOutlinedRect(0, 0, w, h, 1)
|
||||
panel:DrawTextEntryText(color_white, Color(30, 130, 255), color_white)
|
||||
end
|
||||
|
||||
freqSlider.OnValueChanged = function(_, value)
|
||||
local format = "%0." .. PLUGIN.frequencyPrecision .. "f"
|
||||
freqLabel:SetText("Текущая частота: " .. string.format(format, value))
|
||||
end
|
||||
|
||||
-- Кнопка закрытия
|
||||
local closeBtn = frame:Add("DButton")
|
||||
closeBtn:SetPos(50, 150)
|
||||
closeBtn:SetSize(150, 35)
|
||||
closeBtn:SetText("")
|
||||
closeBtn.Paint = function(panel, w, h)
|
||||
surface.SetDrawColor(Color(1, 67, 29))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
surface.SetDrawColor(Color(29, 29, 29))
|
||||
surface.DrawOutlinedRect(0, 0, w, h, 2)
|
||||
draw.SimpleText("ЗАКРЫТЬ", "ixSmallFont", w/2, h/2, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
|
||||
if panel:IsHovered() then
|
||||
surface.SetDrawColor(Color(255, 255, 255, 30))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
end
|
||||
end
|
||||
closeBtn.DoClick = function()
|
||||
frame:Remove()
|
||||
end
|
||||
|
||||
-- Кнопка применения
|
||||
local applyBtn = frame:Add("DButton")
|
||||
applyBtn:SetPos(300, 150)
|
||||
applyBtn:SetSize(150, 35)
|
||||
applyBtn:SetText("")
|
||||
applyBtn.Paint = function(panel, w, h)
|
||||
surface.SetDrawColor(Color(1, 67, 29))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
surface.SetDrawColor(Color(29, 29, 29))
|
||||
surface.DrawOutlinedRect(0, 0, w, h, 2)
|
||||
draw.SimpleText("ПРИМЕНИТЬ", "ixSmallFont", w/2, h/2, color_white, TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
|
||||
|
||||
if panel:IsHovered() then
|
||||
surface.SetDrawColor(Color(255, 255, 255, 30))
|
||||
surface.DrawRect(0, 0, w, h)
|
||||
end
|
||||
end
|
||||
applyBtn.DoClick = function()
|
||||
net.Start("ixRadioSetFrequency")
|
||||
net.WriteFloat(freqSlider:GetValue())
|
||||
net.SendToServer()
|
||||
|
||||
frame:Remove()
|
||||
|
||||
-- Уведомление об успешном применении
|
||||
LocalPlayer():Notify("Частота рации изменена на: " .. string.format("%0." .. PLUGIN.frequencyPrecision .. "f", freqSlider:GetValue()))
|
||||
end
|
||||
end
|
||||
|
||||
-- Комбинации клавиш отключены - используйте Context Menu (C) для управления рацией
|
||||
--[[
|
||||
local lastPress = {
|
||||
listen = 0,
|
||||
transmit = 0,
|
||||
menu = 0
|
||||
}
|
||||
local pressCooldown = 0.2
|
||||
|
||||
hook.Add("PlayerButtonDown", "ixRadioBinds", function(ply, button)
|
||||
if (ply != LocalPlayer()) then
|
||||
return
|
||||
end
|
||||
|
||||
if (vgui.GetKeyboardFocus()) then
|
||||
return
|
||||
end
|
||||
|
||||
local ct = CurTime()
|
||||
|
||||
if (button == KEY_F2) then
|
||||
if (ct - lastPress.menu < pressCooldown) then
|
||||
return
|
||||
end
|
||||
|
||||
lastPress.menu = ct
|
||||
PLUGIN:CreateRadioMenu()
|
||||
elseif if (button == KEY_O and input.IsKeyDown(KEY_LSHIFT)) then
|
||||
if (ct - lastPress.listen < pressCooldown) then
|
||||
return
|
||||
end
|
||||
|
||||
lastPress.listen = ct
|
||||
|
||||
net.Start("ixRadioToggleListen")
|
||||
net.SendToServer()
|
||||
|
||||
-- Уведомление о переключении режима прослушивания
|
||||
local status = ix.plugin.list["radio"]:IsListening(LocalPlayer()) and "включено" or "выключено"
|
||||
LocalPlayer():Notify("Прослушивание рации " .. status)
|
||||
elseif (button == KEY_P and input.IsKeyDown(KEY_LSHIFT)) then
|
||||
if (ct - lastPress.transmit < pressCooldown) then
|
||||
return
|
||||
end
|
||||
|
||||
lastPress.transmit = ct
|
||||
|
||||
net.Start("ixRadioToggleTransmit")
|
||||
net.SendToServer()
|
||||
|
||||
-- Уведомление о переключении режима передачи
|
||||
local status = ix.plugin.list["radio"]:IsTransmitting(LocalPlayer()) and "включена" or "выключена"
|
||||
LocalPlayer():Notify("Передача рации " .. status)
|
||||
end
|
||||
end)
|
||||
--]]
|
||||
|
||||
-- Команды для биндов
|
||||
concommand.Add("radio_menu", function()
|
||||
PLUGIN:CreateRadioMenu()
|
||||
end)
|
||||
|
||||
concommand.Add("radio_listen", function()
|
||||
net.Start("ixRadioToggleListen")
|
||||
net.SendToServer()
|
||||
end)
|
||||
|
||||
concommand.Add("radio_transmit", function()
|
||||
net.Start("ixRadioToggleTransmit")
|
||||
net.SendToServer()
|
||||
end)
|
||||
24
garrysmod/gamemodes/militaryrp/plugins/radio/sh_plugin.lua
Normal file
24
garrysmod/gamemodes/militaryrp/plugins/radio/sh_plugin.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local PLUGIN = PLUGIN
|
||||
PLUGIN.name = "Radio"
|
||||
PLUGIN.author = "RefoselTeamWork"
|
||||
PLUGIN.description = "Provides configurable radio communication."
|
||||
PLUGIN.defaultFrequency = 100.0
|
||||
PLUGIN.minFrequency = 30.0
|
||||
PLUGIN.maxFrequency = 900.0
|
||||
PLUGIN.frequencyPrecision = 3
|
||||
PLUGIN.frequencyTolerance = 0.001
|
||||
|
||||
ix.util.Include("sv_plugin.lua")
|
||||
ix.util.Include("cl_plugin.lua")
|
||||
|
||||
function PLUGIN:GetFrequency(client)
|
||||
return client:GetNetVar("radioFrequency", self.defaultFrequency)
|
||||
end
|
||||
|
||||
function PLUGIN:IsListening(client)
|
||||
return client:GetNetVar("radioListen", true)
|
||||
end
|
||||
|
||||
function PLUGIN:IsTransmitting(client)
|
||||
return client:GetNetVar("radioTransmit", true)
|
||||
end
|
||||
151
garrysmod/gamemodes/militaryrp/plugins/radio/sv_plugin.lua
Normal file
151
garrysmod/gamemodes/militaryrp/plugins/radio/sv_plugin.lua
Normal file
@@ -0,0 +1,151 @@
|
||||
local PLUGIN = PLUGIN
|
||||
util.AddNetworkString("ixRadioSetFrequency")
|
||||
util.AddNetworkString("ixRadioToggleListen")
|
||||
util.AddNetworkString("ixRadioToggleTransmit")
|
||||
|
||||
function PLUGIN:SyncRadioState(client, frequency, listen, transmit)
|
||||
local character = client:GetCharacter()
|
||||
|
||||
if (!character) then
|
||||
return
|
||||
end
|
||||
|
||||
frequency = math.Round(math.Clamp(frequency or self.defaultFrequency, self.minFrequency, self.maxFrequency), self.frequencyPrecision)
|
||||
listen = listen and true or false
|
||||
transmit = transmit and true or false
|
||||
|
||||
if (!listen) then
|
||||
transmit = false
|
||||
end
|
||||
|
||||
character:SetData("radioFrequency", frequency)
|
||||
character:SetData("radioListen", listen)
|
||||
character:SetData("radioTransmit", transmit)
|
||||
|
||||
client:SetNetVar("radioFrequency", frequency)
|
||||
client:SetNetVar("radioListen", listen)
|
||||
client:SetNetVar("radioTransmit", transmit)
|
||||
end
|
||||
|
||||
function PLUGIN:PlayerLoadedCharacter(client, character, lastChar)
|
||||
local frequency = character:GetData("radioFrequency", self.defaultFrequency)
|
||||
|
||||
-- Force radio to be OFF after reconnect or character load
|
||||
local listen = false
|
||||
local transmit = false
|
||||
|
||||
self:SyncRadioState(client, frequency, listen, transmit)
|
||||
end
|
||||
|
||||
net.Receive("ixRadioSetFrequency", function(_, client)
|
||||
local character = client:GetCharacter()
|
||||
if client:IsAdminMode() then return end
|
||||
|
||||
if (!character) then
|
||||
return
|
||||
end
|
||||
|
||||
local frequency = net.ReadFloat()
|
||||
|
||||
if (!isnumber(frequency)) then
|
||||
return
|
||||
end
|
||||
|
||||
frequency = math.Round(math.Clamp(frequency, PLUGIN.minFrequency, PLUGIN.maxFrequency), PLUGIN.frequencyPrecision)
|
||||
|
||||
local listen = character:GetData("radioListen", true)
|
||||
local transmit = character:GetData("radioTransmit", true)
|
||||
|
||||
if (!listen) then
|
||||
transmit = false
|
||||
end
|
||||
|
||||
PLUGIN:SyncRadioState(client, frequency, listen, transmit)
|
||||
|
||||
local format = "%0." .. PLUGIN.frequencyPrecision .. "f"
|
||||
client:Notify("Частота рации установлена на " .. string.format(format, frequency))
|
||||
end)
|
||||
|
||||
net.Receive("ixRadioToggleListen", function(_, client)
|
||||
local character = client:GetCharacter()
|
||||
if client:IsAdminMode() then return end
|
||||
|
||||
if (!character) then
|
||||
return
|
||||
end
|
||||
|
||||
local listen = !character:GetData("radioListen", true)
|
||||
local frequency = character:GetData("radioFrequency", PLUGIN.defaultFrequency)
|
||||
local transmit = character:GetData("radioTransmit", true)
|
||||
|
||||
if (!listen) then
|
||||
transmit = false
|
||||
end
|
||||
|
||||
PLUGIN:SyncRadioState(client, frequency, listen, transmit)
|
||||
client:Notify(listen and "Звук рации включен" or "Звук рации выключен")
|
||||
|
||||
if (!listen and transmit) then
|
||||
client:Notify("Передача микрофона выключена")
|
||||
end
|
||||
end)
|
||||
|
||||
net.Receive("ixRadioToggleTransmit", function(_, client)
|
||||
local character = client:GetCharacter()
|
||||
if client:IsAdminMode() then return end
|
||||
|
||||
if (!character) then
|
||||
return
|
||||
end
|
||||
|
||||
local listen = character:GetData("radioListen", true)
|
||||
local frequency = character:GetData("radioFrequency", PLUGIN.defaultFrequency)
|
||||
|
||||
if (!listen) then
|
||||
PLUGIN:SyncRadioState(client, frequency, listen, false)
|
||||
client:Notify("Сначала включите звук рации")
|
||||
return
|
||||
end
|
||||
|
||||
local transmit = !character:GetData("radioTransmit", true)
|
||||
|
||||
PLUGIN:SyncRadioState(client, frequency, listen, transmit)
|
||||
client:Notify(transmit and "Передача микрофона включена" or "Передача микрофона выключена")
|
||||
end)
|
||||
|
||||
function PLUGIN:PlayerCanHearPlayersVoice(listener, speaker)
|
||||
if (listener == speaker) then
|
||||
return
|
||||
end
|
||||
if listener:IsAdminMode() then return end
|
||||
if speaker:IsAdminMode() then return end
|
||||
|
||||
local listenerChar = listener:GetCharacter()
|
||||
local speakerChar = speaker:GetCharacter()
|
||||
|
||||
if (!listenerChar or !speakerChar) then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
if (!self:IsListening(listener)) then
|
||||
return
|
||||
end
|
||||
|
||||
if (!self:IsListening(speaker)) then
|
||||
return
|
||||
end
|
||||
|
||||
if (!self:IsTransmitting(speaker)) then
|
||||
return
|
||||
end
|
||||
|
||||
local lf = self:GetFrequency(listener)
|
||||
local sf = self:GetFrequency(speaker)
|
||||
|
||||
if (math.abs(lf - sf) > self.frequencyTolerance) then
|
||||
return
|
||||
end
|
||||
|
||||
return true, false
|
||||
end
|
||||
Reference in New Issue
Block a user