Files
bladwin-RP/lua/bladw_announcement/server/sv_function.lua
T
nocode a476a2e017 feat(announcement): implement server-side announcement functions
Add server-side functionality for the announcement system:
- Add bladw_amenu console command to open admin announcement menu
- Add /bannonce and !bannonce chat commands for opening the menu
- Implement bladWSendAnnouncement net message handler to broadcast announcements
- Validate admin permissions and sanitize announcement content (title max 64 chars, text max 200 chars)
- Use default title "Annonce" if not provided
2026-07-20 12:46:46 +02:00

36 lines
1.1 KiB
Lua

-- Ouvre le menu admin pour le joueur (réservé aux admins)
concommand.Add("bladw_amenu", function(ply, cmd)
if not IsValid(ply) then return end
net.Start("bladWOpenAnnouncementMenu")
net.Send(ply)
end)
-- Commande chat : /bannonce (ou !bannonce) -> ouvre le menu d'annonce
hook.Add("PlayerSay", "BladW:AnnouncementChatCmd", function(ply, text)
local cmd = string.lower(string.Trim(text))
if cmd ~= "/bannonce" and cmd ~= "!bannonce" then return end
if not IsValid(ply) then return end
net.Start("bladWOpenAnnouncementMenu")
net.Send(ply)
return "" -- masque la commande dans le chat
end)
-- Un admin demande l'envoi d'une annonce -> on la diffuse à tout le monde
net.Receive("bladWSendAnnouncement", function(len, ply)
if not IsValid(ply) or not ply:IsAdmin() then return end
local title = string.sub(net.ReadString(), 1, 64)
local text = string.sub(net.ReadString(), 1, 200)
if text == "" then return end
if title == "" then title = "Annonce" end
net.Start("bladWShowAnnouncement")
net.WriteString(title)
net.WriteString(text)
net.Broadcast()
end)