|
Member
|
04-01-2015
, 15:16
Re: execute command after 5sec of every round start
|
#13
|
Quote:
Originally Posted by Miu
Yeah, I thought that was how you wanted it. Anyway, here:
Code:
#include <sourcemod>
#include <sdktools>
#define MAX_EDICTS 2048
new bool:g_toggle[MAXPLAYERS + 1];
new g_iSoundEnts[MAX_EDICTS];
new g_iNumSounds;
public OnPluginStart(){
HookEvent("round_start", RoundStart);
RegAdminCmd("sm_runcommandeveryround", RunCommandEveryRound, ADMFLAG_ROOT, "");
}
public Action:RunCommandEveryRound(client, args){
g_toggle[client] = !g_toggle[client];
PrintToChat(client, "%s", g_toggle[client] ? "ON" : "OFF");
}
public Action:RoundStart(Handle:event, const String:name[], bool:dontBroadcast){
// Ents are recreated every round.
g_iNumSounds = 0;
// Find all ambient sounds played by the map.
decl String:sSound[PLATFORM_MAX_PATH];
new entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE)
{
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
new len = strlen(sSound);
if (len > 4 && (StrEqual(sSound[len-3], "mp3") || StrEqual(sSound[len-3], "wav")))
{
g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
}
}
CreateTimer(5.0, AfterRoundStart);
}
Client_StopSound(client, entity, channel, const String:name[])
{
EmitSoundToClient(client, name, entity, channel, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
}
public Action:AfterRoundStart(Handle:timer){
for(new client = 1; client<=MaxClients; client++){
if(!IsClientInGame(client))
{
continue;
}
if(g_toggle[client]){
decl String:sSound[PLATFORM_MAX_PATH], entity;
for (new i = 0; i < g_iNumSounds; i++)
{
entity = EntRefToEntIndex(g_iSoundEnts[i]);
if (entity != INVALID_ENT_REFERENCE)
{
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
Client_StopSound(client, entity, SNDCHAN_STATIC, sSound);
}
}
}
}
}
|
Thanks alot!
|
|
|
|