Raised This Month: $32 Target: $400
 8% 

execute command after 5sec of every round start


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yazeed98
Member
Join Date: Mar 2014
Old 03-30-2015 , 13:49   execute command after 5sec of every round start
Reply With Quote #1

Hello,

Can someone help me to make plugin that execute command after 5sec of every round start
and use it by command like, !runcommandeveryround it'll make it on .. and when running again !runcommandeveryround it will stop it running it every round ..

that's the plugin I want to use..
https://forums.alliedmods.net/showpo...4&postcount=10
Thanks everyone.
yazeed98 is offline
BAILANDO
Senior Member
Join Date: Feb 2015
Location: Slovakia
Old 03-30-2015 , 14:16   Re: execute command after 5sec of every round start
Reply With Quote #2

Here is a code how can you use Timers for start an action after 5 seconds after round start.

Code:
#include <sourcemod> #include <sdktools> #include <cstrike> //#include <sdkhooks> new bool:g_toggle; public Plugin:myinfo = {     name = "",     author = "BAILANDO",     description = "",     version = "1.0",     url = "http://" }; public OnPluginStart(){     HookEvent("round_start", RoundStart);     RegConsoleCmd("sm_runcommandeveryround", RunCommandEveryRound, ""); //If you need command like this, then use RegAdminCmd only for admins(next line)     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){     CreateTimer(5.0, AfterRoundStart); } public Action:AfterRoundStart(Handle:timer){     for(new i = 1; i<=MaxClients;i++){         if(IsClientInGame(i)){             if(g_toggle){                 //TODO if you have toggled ON your command                 //For EXAMPLE:                 PrintToChatAll("[COMMAND] Autobroadcast command is toggled.");             }             else{                 //TODO if you haven't toggled ON your command(command is OFF)                 //You don't need to use else if you don't need action if you have this command off             }         }     } }
Attached Files
File Type: sp Get Plugin or Get Source (after5secstimer.sp - 359 views - 1.4 KB)
BAILANDO is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-30-2015 , 15:25   Re: execute command after 5sec of every round start
Reply With Quote #3

Nitpicks:
  1. Don't include includes you don't use.
  2. Check if toggle is true b4 looping clients. Example:
    PHP Code:
    if (!g_toggle) return Plugin_Handled
__________________

Last edited by WildCard65; 03-30-2015 at 15:29.
WildCard65 is offline
BAILANDO
Senior Member
Join Date: Feb 2015
Location: Slovakia
Old 03-30-2015 , 15:34   Re: execute command after 5sec of every round start
Reply With Quote #4

yea, i forgot
BAILANDO is offline
yazeed98
Member
Join Date: Mar 2014
Old 03-31-2015 , 11:05   Re: execute command after 5sec of every round start
Reply With Quote #5

Quote:
Originally Posted by BAILANDO View Post
Here is a code how can you use Timers for start an action after 5 seconds after round start.

Code:
#include <sourcemod> #include <sdktools> #include <cstrike> //#include <sdkhooks> new bool:g_toggle; public Plugin:myinfo = {     name = "",     author = "BAILANDO",     description = "",     version = "1.0",     url = "http://" }; public OnPluginStart(){     HookEvent("round_start", RoundStart);     RegConsoleCmd("sm_runcommandeveryround", RunCommandEveryRound, ""); //If you need command like this, then use RegAdminCmd only for admins(next line)     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){     CreateTimer(5.0, AfterRoundStart); } public Action:AfterRoundStart(Handle:timer){     for(new i = 1; i<=MaxClients;i++){         if(IsClientInGame(i)){             if(g_toggle){                 //TODO if you have toggled ON your command                 //For EXAMPLE:                 PrintToChatAll("[COMMAND] Autobroadcast command is toggled.");             }             else{                 //TODO if you haven't toggled ON your command(command is OFF)                 //You don't need to use else if you don't need action if you have this command off             }         }     } }
Thanks, Can you please rewrite it with fix user above said.. > not good at sourcemod programing ..
Thanks..
yazeed98 is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-31-2015 , 11:33   Re: execute command after 5sec of every round start
Reply With Quote #6

oh ya, 1 more nitpick I forgot:
for the command handler, just do this:
PHP Code:
g_toggle = !g_toggle;
ReplyToCommand(client"[COMMAND] Toggled command execution on round start to %s."g_toggle "run" "not run"); 
__________________

Last edited by WildCard65; 03-31-2015 at 11:34.
WildCard65 is offline
yazeed98
Member
Join Date: Mar 2014
Old 03-31-2015 , 11:57   Re: execute command after 5sec of every round start
Reply With Quote #7

Quote:
Originally Posted by WildCard65 View Post
oh ya, 1 more nitpick I forgot:
for the command handler, just do this:
PHP Code:
g_toggle = !g_toggle;
ReplyToCommand(client"[COMMAND] Toggled command execution on round start to %s."g_toggle "run" "not run"); 
Thanks, so like that?
Code:
//#include <sdkhooks>

new bool:g_toggle;

public Plugin:myinfo = 
{
    name = "",
    author = "BAILANDO",
    description = "",
    version = "1.0",
    url = "http://"
};

public OnPluginStart(){
    HookEvent("round_start", RoundStart);
    RegConsoleCmd("sm_runcommandeveryround", RunCommandEveryRound, ""); //If you need command like this, then use RegAdminCmd only for admins(next line)
    RegAdminCmd("sm_runcommandeveryround", RunCommandEveryRound, ADMFLAG_ROOT, "");
}

public Action:RunCommandEveryRound(client, args){
if (!g_toggle) return Plugin_Handled;  {
        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){
    CreateTimer(5.0, AfterRoundStart);
}

public Action:AfterRoundStart(Handle:timer){
    for(new i = 1; i<=MaxClients;i++){
        if(IsClientInGame(i)){
g_toggle = !g_toggle;
ReplyToCommand(client, "[COMMAND] Toggled command execution on round start to %s.", g_toggle ? "run" : "not run");
            }
            else{
                //TODO if you haven't toggled ON your command(command is OFF)
                //You don't need to use else if you don't need action if you have this command off
            }
        }
    }
}
yazeed98 is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-31-2015 , 12:01   Re: execute command after 5sec of every round start
Reply With Quote #8

Not even close
__________________
WildCard65 is offline
yazeed98
Member
Join Date: Mar 2014
Old 03-31-2015 , 15:10   Re: execute command after 5sec of every round start
Reply With Quote #9

Quote:
Originally Posted by WildCard65 View Post
Not even close
Can you please help, the command is sm_stopmusic
thanks...
yazeed98 is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 03-31-2015 , 16:49   Re: execute command after 5sec of every round start
Reply With Quote #10

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
Miu 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 23:33.


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