forked from SirPlease/L4D2-Competitive-Rework
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor SpecLister plugin to improve code readability and maintainab…
…ility
- Loading branch information
1 parent
0968190
commit e597c5b
Showing
2 changed files
with
16 additions
and
84 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,103 +1,35 @@ | ||
#pragma semicolon 1 | ||
#pragma newdecls required | ||
|
||
#include <sourcemod> | ||
#include <sdktools> | ||
|
||
#define VOICE_NORMAL 0 | ||
#define VOICE_MUTED 1 | ||
#define VOICE_SPEAKALL 2 | ||
#define VOICE_LISTENALL 4 | ||
#define VOICE_TEAM 8 | ||
|
||
#define TEAM_SPEC 1 | ||
#define PLUGIN_VERSION "1.0" | ||
|
||
public Plugin:myinfo = | ||
public Plugin myinfo = | ||
{ | ||
name = "SpecLister", | ||
author = "waertf & bear", | ||
description = "Allows spectator listen others team voice for l4d", | ||
author = "Altair Sossai", | ||
description = "Allow spectators to hear all players", | ||
version = "1.0", | ||
url = "http://forums.alliedmods.net/showthread.php?t=95474" | ||
url = "https://github.com/altair-sossai/l4d2-zone-server" | ||
} | ||
|
||
public OnPluginStart() | ||
public void OnPluginStart() | ||
{ | ||
HookEvent("player_team", PlayerChangeTeamEvent); | ||
|
||
RegConsoleCmd("hear", PanelCommand); | ||
RegConsoleCmd("muteall", MuteAllCommand); | ||
} | ||
|
||
public PlayerChangeTeamEvent(Handle:event, const String:name[], bool:dontBroadcast) | ||
{ | ||
new userId = GetEventInt(event, "userid"); | ||
new client = GetClientOfUserId(userId); | ||
new team = GetEventInt(event, "team"); | ||
|
||
if(client == 0) | ||
return ; | ||
|
||
SetClientListeningFlags(client, team == TEAM_SPEC ? VOICE_LISTENALL : VOICE_NORMAL); | ||
HookEvent("player_team", PlayerTeam_Event); | ||
} | ||
|
||
public Action:PanelCommand(client, args) | ||
void PlayerTeam_Event(Event event, const char[] name, bool dontBroadcast) | ||
{ | ||
if(GetClientTeam(client) != TEAM_SPEC) | ||
return Plugin_Handled; | ||
|
||
new Handle:panel = CreatePanel(); | ||
|
||
SetPanelTitle(panel, "O que você deseja fazer?"); | ||
DrawPanelItem(panel, "Ouvir todos os jogadores"); | ||
DrawPanelItem(panel, "Ouvir apenas os espectadores"); | ||
DrawPanelItem(panel, "Mutar todos"); | ||
|
||
SendPanelToClient(panel, client, PanelHandler, 20); | ||
|
||
CloseHandle(panel); | ||
|
||
return Plugin_Handled; | ||
} | ||
|
||
public Action:MuteAllCommand(client, args) | ||
{ | ||
if(GetClientTeam(client) != TEAM_SPEC) | ||
return Plugin_Handled; | ||
|
||
SetClientListeningFlags(client, VOICE_MUTED); | ||
PrintToChat(client, "\x04[Silêncio] \x03Você mutou todos..."); | ||
} | ||
|
||
public PanelHandler(Handle:menu, MenuAction:action, client, selectedValue) | ||
{ | ||
if (action != MenuAction_Select) | ||
return; | ||
|
||
if(selectedValue == 1) | ||
{ | ||
SetClientListeningFlags(client, VOICE_LISTENALL); | ||
PrintToChat(client,"\x04[Ouvir] \x03Ouvindo jogadores e espectadores..."); | ||
} | ||
else if(selectedValue == 2) | ||
{ | ||
SetClientListeningFlags(client, VOICE_NORMAL); | ||
PrintToChat(client,"\x04[Ouvir] \x03Ouvindo apenas espectadores..."); | ||
} | ||
else if(selectedValue == 3) | ||
{ | ||
SetClientListeningFlags(client, VOICE_MUTED); | ||
PrintToChat(client, "\x04[Silêncio] \x03Você mutou todos..."); | ||
} | ||
} | ||
|
||
public OnClientPutInServer(client) | ||
{ | ||
CreateTimer(20.0, TimerAnnounce, client); | ||
} | ||
|
||
public Action:TimerAnnounce(Handle:timer, any:client) | ||
{ | ||
if (!IsClientInGame(client)) | ||
int client = GetClientOfUserId(GetEventInt(event, "userid")); | ||
if (client <= 0 || client > MaxClients || !IsClientInGame(client) || IsFakeClient(client)) | ||
return; | ||
|
||
if (GetClientTeam(client) == TEAM_SPEC) | ||
PrintToChat(client, "\x04[Ouvir/Mutar] \x01Para ouvir ou mutar os jogadores digite: \03!hear"); | ||
int team = GetEventInt(event, "team"); | ||
|
||
SetClientListeningFlags(client, team == TEAM_SPEC ? VOICE_LISTENALL : VOICE_TEAM); | ||
} |