Advertisement
TnTSCS

DeadVoice

Oct 12th, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.59 KB | None | 0 0
  1. /**
  2.  *
  3.  * Simple dead talk where alive players cannot hear dead players or spectators.  Dead can hear everyone (dead, alive, spectators).
  4.  * Admins are immune, they can hear everyone and everyone can hear them regardless of if they're dead, alive, or spectating.
  5.  *
  6.  */
  7.  
  8. #pragma semicolon 1
  9. #include <sourcemod>
  10. #include <sdktools>
  11. #include <clientprefs>
  12. #include <morecolors>
  13. #include <basecomm>
  14.  
  15. #define     PLUGIN_VERSION      "1.0.0.0"
  16. #define     UPDATE_URL          "http://dl.dropbox.com/u/3266762/deadtalk.txt"
  17.  
  18. new bool:IsClientAdmin[MAXPLAYERS+1] = {false, ...};
  19. new bool:PlayerNoDeadTalk[MAXPLAYERS+1] = {false, ...};
  20. new bool:PlayerCachedCookie[MAXPLAYERS+1] = {false, ...};
  21. new bool:SM_Muted[MAXPLAYERS+1] = {false, ...};
  22. new Handle:g_cookie = INVALID_HANDLE;
  23.  
  24. public Plugin:myinfo =
  25. {
  26.     name = "DHG DeadVoice",
  27.     author = "TnTSCS aka ClarkKent",
  28.     description = "Allow players to turn on or off hearing dead players talk",
  29.     version = PLUGIN_VERSION,
  30.     url = "http://www.dhgamers.com"
  31. };
  32.  
  33. public OnPluginStart()
  34. {
  35.     HookEvent("player_death", OnPlayerDeath);
  36.     HookEvent("player_spawn", OnPlayerSpawn);
  37.     HookEvent("round_start", OnRoundStart);
  38.    
  39.     RegConsoleCmd("sm_deadvoice", Cmd_DeadVoice, "Command to toggle deadvoice on/off");
  40.    
  41.     g_cookie = RegClientCookie("sm-deadtalk", "Dead talk status", CookieAccess_Protected);
  42. }
  43.  
  44. public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
  45. {
  46.     if (late)
  47.     {
  48.         for (new i = 1; i <= MaxClients; i++)
  49.         {
  50.             if (IsClientInGame(i))
  51.             {
  52.                 OnClientPostAdminCheck(i);
  53.             }
  54.         }
  55.     }
  56.    
  57.     return APLRes_Success;
  58. }
  59.  
  60. public Action:Cmd_DeadVoice(client, args)
  61. {
  62.     if (client == 0)
  63.     {
  64.         ReplyToCommand(client, "This is an in-game command only.");
  65.         return Plugin_Handled;
  66.     }
  67.    
  68.     if (args != 1)
  69.     {
  70.         ReplyToCommand(client, "[SM] Usage: sm_deadvoice <1/0> (1 to hear dead players talk, 0 to mute dead players)");
  71.         return Plugin_Handled;
  72.     }
  73.    
  74.     new String:arg[2];
  75.     GetCmdArg(1, arg, sizeof(arg));
  76.     new onoff = StringToInt(arg);
  77.     new bool:deadchat = (onoff == 1 ? true : false);
  78.    
  79.     if (deadchat)
  80.     {
  81.         PlayerNoDeadTalk[client] = false;
  82.         SetClientCookie(client, g_cookie, "0");
  83.         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.");
  84.         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.");
  85.     }
  86.     else
  87.     {
  88.         PlayerNoDeadTalk[client] = true;
  89.         SetClientCookie(client, g_cookie, "1");
  90.         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.");
  91.         PrintToConsole(client, "Current setting for hearing dead people talk: NO.  Use [sm_deadvoice 1] to change this so you can hear dead players talk.");
  92.     }
  93.    
  94.     if (IsClientAdmin[client])
  95.     {
  96.         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.");
  97.     }
  98.    
  99.     return Plugin_Continue;
  100. }
  101.  
  102. public OnPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
  103. {
  104.     new deadplayer = GetClientOfUserId(GetEventInt(event, "userid")); // Client who just died
  105.    
  106.     if (IsFakeClient(deadplayer))
  107.     {
  108.         return; // Don't process bots
  109.     }
  110.    
  111.     // 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
  112.     for (new i = 1; i <= MaxClients; i++)
  113.     {
  114.         if (!IsClientInGame(i) || deadplayer == i) // i isn't in game or i is the same as deadplayer or i doesn't care about deadchat
  115.         {
  116.             continue; // move on to next i
  117.         }
  118.        
  119.         SetListenOverride(deadplayer, i, Listen_Yes); // deadplayer should listen to i
  120.        
  121.         if (GetClientTeam(i) > 1 && IsPlayerAlive(i) && !IsClientAdmin[i] && PlayerNoDeadTalk[i]) // i is on a team and alive and is not an admin
  122.         {
  123.             SetListenOverride(i, deadplayer, Listen_No); // Alive player (non-admin) cannot hear deadplayer who just died
  124.             continue;
  125.         }
  126.        
  127.         SetListenOverride(i, deadplayer, Listen_Yes); // Alive admin player can hear deadplayer who just died
  128.     }
  129. }
  130.  
  131. public OnPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
  132. {
  133.     new spawnedplayer = GetClientOfUserId(GetEventInt(event, "userid"));
  134.    
  135.     if (IsFakeClient(spawnedplayer))
  136.     {
  137.         return; // Don't process bots
  138.     }
  139.    
  140.     // reset all player's listening so they can hear everyone (except spectators)
  141.     for (new i = 1; i <= MaxClients; i++)
  142.     {
  143.         if (!IsClientInGame(i) || spawnedplayer == i) // i isn't in game or spawnedplayer is i
  144.         {
  145.             continue; // process next listener
  146.         }
  147.        
  148.         if (SM_Muted[spawnedplayer])
  149.         {
  150.             SetListenOverride(i, spawnedplayer, Listen_No); // i should not hear spawnedplayer, because spawnedplayer has been muted with sm_mute
  151.         }
  152.         else
  153.         {
  154.             SetListenOverride(i, spawnedplayer, Listen_Yes); // i should hear spawnedplayer
  155.         }
  156.        
  157.         if (GetClientTeam(i) <= 1 && !IsClientAdmin[spawnedplayer] && PlayerNoDeadTalk[spawnedplayer]) // i is spectator and not an admin
  158.         {
  159.             SetListenOverride(spawnedplayer, i, Listen_No); // Spawnedplayer (non-admin) can't hear spectator
  160.             continue; // process next i
  161.         }
  162.        
  163.         SetListenOverride(spawnedplayer, i, Listen_Yes); // spawnedplayer can hear i
  164.     }
  165. }
  166.  
  167. public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  168. {
  169.     // reset all player's listening so they can hear everyone (except spectators and admins)
  170.     for (new i = 1; i <= MaxClients; i++)
  171.     {
  172.         if (!IsClientInGame(i) || IsFakeClient(i)) // player i isn't in game or is a bot
  173.         {
  174.             continue; // process next i
  175.         }
  176.        
  177.         if (GetClientTeam(i) > 1)
  178.         {
  179.             for (new j = 1; j <= MaxClients; j++)
  180.             {
  181.                 if (!IsClientInGame(j) || i == j || IsFakeClient(j)) // player j isn't in game or j is same as i or j is a bot
  182.                 {
  183.                     continue; // process next i
  184.                 }
  185.                
  186.                 // Set initial overrides
  187.                 if (SM_Muted[i])
  188.                 {
  189.                     SetListenOverride(j, i, Listen_No); // j should not hear i because i was muted with sm_mute
  190.                 }
  191.                 else
  192.                 {
  193.                     SetListenOverride(j, i, Listen_Yes); // j should hear i
  194.                 }
  195.                
  196.                 if (SM_Muted[j])
  197.                 {
  198.                     SetListenOverride(i, j, Listen_No); // i should not hear j because j was muted with sm_mute
  199.                 }
  200.                 else
  201.                 {
  202.                     SetListenOverride(i, j, Listen_Yes); // i should hear j
  203.                 }
  204.                
  205.                 if (IsClientAdmin[i] || IsClientAdmin[j]) // player i or j is admin, leave listen flags set to yes
  206.                 {
  207.                     continue; // Admins can hear everyone and everyone can hear admins
  208.                 }
  209.                
  210.                 if (!IsPlayerAlive(j) && PlayerNoDeadTalk[i])
  211.                 {
  212.                     SetListenOverride(i, j, Listen_No); // Non-admin (i) cannot hear dead player (j)
  213.                 }
  214.                
  215.                 if (!IsPlayerAlive(i) && PlayerNoDeadTalk[j])
  216.                 {
  217.                     SetListenOverride(j, i, Listen_No); // Non-admin (j) cannot hear dead player (i)
  218.                 }
  219.                
  220.                 if (GetClientTeam(i) == 1 && PlayerNoDeadTalk[j])
  221.                 {
  222.                     SetListenOverride(j, i, Listen_No); // Non-admin (j) cannot hear spectator (i)
  223.                 }
  224.                
  225.                 if (GetClientTeam(j) == 1 && PlayerNoDeadTalk[i])
  226.                 {
  227.                     SetListenOverride(i, j, Listen_No); // Non-admin (i) cannot hear spectator (j)
  228.                 }
  229.             }
  230.         }
  231.     }
  232. }
  233.  
  234. public BaseComm_OnClientMute(client, bool:muteState)
  235. {
  236.     SM_Muted[client] = muteState;
  237. }
  238.  
  239. public OnClientPostAdminCheck(client)
  240. {
  241.     if (IsFakeClient(client))
  242.     {
  243.         return;
  244.     }
  245.    
  246.     PlayerNoDeadTalk[client] = false;
  247.    
  248.     if (CheckCommandAccess(client, "listen_admin", ADMFLAG_BAN))
  249.     {
  250.         IsClientAdmin[client] = true;
  251.     }
  252.     else
  253.     {
  254.         IsClientAdmin[client] = false;
  255.     }
  256.    
  257.     CreateTimer(10.0, Timer_Cookies, GetClientSerial(client), TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
  258. }
  259.  
  260. public OnClientDisconnect(client)
  261. {
  262.     if (IsClientInGame(client) && !IsFakeClient(client))
  263.     {
  264.         IsClientAdmin[client] = false;
  265.         PlayerNoDeadTalk[client] = false;
  266.     }
  267. }
  268.  
  269. public Action:Timer_Cookies(Handle:timer, any:serial)
  270. {
  271.     new client = GetClientFromSerial(serial);
  272.    
  273.     if (client == 0 || !IsClientInGame(client) || IsFakeClient(client))
  274.     {
  275.         return Plugin_Stop;
  276.     }
  277.    
  278.     if (AreClientCookiesCached(client))
  279.     {
  280.         ProcessCookies(client);
  281.         return Plugin_Stop;
  282.     }
  283.    
  284.     return Plugin_Continue;
  285. }
  286.  
  287. public ProcessCookies(client)
  288. {
  289.     PlayerCachedCookie[client] = true;
  290.    
  291.     if (!PlayerWantNoDeadTalk(client))
  292.     {
  293.         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.");
  294.         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");
  295.         PlayerNoDeadTalk[client] = false;
  296.     }
  297.     else
  298.     {
  299.         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.");
  300.         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");
  301.         PlayerNoDeadTalk[client] = true;
  302.     }
  303.    
  304.     if (IsClientAdmin[client])
  305.     {
  306.         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.");
  307.     }
  308. }
  309.  
  310. bool:PlayerWantNoDeadTalk(client)
  311. {
  312.     new String:cookie[2];
  313.    
  314.     GetClientCookie(client, g_cookie, cookie, sizeof(cookie));
  315.    
  316.     if (StrEqual(cookie, "1", false))
  317.     {
  318.         return true; // Player does not want to hear dead people
  319.     }
  320.    
  321.     return false; // Player will hear dead people
  322. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement