Raised This Month: $ Target: $400
 0% 

Run a server command for 5 rounds


Post New Thread Reply   
 
Thread Tools Display Modes
Tylerst
Veteran Member
Join Date: Oct 2010
Old 03-19-2012 , 16:52   Re: Run a server command for 5 rounds
Reply With Quote #11

Edit: See post 16

Last edited by Tylerst; 03-19-2012 at 17:44.
Tylerst is offline
Dreamy
SourceMod Donor
Join Date: Mar 2012
Old 03-19-2012 , 17:01   Re: Run a server command for 5 rounds
Reply With Quote #12

^^ that will execute the command for 6 rounds.

PHP Code:
public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (++
Rounds <= 5)
        
ServerCommand("exec my_config.cfg");


Last edited by Dreamy; 03-19-2012 at 17:01.
Dreamy is offline
cold-serenity
Member
Join Date: Sep 2009
Old 03-19-2012 , 17:02   Re: Run a server command for 5 rounds
Reply With Quote #13

The game is counter-strike source.

I tried mixing yours and some other code and I got the plugin to compile:

PHP Code:
public Plugin:myinfo 
{
    
name "Exec cfg/round_start.cfg file every round",
    
description "Execute config file every round start"
}

public 
OnPluginStart()
{
    
HookEvent("round_start"round_startEventHookMode_PostNoCopy);
}

new 
Rounds 0;

public 
round_start(Handle:event, const String:name[], bool:dontBroadcast)
{
    if (
Rounds 5) return Plugin_Continue;
    {
    
Rounds Rounds 1;
    }
    if(
FileExists("/cfg/round_start.cfg"false))
    {
        
ServerCommand("exec hs.cfg");
    }

However, it just runs the hs.cfg 6 times (not 5) straight, then stops. To elaborate, I have a custom vote system setup to as the majority of the server if they want a headshot only round. If the server votes yes, I want my hs.cfg to be ran at the start of the next 5 rounds, then quit until the population votes for it again.

Also if rounds is just an integer, can u explain how the plugin is read. Like how does it know that rounds means actual rounds. If I set it as bananas, then the server still reads bananas as rounds? I just want to understand, Thanks.

Last edited by cold-serenity; 03-19-2012 at 17:04.
cold-serenity is offline
Tylerst
Veteran Member
Join Date: Oct 2010
Old 03-19-2012 , 17:11   Re: Run a server command for 5 rounds
Reply With Quote #14

Quote:
Originally Posted by Dreamy View Post
^^ that will execute the command for 6 rounds.
Whoops, forgot the =, my bad. Fixed my OP.

Last edited by Tylerst; 03-19-2012 at 17:14.
Tylerst is offline
Dreamy
SourceMod Donor
Join Date: Mar 2012
Old 03-19-2012 , 17:14   Re: Run a server command for 5 rounds
Reply With Quote #15

Quote:
Originally Posted by cold-serenity View Post
Is it because Rounds itself is only the name of the variable and as such is not actually assigned to real ingame rounds?
ding ding ding..

Quote:
Originally Posted by cold-serenity View Post
Also if rounds is just an integer, can u explain how the plugin is read. Like how does it know that rounds means actual rounds. If I set it as bananas, then the server still reads bananas as rounds? I just want to understand, Thanks.
we are hooking the ingame event "round_start" which is fired.. wait for it.. once per round ;O
in the callback of that hook we add 1 to a global variable with the name "Rounds".

Last edited by Dreamy; 03-19-2012 at 17:18.
Dreamy is offline
Tylerst
Veteran Member
Join Date: Oct 2010
Old 03-19-2012 , 17:43   Re: Run a server command for 5 rounds
Reply With Quote #16

I just tested this myself to make sure, this will work for you.

PHP Code:
#include <sourcemod>

new Rounds;

public 
OnPluginStart() HookEvent("round_start"Event_RoundStart);
public 
OnMapStart() Rounds 0;
public 
Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast) if(++Rounds <= 5ServerCommand("exec my_config.cfg"); 

Last edited by Tylerst; 03-19-2012 at 18:14.
Tylerst is offline
cold-serenity
Member
Join Date: Sep 2009
Old 03-19-2012 , 17:45   Re: Run a server command for 5 rounds
Reply With Quote #17

So when the script uses the hook at the start, anything below that line is tied to that hook? Where can I read more about hooks?

And what does "(Handle:event, const String:name[], bool:dontBroadcast)" all that actually mean?

Also thanks everyone for the help, I am really trying hard to understand sourcepawn. I just started scripting in AutoIt, and now I am moving up to SourcePawn.

And thanks Tyler I will try it now.

Oh tyler, so after this script is ran, will it unload itself? Because my voting system works by loading the script each time.

Last edited by cold-serenity; 03-19-2012 at 17:47.
cold-serenity is offline
Tylerst
Veteran Member
Join Date: Oct 2010
Old 03-19-2012 , 18:02   Re: Run a server command for 5 rounds
Reply With Quote #18

Quote:
Originally Posted by cold-serenity View Post
So when the script uses the hook at the start, anything below that line is tied to that hook? Where can I read more about hooks?

And what does "(Handle:event, const String:name[], bool:dontBroadcast)" all that actually mean?

Also thanks everyone for the help, I am really trying hard to understand sourcepawn. I just started scripting in AutoIt, and now I am moving up to SourcePawn.

And thanks Tyler I will try it now.

Oh tyler, so after this script is ran, will it unload itself? Because my voting system works by loading the script each time.
You can read more about sourcepawn here: http://wiki.alliedmods.net/Category:SourceMod_Scripting
(Look at Events, for this case)

HookEvent is a sourcemod function which requires at least the event name(must be exact, look here:http://wiki.alliedmods.net/Game_Events_(Source)) and a callback(which can be named whatever you want)

For example:
PHP Code:
HookEvent("player_death"Iamaneventcallbackname_lololol); 
The plugin will look for the callback named Iamaneventcallbackname_lololol and execute it, regardless of where it is.



The generic event info is the (Handle:event, const String:name[], bool:dontBroadcast).

The Handle:event is the handle that the event is stored into when hooking, so that information can be taken from it if neccesary(For example, if you wanted to get who died in the player_death event)

The name String is just the name of the event for if you want to use it in chat, or logging, etc

The dontBroadcast boolean just keeps the event message from being sent to clients(It won't prevent the event from being fired). Generally only used when creating an event yourself, not from hooked ones.

In this case:
PHP Code:
HookEvent("player_death"Iamaneventcallbackname_lololol);
Iamaneventcallbackname_lololol(Handle:event, const String:name[], bool:dontBroadcast)
{
     
//Dostuff

I'll check back later if you have more questions. For now, I really need some sleep X_X

Have fun.

Last edited by Tylerst; 03-19-2012 at 18:12.
Tylerst is offline
cold-serenity
Member
Join Date: Sep 2009
Old 03-19-2012 , 18:12   Re: Run a server command for 5 rounds
Reply With Quote #19

For some reason it is using the servercommand(exec hs.cfg) everytime someone in the server dies. After 5 deaths it stops.
cold-serenity is offline
Tylerst
Veteran Member
Join Date: Oct 2010
Old 03-19-2012 , 18:14   Re: Run a server command for 5 rounds
Reply With Quote #20

Quote:
Originally Posted by cold-serenity View Post
For some reason it is using the servercommand(exec hs.cfg) everytime someone in the server dies. After 5 deaths it stops.
Whoops, I changed it to player_death while I was testing it, just change it back to round_start. Ill go back and fix my post. Sorry, I'm really tired >.<
Tylerst 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 04:23.


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