View Single Post
roxie
New Member
Join Date: Jul 2018
Old 07-20-2018 , 06:34   Re: Dead only talk for limited time
Reply With Quote #3

I got it to almost working. But if all the players in a team die, then it bugs for some reason.

Here's my code.

Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "roxie"
#define PLUGIN_VERSION "0.1"

#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>

#pragma newdecls required

EngineVersion g_Game;

#define VOICETIMER 7.0
bool RoundEnd = false;

public Plugin myinfo = 
{
	name = "Dead Voice Timer",
	author = PLUGIN_AUTHOR,
	description = "Dead players can only talk to living players for a limited amount of time.",
	version = PLUGIN_VERSION,
	url = ""
};

public void OnPluginStart()
{
	g_Game = GetEngineVersion();
	if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
	{
		SetFailState("This plugin is for CSGO/CSS only.");	
	}
	RoundEnd = false;

	HookEvent("player_death", Event_PlayerDeath);
	HookEvent("round_start", Event_RoundStart);
	HookEvent("round_end", Event_RoundEnd, EventHookMode_Pre);
}

public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast)
{
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	
	PrintToChat(client, "\x01[UPG] \x02You have %.1fseconds to speak with your alive teammates.", VOICETIMER);
	
	SetListenVoice(client, true);
	
	CreateTimer(VOICETIMER, TimerCallback, client);	
}

public Action Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
{
	PrintToServer("RoundEnd: Round end: %d", RoundEnd);
	RoundEnd = true;
}
public Action Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
	PrintToServer("RoundStart: Round end: %d", RoundEnd);
	ResetVoice();
}

public void ResetVoice()
{
	int max = GetClientCount();
	for (int i = 1; i < max + 1; i++) {
		for (int j = i + 1; j < max; j++)
		{
			if (IsClientInGame(j) && IsClientInGame(i))
		    {
		    	SetListenOverride(j, i, Listen_Default);
		    	SetListenOverride(i, j, Listen_Default);
		    }
		}
	}
}

public Action TimerCallback(Handle timer, any client)
{
	if(!RoundEnd)
	{
		SetListenVoice(client, false);
		
		ResetVoice();
		PrintToChat(client, "\x01[UPG] \x02Time is up. Your alive teammates can no longer hear you.");
	}
	else
	{
		PrintToChat(client, "\x01[UPG] \x02Round ended. Voice was reset.");
	}
	RoundEnd = false;
	PrintToServer("Timer FInish: Round end: %d", RoundEnd);
}

public void SetListenVoice(int client, bool shouldListen)
{
	int TeamID = GetClientTeam(client);
	
	int max = GetClientCount();
	
	for (int i = 1; i < max + 1; i++)
	{
		if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == TeamID)
	    {
	    	if(shouldListen)
	    	{
	    		SetListenOverride(i, client, Listen_Yes);
	    	}
	    	else
	    	{
	    		SetListenOverride(i, client, Listen_No);
	    	}
	    }
	}
}
roxie is offline