Skip to content

Commit

Permalink
Add squad-only messages hook
Browse files Browse the repository at this point in the history
  • Loading branch information
StyledStrike committed Jul 1, 2024
1 parent ef08030 commit 5f05f0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,22 @@ hook.Add( "ShouldAllowSquadName", "BlockWordsExample", function( name, leader )
end )
```

You can also override/filter squad-only messages by using the `SquadPlayerSay` hook **on the server**.

```lua
hook.Add( "SquadPlayerSay", "BlockMessagesExample", function( sender, text )
-- When you return false, the message will not be sent.
if string.find( text, "amogus" ) then
return false
end

-- You can return a string to override the message.
if string.find( text, "sus" ) then
return string.Replace( text, "sus", "nope" )
end
end )
```

# Contributing

Before you open a pull request, if it deals with Lua code, please read [this](https://github.com/StyledStrike/gmod-squad-menu/blob/main/.github/pull_request_template.md).
4 changes: 4 additions & 0 deletions lua/squad_menu/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ hook.Add( "PlayerSay", "SquadMenu.RemovePrefix", function( sender, text, _, chan
return ""
end

local override = hook.Run( "SquadPlayerSay", sender, text )
if override ~= nil and ( not override or override == "" ) then return "" end
if type( override ) == "string" then text = override end

local members = SquadMenu:GetSquad( id ):GetActiveMembers()

SquadMenu.StartEvent( "members_chat", {
Expand Down

0 comments on commit 5f05f0c

Please sign in to comment.