Skip to content

Commit

Permalink
Add convar: squad_broadcast_creation_message
Browse files Browse the repository at this point in the history
  • Loading branch information
StyledStrike committed May 2, 2024
1 parent ddaa7da commit ab45a79
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
21 changes: 17 additions & 4 deletions lua/autorun/sh_squad_menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ CreateConVar(
1, 9
)

CreateConVar(
"squad_broadcast_creation_message",
"1",
FCVAR_ARCHIVE + FCVAR_REPLICATED + FCVAR_NOTIFY,
"When set to 1, Squad Menu will print when a new squad is created on the chat.",
0, 1
)

function SquadMenu.PrintF( str, ... )
MsgC( SquadMenu.THEME_COLOR, "[Squad Menu] ", Color( 255, 255, 255 ), string.format( str, ... ), "\n" )
end
Expand All @@ -66,13 +74,18 @@ function SquadMenu.JSONToTable( s )
end

function SquadMenu.GetMemberLimit()
local cvarLimit = GetConVar( "squad_max_members" )
return cvarLimit and cvarLimit:GetInt() or 10
local cvar = GetConVar( "squad_max_members" )
return cvar and cvar:GetInt() or 10
end

function SquadMenu.GetMembersPosition()
local cvarPosition = GetConVar( "squad_members_position" )
return cvarPosition and cvarPosition:GetInt() or 6
local cvar = GetConVar( "squad_members_position" )
return cvar and cvar:GetInt() or 6
end

function SquadMenu.GetShowCreationMessage()
local cvar = GetConVar( "squad_broadcast_creation_message" )
return cvar and cvar:GetInt() or 1
end

function SquadMenu.AllPlayersBySteamID()
Expand Down
5 changes: 5 additions & 0 deletions lua/squad_menu/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ commands[SquadMenu.BROADCAST_EVENT] = function()
elseif event == "squad_created" or event == "squad_deleted" then
SquadMenu:RequestSquadListUpdate()

if event == "squad_created" and data.name and SquadMenu.GetShowCreationMessage() > 0 then
local color = Color( data.r, data.g, data.b )
SquadMenu.ChatPrint( string.format( L"squad_created", data.leaderName ), color, " " .. data.name )
end

elseif event == "members_chat" then
local squad = SquadMenu.mySquad
if not squad then return end
Expand Down
10 changes: 10 additions & 0 deletions lua/squad_menu/server/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ commands[SquadMenu.SETUP_SQUAD] = function( ply )
local squad = SquadMenu:CreateSquad( ply )
squad:SetBasicInfo( data )
squad:AddMember( ply )

SquadMenu.StartEvent( "squad_created", {
id = squadId,
name = squad.name,
leaderName = ply:Nick(),
r = squad.r,
g = squad.g,
b = squad.b
} )
net.Broadcast()
end

commands[SquadMenu.JOIN_SQUAD] = function( ply )
Expand Down
3 changes: 0 additions & 3 deletions lua/squad_menu/server/squad.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ function SquadMenu:CreateSquad( leader )

self.PrintF( "Created squad #%d for %s", id, leader:SteamID() )

self.StartEvent( "squad_created", { id = id } )
net.Broadcast()

return self.squads[id]
end

Expand Down
1 change: 1 addition & 0 deletions resource/localization/en/squad_menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ squad_menu.squad_rings=Show ring around members
squad_menu.member_joined=%s joined the squad!
squad_menu.member_left=%s left the squad!
squad_menu.squad_welcome=Welcome to the squad:
squad_menu.squad_created=%s created a squad:
squad_menu.chat_tip=Type any of these commands to only chat with your squad:
squad_menu.request_message=%s requested to join your squad.
squad_menu.left_squad=You left the squad.
Expand Down
1 change: 1 addition & 0 deletions resource/localization/pt-br/squad_menu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ squad_menu.squad_rings=Mostre anel ao redor dos membros
squad_menu.member_joined=%s entrou no esquadrão!
squad_menu.member_left=%s saiu do esquadrão!
squad_menu.squad_welcome=Bem-vindo ao esquadrão:
squad_menu.squad_created=%s criou o esquadrão:
squad_menu.chat_tip=Use um destes comandos para conversar apenas com seu esquadrão:
squad_menu.request_message=%s pediu para entrar no seu esquadrão.
squad_menu.left_squad=Você saiu do esquadrão.
Expand Down

0 comments on commit ab45a79

Please sign in to comment.