Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- * Simple dead talk where alive players cannot hear dead players or spectators. Dead can hear everyone (dead, alive, spectators).
- * Admins are immune, they can hear everyone and everyone can hear them regardless of if they're dead, alive, or spectating.
- *
- */
- #pragma semicolon 1
- #include <sourcemod>
- #include <sdktools>
- #include <clientprefs>
- #include <morecolors>
- #include <basecomm>
- #define PLUGIN_VERSION "1.0.0.0"
- #define UPDATE_URL "http://dl.dropbox.com/u/3266762/deadtalk.txt"
- new bool:IsClientAdmin[MAXPLAYERS+1] = {false, ...};
- new bool:PlayerNoDeadTalk[MAXPLAYERS+1] = {false, ...};
- new bool:PlayerCachedCookie[MAXPLAYERS+1] = {false, ...};
- new bool:SM_Muted[MAXPLAYERS+1] = {false, ...};
- new Handle:g_cookie = INVALID_HANDLE;
- public Plugin:myinfo =
- {
- name = "DHG DeadVoice",
- author = "TnTSCS aka ClarkKent",
- description = "Allow players to turn on or off hearing dead players talk",
- version = PLUGIN_VERSION,
- url = "http://www.dhgamers.com"
- };
- public OnPluginStart()
- {
- HookEvent("player_death", OnPlayerDeath);
- HookEvent("player_spawn", OnPlayerSpawn);
- HookEvent("round_start", OnRoundStart);
- RegConsoleCmd("sm_deadvoice", Cmd_DeadVoice, "Command to toggle deadvoice on/off");
- g_cookie = RegClientCookie("sm-deadtalk", "Dead talk status", CookieAccess_Protected);
- }
- public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
- {
- if (late)
- {
- for (new i = 1; i <= MaxClients; i++)
- {
- if (IsClientInGame(i))
- {
- OnClientPostAdminCheck(i);
- }
- }
- }
- return APLRes_Success;
- }
- public Action:Cmd_DeadVoice(client, args)
- {
- if (client == 0)
- {
- ReplyToCommand(client, "This is an in-game command only.");
- return Plugin_Handled;
- }
- if (args != 1)
- {
- ReplyToCommand(client, "[SM] Usage: sm_deadvoice <1/0> (1 to hear dead players talk, 0 to mute dead players)");
- return Plugin_Handled;
- }
- new String:arg[2];
- GetCmdArg(1, arg, sizeof(arg));
- new onoff = StringToInt(arg);
- new bool:deadchat = (onoff == 1 ? true : false);
- if (deadchat)
- {
- PlayerNoDeadTalk[client] = false;
- SetClientCookie(client, g_cookie, "0");
- CPrintToChat(client, "{blue}Current setting for hearing dead people talk: {white}YES.\n{blue}Use {lightgreen}[!deadvoice 0]{blue} to change this so you don't hear dead players talk.");
- PrintToConsole(client, "Current setting for hearing dead people talk: YES. Use [sm_deadvoice 0] to change this so you don't hear dead players talk.");
- }
- else
- {
- PlayerNoDeadTalk[client] = true;
- SetClientCookie(client, g_cookie, "1");
- CPrintToChat(client, "{blue}Current setting for hearing dead people talk: {white}NO.\n{blue}Use {lightgreen}[!deadvoice 1]{blue} to change this so you can hear dead players talk.");
- PrintToConsole(client, "Current setting for hearing dead people talk: NO. Use [sm_deadvoice 1] to change this so you can hear dead players talk.");
- }
- if (IsClientAdmin[client])
- {
- CPrintToChat(client, "{purple}Since you're an admin, you can always hear all players and all players can always hear you, regardless of your alive state.");
- }
- return Plugin_Continue;
- }
- public OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new deadplayer = GetClientOfUserId(GetEventInt(event, "userid")); // Client who just died
- if (IsFakeClient(deadplayer))
- {
- return; // Don't process bots
- }
- // Set all alive players to not hear victim now that they are dead (unless they're admin) - dead players can still hear all other players and spectators
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientInGame(i) || deadplayer == i) // i isn't in game or i is the same as deadplayer or i doesn't care about deadchat
- {
- continue; // move on to next i
- }
- SetListenOverride(deadplayer, i, Listen_Yes); // deadplayer should listen to i
- if (GetClientTeam(i) > 1 && IsPlayerAlive(i) && !IsClientAdmin[i] && PlayerNoDeadTalk[i]) // i is on a team and alive and is not an admin
- {
- SetListenOverride(i, deadplayer, Listen_No); // Alive player (non-admin) cannot hear deadplayer who just died
- continue;
- }
- SetListenOverride(i, deadplayer, Listen_Yes); // Alive admin player can hear deadplayer who just died
- }
- }
- public OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
- {
- new spawnedplayer = GetClientOfUserId(GetEventInt(event, "userid"));
- if (IsFakeClient(spawnedplayer))
- {
- return; // Don't process bots
- }
- // reset all player's listening so they can hear everyone (except spectators)
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientInGame(i) || spawnedplayer == i) // i isn't in game or spawnedplayer is i
- {
- continue; // process next listener
- }
- if (SM_Muted[spawnedplayer])
- {
- SetListenOverride(i, spawnedplayer, Listen_No); // i should not hear spawnedplayer, because spawnedplayer has been muted with sm_mute
- }
- else
- {
- SetListenOverride(i, spawnedplayer, Listen_Yes); // i should hear spawnedplayer
- }
- if (GetClientTeam(i) <= 1 && !IsClientAdmin[spawnedplayer] && PlayerNoDeadTalk[spawnedplayer]) // i is spectator and not an admin
- {
- SetListenOverride(spawnedplayer, i, Listen_No); // Spawnedplayer (non-admin) can't hear spectator
- continue; // process next i
- }
- SetListenOverride(spawnedplayer, i, Listen_Yes); // spawnedplayer can hear i
- }
- }
- public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
- {
- // reset all player's listening so they can hear everyone (except spectators and admins)
- for (new i = 1; i <= MaxClients; i++)
- {
- if (!IsClientInGame(i) || IsFakeClient(i)) // player i isn't in game or is a bot
- {
- continue; // process next i
- }
- if (GetClientTeam(i) > 1)
- {
- for (new j = 1; j <= MaxClients; j++)
- {
- if (!IsClientInGame(j) || i == j || IsFakeClient(j)) // player j isn't in game or j is same as i or j is a bot
- {
- continue; // process next i
- }
- // Set initial overrides
- if (SM_Muted[i])
- {
- SetListenOverride(j, i, Listen_No); // j should not hear i because i was muted with sm_mute
- }
- else
- {
- SetListenOverride(j, i, Listen_Yes); // j should hear i
- }
- if (SM_Muted[j])
- {
- SetListenOverride(i, j, Listen_No); // i should not hear j because j was muted with sm_mute
- }
- else
- {
- SetListenOverride(i, j, Listen_Yes); // i should hear j
- }
- if (IsClientAdmin[i] || IsClientAdmin[j]) // player i or j is admin, leave listen flags set to yes
- {
- continue; // Admins can hear everyone and everyone can hear admins
- }
- if (!IsPlayerAlive(j) && PlayerNoDeadTalk[i])
- {
- SetListenOverride(i, j, Listen_No); // Non-admin (i) cannot hear dead player (j)
- }
- if (!IsPlayerAlive(i) && PlayerNoDeadTalk[j])
- {
- SetListenOverride(j, i, Listen_No); // Non-admin (j) cannot hear dead player (i)
- }
- if (GetClientTeam(i) == 1 && PlayerNoDeadTalk[j])
- {
- SetListenOverride(j, i, Listen_No); // Non-admin (j) cannot hear spectator (i)
- }
- if (GetClientTeam(j) == 1 && PlayerNoDeadTalk[i])
- {
- SetListenOverride(i, j, Listen_No); // Non-admin (i) cannot hear spectator (j)
- }
- }
- }
- }
- }
- public BaseComm_OnClientMute(client, bool:muteState)
- {
- SM_Muted[client] = muteState;
- }
- public OnClientPostAdminCheck(client)
- {
- if (IsFakeClient(client))
- {
- return;
- }
- PlayerNoDeadTalk[client] = false;
- if (CheckCommandAccess(client, "listen_admin", ADMFLAG_BAN))
- {
- IsClientAdmin[client] = true;
- }
- else
- {
- IsClientAdmin[client] = false;
- }
- CreateTimer(10.0, Timer_Cookies, GetClientSerial(client), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
- }
- public OnClientDisconnect(client)
- {
- if (IsClientInGame(client) && !IsFakeClient(client))
- {
- IsClientAdmin[client] = false;
- PlayerNoDeadTalk[client] = false;
- }
- }
- public Action:Timer_Cookies(Handle:timer, any:serial)
- {
- new client = GetClientFromSerial(serial);
- if (client == 0 || !IsClientInGame(client) || IsFakeClient(client))
- {
- return Plugin_Stop;
- }
- if (AreClientCookiesCached(client))
- {
- ProcessCookies(client);
- return Plugin_Stop;
- }
- return Plugin_Continue;
- }
- public ProcessCookies(client)
- {
- PlayerCachedCookie[client] = true;
- if (!PlayerWantNoDeadTalk(client))
- {
- CPrintToChat(client, "{blue}Current setting for hearing dead people talk: {white}YES.\n{blue}Use {lightgreen}[!deadvoice 0]{blue} to change this so you don't hear dead players talk.");
- PrintToConsole(client, "\n** DEAD VOICE**\nCurrent setting for hearing dead people talk: YES. Use [sm_deadvoice 0] to change this so you don't hear dead players talk.\n");
- PlayerNoDeadTalk[client] = false;
- }
- else
- {
- CPrintToChat(client, "{blue}Current setting for hearing dead people talk: {white}NO.\n{blue}Use {lightgreen}[!deadvoice 1]{blue} to change this so you can hear dead players talk.");
- PrintToConsole(client, "\n** DEAD VOICE**\nCurrent setting for hearing dead people talk: NO. Use [sm_deadvoice 1] to change this so you can hear dead players talk.\n");
- PlayerNoDeadTalk[client] = true;
- }
- if (IsClientAdmin[client])
- {
- CPrintToChat(client, "{purple}Since you're an admin, you can always hear all players and all players can always hear you, regardless of your alive state.");
- }
- }
- bool:PlayerWantNoDeadTalk(client)
- {
- new String:cookie[2];
- GetClientCookie(client, g_cookie, cookie, sizeof(cookie));
- if (StrEqual(cookie, "1", false))
- {
- return true; // Player does not want to hear dead people
- }
- return false; // Player will hear dead people
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement