-- Серверный скрипт для обработки взаимодействий…
- User
-- Серверный скрипт для обработки взаимодействий include("autorun/sh_interactions_config.lua")
util.AddNetworkString("RequestInteraction") util.AddNetworkString("ConsentRequest") util.AddNetworkString("ConsentResponse")
local interactionRadius = 250 -- Радиус отображения действия
-- Функция для проигрывания анимаций local function PlayAnimation(ply, animation) if IsValid(ply) and animation then local sequence = ply:LookupSequence(animation) if sequence > 0 then LSCS:PlayVCDSequence(ply, animation, 0.1) else ply:ChatPrint("Анимация '" .. animation .. "' не найдена у игрока.") end end end
-- Функция для обработки запроса взаимодействия local function HandleInteractionRequest(len, ply) local action = net.ReadString() local target = net.ReadEntity() local actionData = nil
code-- Проходим по всем категориям и ищем действие for category, actions in pairs(InteractionsConfig) do if actions[action] then actionData = actions[action] break end end if actionData then local cooldown = actionData.cooldown or 0 local lastInteraction = ply:GetNWFloat("LastInteraction_" .. action, 0) if CurTime() - lastInteraction < cooldown then ply:ChatPrint("Пожалуйста, подождите " .. math.ceil(cooldown - (CurTime() - lastInteraction)) .. " секунд.") return end ply:SetNWFloat("LastInteraction_" .. action, CurTime()) if IsValid(target) and target:IsPlayer() and target:GetPos():Distance(ply:GetPos()) <= interactionRadius then local consentRequired = InteractionsConfig.ConsentRequired and InteractionsConfig.ConsentRequired[action] if consentRequired then -- Отправляем запрос на согласие net.Start("ConsentRequest") net.WriteEntity(ply) net.WriteString(action) net.Send(target) else -- Выполняем действие без согласия local message = actionData.messages[math.random(#actionData.messages)] local formattedMessage = string.Replace(message, "actor", ply:Nick()) formattedMessage = string.Replace(formattedMessage, "target", target:Nick()) -- Отображаем действие в радиусе for _, v in pairs(ents.FindInSphere(ply:GetPos(), interactionRadius)) do if v:IsPlayer() then v:ChatPrint(formattedMessage) end end -- Выполняем анимации и звуки if actionData.animation then PlayAnimation(ply, actionData.animation) end if actionData.sound and actionData.sound ~= "" then target:EmitSound(actionData.sound) end end else ply:ChatPrint("Цель недоступна или слишком далеко.") end else ply:ChatPrint("Действие не найдено.") end - Assistant