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

Using ClientCommand in a timer?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SociallyAwkward
Junior Member
Join Date: Nov 2017
Old 11-13-2017 , 15:32   Using ClientCommand in a timer?
Reply With Quote #1

Hello, My most recent plugin "MapTime" has been working great, but I would like to add some sounds that play at the 5 minute and 1 minute mark. Unfortunately I am unable to figure out how to do so.

(The client commands are commented because they were not working.)

My Code Is Here:
Code:
#include <sourcemod>
#include <sdktools>
#include <morecolors>
 
Handle g_hTimer;
 
public Plugin myinfo =
{
    name = "|CelMod| Map Time",
    author = "SociallyAwkward",
    description = "This plugin will display the time left for the map periodically, as well as via a command.",
    version = "1.0",
    url = "http://www.bitbucket.org/sociallyawkwardd"
};
 
//When plugin is loaded
public void OnPluginStart()
{
    PrintToServer("Created By SociallyAwkward - 10/11/2017");
    PrintToServer("Created For Use On The |CelMod| Server");
    RegConsoleCmd("sm_maptime", Command_MapTime, "Display Time Left For The Map.");
}
 
//When map starts
public void OnMapStart()
{
  	 g_hTimer = CreateTimer(600.0, MapTimer,_, TIMER_REPEAT);
   	 g_hTimer = CreateTimer(1.0, SaveTimer,_, TIMER_REPEAT);
 
}
 
//When user runs command
public Action Command_MapTime(int client, int args)
{
    int timeleft;
    GetMapTimeLeft(timeleft);
    CPrintToChat(client,"{blue}|CelMod| {default}%d Minutes Remaining.", (timeleft / 60));
    return Plugin_Handled;
}
 
//When the map timer reaches 10 minutes
public Action MapTimer(Handle timer, Handle hndl)
{
    int timeleft; // blocked-scoped variable
    GetMapTimeLeft(timeleft);
    CPrintToChatAll("{blue}|CelMod| {default}%d Minutes Remaining.", (timeleft / 60));
    return Plugin_Continue;
}
 
 public Action SaveTimer(Handle timer, Handle hndl)
{
	int timeleft;
	GetMapTimeLeft(timeleft);
	
	if (timeleft == 300){
	//ClientCommand(client,"play ambient/alarms/warningbell1.wav");
	//ClientCommand(client,"play npc/combine_soldier/vo/stayalert.wav");
	CPrintToChatAll("{blue}-=-=-={green}5 MINUTES REMAINING - SAVE YOUR BUILDS{blue}=-=-=-");
	}
	if (timeleft == 60){
	//ClientCommand(client,"play ambient/alarms/warningbell1.wav");
	//ClientCommand(client,"play npc/overwatch/cityvoice/fcitadel_1minutetosingularity.wav");
	CPrintToChatAll("{blue}-=-=-={green}1 MINUTE REMAINING - SAVE YOUR BUILDS{blue}=-=-=-");
}
	return Plugin_Continue;
}
 
	public void OnMapEnd()
{
    	CloseHandle(g_hTimer);
}

Last edited by SociallyAwkward; 11-13-2017 at 15:33. Reason: .
SociallyAwkward is offline
Walgrim
AlliedModders Donor
Join Date: Dec 2015
Location: France
Old 11-13-2017 , 16:24   Re: Using ClientCommand in a timer?
Reply With Quote #2

Hey,
You can use EmitSoundToClient to do that :^)
Walgrim is offline
SociallyAwkward
Junior Member
Join Date: Nov 2017
Old 11-13-2017 , 17:01   Re: Using ClientCommand in a timer?
Reply With Quote #3

Quote:
Originally Posted by Walgrim View Post
Hey,
You can use EmitSoundToClient to do that :^)
I changed it to EmitSoundToAll("...");
It seems to "work" but it doesn't really..
No sounds play and when I look in console I get
"SV_StartSound: ambient/alarms/warningbell1.wav not precached <0>"
"SV_StartSound: npc/combine_soldier/vo/stayalert.wav not precached <0>"

(No clue what that means or how to fix it.)
SociallyAwkward is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 11-13-2017 , 17:11   Re: Using ClientCommand in a timer?
Reply With Quote #4

You'll want to use PrecacheSound and pass in those sound names you posted in during the OnMapStart callback.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
SociallyAwkward
Junior Member
Join Date: Nov 2017
Old 11-13-2017 , 17:22   Re: Using ClientCommand in a timer?
Reply With Quote #5

Quote:
Originally Posted by nosoop View Post
You'll want to use PrecacheSound and pass in those sound names you posted in during the OnMapStart callback.
Alright, It all works now.
Thank you so much!
SociallyAwkward is offline
Reply



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 15:21.


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