Raised This Month: $12 Target: $400
 3% 

Dead only talk for limited time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
roxie
New Member
Join Date: Jul 2018
Old 07-15-2018 , 14:29   Dead only talk for limited time
Reply With Quote #1

Greetings.

I needed a plugin that only allows players to talk for a limited amount of time after being killed. They could still talk between dead players but not to alive players, kind of like ESEA.

Since I couldn't find one, I decided to make it myself. However, I have no idea how to achieve this. Can I get some tips?

Thanks in advance.
roxie is offline
FaceCSGO
Junior Member
Join Date: Mar 2015
Old 07-15-2018 , 14:46   Re: Dead only talk for limited time
Reply With Quote #2

Take a look at https://sm.alliedmods.net/new-api/sd...ListenOverride
You can set who can hear who on a player by player basis based on whatever you want to do
FaceCSGO is offline
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
roxie
New Member
Join Date: Jul 2018
Old 07-20-2018 , 12:51   Re: Dead only talk for limited time
Reply With Quote #4

Nevermind i got it right. Thanks!
roxie is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode