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

execute command after 5sec of every round start


Post New Thread Reply   
 
Thread Tools Display Modes
yazeed98
Member
Join Date: Mar 2014
Old 04-01-2015 , 12:44   Re: execute command after 5sec of every round start
Reply With Quote #11

Quote:
Originally Posted by Miu View Post
Code:
#include <sourcemod> #include <sdktools> #define MAX_EDICTS    2048 new bool:g_toggle = true; 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){     if(!g_toggle){         g_toggle = true;         PrintToChat(client, "[COMMAND] Toggle command after 5 seconds every round. \x04Turned ON");     }     else{         g_toggle=false;         PrintToChat(client, "[COMMAND] Toggle command after 5 seconds every round. \x04Turned 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){             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);                 }             }         }     } }

Try this
Thanks but looks for whole server not only 1 player.
yazeed98 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 04-01-2015 , 15:07   Re: execute command after 5sec of every round start
Reply With Quote #12

Quote:
Originally Posted by yazeed98 View Post
Thanks but looks for whole server not only 1 player.
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);
                }
            }
        }
    }
}
Miu is offline
yazeed98
Member
Join Date: Mar 2014
Old 04-01-2015 , 15:16   Re: execute command after 5sec of every round start
Reply With Quote #13

Quote:
Originally Posted by Miu View Post
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!
yazeed98 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 04-01-2015 , 15:20   Re: execute command after 5sec of every round start
Reply With Quote #14

also forgot, might want to change

PHP Code:
RegAdminCmd("sm_runcommandeveryround"RunCommandEveryRoundADMFLAG_ROOT""); 
to

PHP Code:
RegConsoleCmd("sm_runcommandeveryround"RunCommandEveryRound""); 
if you want regular users to be able to use the command, not just administrators
Miu is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 04-02-2015 , 20:09   Re: execute command after 5sec of every round start
Reply With Quote #15

You should set a global variable as a serial, incrementing it each round change. If the variable is not the same ad the one passed to e timer, then cancel the timer. In some instances rounds will restart rapidly. Also, you should probably use timer flag no mapchange, whenever you dont want the timer to execute if the map changes.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram 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 11:08.


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