PDA

View Full Version : Winning Team Restriction


red!
10-16-2007, 16:03
This plugin calls a configurable command to restrict items for the winning team. Restrictions can be done using any restriction-utility that allows team-based restriction (e.g. ^bugs^ sm_restrict).
New feature: win streak override, if the team losing by absolute number of points wins a certain amount of rounds, the restriction may be overridden with restrict all or complete unrestrict.

For those who need it clear: ITS NOT A STANDALONE PLUGIN, IT NEEDS ANOTHER PLUGIN TO WORK. (I do not appreciate do do the same work twice)

commands:

sm_wtrestrict_status, show restrictions status

cvars:

sm_wt_restrict_enable 1/0, enable/disable plugin
sm_wt_offset <int>, offset of score that one team may have more than the other before restriction becomes active
sm_restrict_cmd_unrestrict_all "<cmd>", command that resets all restrictions to off. called each mapchange to get a defined state of restriction
sm_restrict_cmd_t "<cmd>", command to activate restrictions on terrorist team
sm_restrict_cmd_ct "<cmd>", command to activate restrictions on counter-terrorist team
sm_unrestrict_cmd_t "<cmd>", command to disable restrictions on terrorist team
sm_unrestrict_cmd_ct "<cmd>", command to disable restrictions on terrorist team
sm_winstreak_length <wins>, number of subsequent round the loosing team has to win to enable win stream override (default "2"), set to 0 to disable this feature
sm_winstreak_mode 0/1, what shall be done if loosing team has a win streak (0=unrestrict, 1=restrict for both teams, default "1")

version history:

1.0.3 beta: first public release
1.0.4 fixed bug on disabling and reenabling the plugin during one map, added sm_wt_offset
1.2.5 some code cleanups, added win streak handling

red!
10-16-2007, 16:06
Additionally I can provide you my sample config based on ^bugs^ sm_restrict (http://forums.alliedmods.net/showthread.php?t=56863) (possibly instead of a real documentation :mrgreen:):



sm_wt_restrict_enable 1
sm_wt_offset 1
sm_restrict_cmd_unrestrict_all "sm_unrestrict all"
sm_restrict_cmd_t "sm_restrict item team t awp g3sg1 sg550 dummy"
sm_restrict_cmd_ct "sm_restrict item team ct awp g3sg1 sg550 dummy"
sm_unrestrict_cmd_t "sm_unrestrict item team t awp g3sg1 sg550"
sm_unrestrict_cmd_ct "sm_unrestrict item team ct awp g3sg1 sg550"


and here the alternative config for Liams restrict plugin (http://forums.alliedmods.net/showthread.php?t=69987):

sm_wt_restrict_enable 1
sm_wt_offset 1
sm_restrict_cmd_unrestrict_all "sm_unrestrict awp all;sm_unrestrict sg550 all; sm_unrestrict g3sg1 all"
sm_restrict_cmd_t "sm_restrict awp 0 t;sm_restrict sg550 0 t; sm_restrict g3sg1 0 t"
sm_restrict_cmd_ct "sm_restrict awp 0 ct;sm_restrict sg550 0 ct; sm_restrict g3sg1 0 ct"
sm_unrestrict_cmd_t "sm_unrestrict awp t;sm_unrestrict sg550 t; sm_unrestrict g3sg1 t"
sm_unrestrict_cmd_ct "sm_unrestrict awp ct;sm_unrestrict sg550 ct; sm_unrestrict g3sg1 ct"

^BuGs^
10-23-2007, 13:24
red, when I get back from vacation, I will help you work with the API on this. Good idea. :) Kinda like my KDR plugin.

red!
10-23-2007, 18:20
nice idea. at the moment I suffer from a lack of spare time, to write plugins, administrate a CS:S server and do my day-time job.

maybe the most time-consuming job of porting my CS:S-Server to sourcemod is done now, and we'll see what we can do after you vacation. have a nice trip.

ferret
11-05-2007, 09:47
Please edit your plugin and put the id # for Bug's weapon restriction in the "Dependancies" field

red!
11-06-2007, 12:31
Please edit your plugin and put the id # for Bug's weapon restriction in the "Dependancies" field

I would not treat bugs plugin as a hard dependency. This plugin is able to trigger any action on winning/losing team.
In my opinion Bugs plugin is a bit too heavy-weight for this purpose. I use it due to missing alternatives. And even worse bugs plugin very often causes crashed due to some index errors (http://bugs.alliedmods.net/index.php?do=details&task_id=1094) making the whole admin-system unavailable.

andrey (Russia)
11-12-2007, 09:35
Very-very cool

Noobtastic
11-22-2007, 00:20
Just a quick question, do the restrictions get deactivated again after the losing team has made up the difference? For instance, CT is leading with 7-2, I'll have my offset at 5, so the restrictions become active. If the T team levels the score or even just brings it back to 7-3, will the restrictions get deactivated?

red!
11-22-2007, 08:26
Just a quick question, do the restrictions get deactivated again after the losing team has made up the difference? For instance, CT is leading with 7-2, I'll have my offset at 5, so the restrictions become active. If the T team levels the score or even just brings it back to 7-3, will the restrictions get deactivated?

yes, thats the reason why you have to configure

sm_unrestrict_cmd_t "..."
sm_unrestrict_cmd_ct "..."

if teams scores get back in balance both teams get unrestricted.

Noobtastic
11-22-2007, 10:59
Ah yes, of course, thanks, I'll try this plugin on one of my servers :).

Laplace
08-28-2010, 09:31
Hi,

i'm running a CSS server with the weapon_restrict plugin and want to use it together with the wt_restrict plugin - but I dont know how to handle the "interface" to weapon_restrict plugin, i tried:


// Enable / Disable plugin
sm_wt_restrict_enable 1

// Offset of score, that one team may have more than the other before restriction becomes active
sm_wt_offset 5

// Command that resets all restrictions to off. Called each mapchange to get a defined state of restriction
sm_restrict_cmd_unrestrict_all "sm_restrict_awp_t \"1\"; sm_restrict_awp_ct \"1\"; sm_restrict_sg550_t \"1\"; sm_restrict_sg550_ct \"1\"; sm_restrict_g3sg1_t \"1\"; sm_restrict_g3sg1_ct \"1\""

// Command to activate restrictions on terrorist team
sm_restrict_cmd_t "sm_restrict_awp_t \"0\"; sm_restrict_sg550_t \"0\"; sm_restrict_g3sg1_t \"0\""

// Command to activate restrictions on counter-terrorist team
sm_restrict_cmd_ct "sm_restrict_awp_ct \"0\"; sm_restrict_sg550_ct \"0\"; sm_restrict_g3sg1_ct \"0\""

// command to disable restrictions on terrorist team
sm_unrestrict_cmd_t "sm_restrict_awp_t \"1\"; sm_restrict_sg550_t \"1\"; sm_restrict_g3sg1_t \"1\""

// command to disable restrictions on counter-terrorist team
sm_unrestrict_cmd_ct "sm_restrict_awp_ct \"1\"; sm_restrict_sg550_ct \"1\"; sm_restrict_g3sg1_ct \"1\""


because according weapon_restrict documentation is a command like


// Restrict/Unrestrict -1 unrestricts awp for ct
// -
// Default: "-1"
sm_restrict_awp_ct "1"


... but it does not work without or with the quotes \". When i type sm_wtrestrict_status in the client console i get the correct status, so the plugin is working but does not execute the restriction commands, or theres a syntax mistake in my config file. Any hints?

Greetz
Laplace

Laplace
08-29-2010, 17:41
nobody an idea?

Greetz
Laplace

red!
09-13-2010, 18:29
You did not really try to get behind the idea of the plugin nor did you read any of the documentation. Please start reading the first posts ...

Laplace
09-13-2010, 19:00
Hello red!,
thank you for your answer. I think i read the documentation and as far as i understood i need a second plugin to restrict the weapons. I use the weapon_restrict plugin for this stuff, and this plugin is working fine for me.
Now I want to restrict awe and autosniper for the winning team when a difference of more than 5 wins is between the teams. So i set ...

sm_wt_offset 5

To handle the weapon restriction i tried ...

sm_restrict_cmd_t "sm_restrict_awp_t 0; sm_restrict_sg550_t 0;sm_restrict_g3sg1_t 0"

... but it does not restrict the weapons. Or did i something missunderstand under "winning team restriction" ... maybe your plugin is making coffee?

Regards,
Laplace

red!
09-13-2010, 19:29
Ok, maybe I got you wrong. Sorry for that.

For me the plugin works fine with CSS, so I am sure it survived the orange-box update. Did you check the logfile for anything related to this plugin?

And do me a favour and try the command sm_wtrestrict_status from the server console. If the plugin is running correctly it should give a hint about what the plugin thinks about its state ...

Laplace
09-26-2010, 04:45
Hi red!,

today I found the time to analyze the behaviour. As you already mentioned I tried:
sm_wtrestrict_status
[wt_restrict] ct score 9, restriction 0, t score 18, restriction 1

After a check of the cvar sm_restrict_cmd_ct the Server returned

"sm_restrict_cmd_ct" = "sm_restrict_awp_ct"


but it should be:

"sm_restrict_cmd_ct" = "sm_restrict_awp_ct 0;sm_restrict_sg550_ct 0"


I set the cvars within the postwarmup.cfg of the weapon_restrict plugin, this does not to work - all cvar are cutted at the first space character. Now as workaround i added ...

AutoExecConfig(true, "plugin.wt_restrict");

in OnPluginStart() to create and load an own config file for your plugin. After compile and reload it works as expected - thx a lot for this plugin.
Maybe you also can add the line in your release.

Greetings
Laplace

sidjamesbond
01-16-2011, 01:06
so the 2 plugins this is based off of are dis-approved? does that mean this should be dis-approved? post 1 says this is not a stand alone plugin but does not say what additional plugin is needed.

Laplace
01-16-2011, 04:48
Hi,
no it should not be dis-approved because it works fine together with the weapon restrict (http://forums.alliedmods.net/showthread.php?p=950174) plugin.

Best Regards,
Laplace

red!
01-17-2011, 02:37
so the 2 plugins this is based off of are dis-approved? does that mean this should be dis-approved? post 1 says this is not a stand alone plugin but does not say what additional plugin is needed.

This plugin is designed to call any console command, if the winning team condition changes. The above usage examples are just what I called them: Examples. Use it with every restriction plugin you like.

sidjamesbond
01-18-2011, 07:37
ok, cool! it was just confusing to me (noob) as to what plugins it would work for on the first post. thanks!

sidjamesbond
02-12-2011, 20:42
Hi, I am having having trouble getting the plugin to work. hopefully you can identify what my problem is. below is the restrict plugin im using with it. when i type wtrestrict_status it shows its registering as "its working but does not restrict anything.
"[wt_restrict] ct score 6, restriction 1, t score 0,"
any ideas for me to start trouble shooting? thanks, Rob



Hi,
no it should not be dis-approved because it works fine together with the weapon restrict (http://forums.alliedmods.net/showthread.php?p=950174) plugin.

Best Regards,
Laplace

red!
02-14-2011, 18:33
Obviously the plugin is up and running. Most likely the restriction commands you configured do not work as they should. Maybe you should test them isolated from this plugin.

sidjamesbond
02-20-2011, 02:31
For those who need it clear: ITS NOT A STANDALONE PLUGIN, IT NEEDS ANOTHER PLUGIN TO WORK. (I do not appreciate do do the same work twice)



How do i test it alone if it takes another plugin to work? I am not very smart when it comes to this stuff. like i said typing the tr status command shows the spread and restriction 1 for the right team, I have the cvars in my server.cfg file

sm_wt_restrict_enable 1
sm_wt_offset 3
sm_restrict_cmd_unrestrict_all "sm_unrestrict all"
sm_restrict_cmd_t "sm_restrict item team t awp g3sg1 sg550"
sm_restrict_cmd_ct "sm_restrict item team ct awp g3sg1 sg550"
sm_unrestrict_cmd_t "sm_unrestrict item team t awp g3sg1 sg550"
sm_unrestrict_cmd_ct "sm_unrestrict item team ct awp g3sg1 sg550"

i also took off zblock just to make sure that was not messing with it. no KAC. just throwing knives

any advice on how to test alone?

Laplace
02-27-2011, 04:33
Hello sidjamesbond,

I had the same probs at the beginning. Do you use the above mentioned weapon_restrict plugin? then your syntax is wrong.

I configured wt restrict as follows (valid for weapon_restrict plugin):


// This file was auto-generated by SourceMod (v1.3.4)
// ConVars for plugin "wt_restrict.smx"
 
// -
// Default: ""
sm_restrict_cmd_ct "sm_restrict_awp_ct 0;sm_restrict_sg550_ct 0"
// -
// Default: ""
sm_restrict_cmd_t "sm_restrict_awp_t 0;sm_restrict_g3sg1_t 0"
// -
// Default: ""
sm_restrict_cmd_unrestrict_all "sm_restrict_awp_t 1;sm_restrict_awp_ct 1;sm_restrict_sg550_ct 1;sm_restrict_g3sg1_t 1"
// -
// Default: ""
sm_unrestrict_cmd_ct "sm_restrict_awp_ct 1;sm_restrict_sg550_ct 1"
// -
// Default: ""
sm_unrestrict_cmd_t "sm_restrict_awp_t 1;sm_restrict_g3sg1_t 1"
// -
// Default: "0"
sm_wt_offset "4"
// -
// Default: "1"
sm_wt_restrict_enable "1"
// Version of [HANSE] WT-Restrict
// -
// Default: "1.0.4"
wt_restrict_version "1.0.4"


... you can put the restrict and unrestrict strings into the sourcemod.cfg file or (I preffer this) modify the source code of the wt_restrict plugin in line 74 the following statement:


AutoExecConfig(true, "plugin.wt_restrict");


.. then compile again and a config file will be created after restart / reload. You can put then the restrict and unrestrict commands into this file.

Best Regards,
Laplace

sidjamesbond
02-28-2011, 05:06
thank you very much for the reply, i changed the SM cfg file because i do not know how to edit a .smx file. the server is currently empty so i can not test it out at the moment. thank you very much for the help! Rob

TnTSCS
03-28-2011, 19:28
I use this Weapon Restrict (http://forums.alliedmods.net/showthread.php?p=950174) with the following configs in my sourcemod.cfg file:


///////
/////// Winning Team Restrict with Weapon Restrict
///////

// Default: ""
sm_restrict_cmd_ct "sm_restrict awp 0 ct;sm_restrict sg550 0 ct;sm_restrict g3sg1 0 ct;sm_cash t 8000;sm_csay Snipers Restricted for Counter Terrorists;sm_say CTs are DOMINATING, AWPs/Autos are restricted;sm_say Terrorists cash is set to $8,000!! They can buy weapons, watch out!!;sm_say Snipers are restricted for Counter Terrorists;sm_say If a CT has a restricted weapon, it will be removed and money refunded"
// -
// Default: ""
sm_restrict_cmd_t "sm_restrict awp 0 t;sm_restrict sg550 0 t;sm_restrict g3sg1 0 t;sm_cash ct 8000;sm_csay Snipers Restricted for Terrorists;sm_say Ts are DOMINATING, AWPs/Autos are restricted;sm_say Counter Terrorist's cash is set to $8,000!! They can buy weapons, watch out!!;sm_say If a Terrorist has a restricted weapon, it will be removed and money refunded"
// -
// Default: ""
sm_restrict_cmd_unrestrict_all "sm_restrict awp 2 t;sm_restrict awp 2 ct;sm_restrict sg550 2 ct;sm_restrict sg550 2 t;sm_restrict g3sg1 2 t;sm_restrict g3sg1 2 ct;sm_say AWPs and Autos are restricted to 2 per team!!"
// -
// Default: ""
sm_unrestrict_cmd_ct "sm_restrict awp 2 ct;sm_restrict sg550 2 ct;sm_restrict g3sg1 2 ct;sm_csay Snipers UnRestricted for CTs;sm_csay Snipers UnRestricted for CTs;sm_say Snipers UnRestricted for Counter Terrorists;sm_say Snipers UnRestricted for Counter Terrorists"
// -
// Default: ""
sm_unrestrict_cmd_t "sm_restrict awp 2 t;sm_restrict sg550 2 t;sm_restrict g3sg1 2 t;sm_csay Snipers UnRestricted for Ts;sm_csay Snipers UnRestricted for Ts;sm_say Snipers UnRestricted for Terrorists;sm_say Snipers UnRestricted for Terrorists"
// -
// Default: "0"
sm_wt_offset "4"
// -
// Default: "1"
sm_wt_restrict_enable "1"
// Version of [HANSE] WT-Restrict
// -
// Default: "1.0.4"
wt_restrict_version "1.0.4"


I also use the SmCash (http://forums.alliedmods.net/showthread.php?p=494902) plugin.

I've tested this and it works like a charm. Only thing, I think my command is too long because the last sm_say doesn't execute.

TnTSCS
04-23-2011, 19:26
Any update as to why it won't fully execute the sm_restrict_cmd_t? It only executes about half of it.

Here's what I have set for sm_restrict_cmd_t

///////
/////// Winning Team Restrict with Weapon Restrict
///////

// Default: ""
sm_restrict_cmd_ct "sm_restrict awp 0 ct;sm_restrict sg550 0 ct;sm_restrict g3sg1 0 ct;sm_cash @t +4500;sm_say Counter Terrorists are winning by 5, AWPs & AUTOs are restricted for CTs;sm_say Snipers are restricted for Counter Terrorists"
// -
// Default: ""
sm_restrict_cmd_t "sm_restrict awp 0 t;sm_restrict sg550 0 t;sm_restrict g3sg1 0 t;sm_cash @ct +4500;sm_say Terrorists are winning by 5, AWPs & AUTOs are RESTRICTED for Ts;sm_say Snipers are RESTRICTED for Terrorists"
// -
// Default: ""
sm_restrict_cmd_unrestrict_all "sm_restrict awp 2 t;sm_restrict awp 2 ct;sm_restrict sg550 2 ct;sm_restrict sg550 2 t;sm_restrict g3sg1 2 t;sm_restrict g3sg1 2 ct"
// -
// Default: ""
sm_unrestrict_cmd_ct "sm_restrict awp 2 ct;sm_restrict sg550 2 ct;sm_restrict g3sg1 2 ct;sm_say Snipers UnRestricted for Counter Terrorists;sm_say Snipers UnRestricted for Counter Terrorists"
// -
// Default: ""
sm_unrestrict_cmd_t "sm_restrict awp 2 t;sm_restrict sg550 2 t;sm_restrict g3sg1 2 t;sm_say AWPs & AUTOs are UnRestricted for Terrorists;sm_say AWPs & AUTOs are UnRestricted for Terrorists"
// -
// Default: "0"
sm_wt_offset "4"
// -
// Default: "1"
sm_wt_restrict_enable "1"
// Version of [HANSE] WT-Restrict
// -
// Default: "1.0.4"
wt_restrict_version "1.0.4"

Here's the outcome of it:
[SM] Console set cash of Player1 to $6650 [+4500]
[SM] Console set cash of Player2 to $9500 [+4500]
[SM] Console restricted awp to 0 for t
[SM] Console restricted sg550 to 0 for t
[SM] Console restricted g3sg1 to 0 for t
(ALL) Console: Terrorists are winning by 5, AWPs & AU

TnTSCS
04-23-2011, 19:28
hmm... I think I found it - I took a look at the .sp and saw that you limit the sm_restrict_cmd_t to 128 where you allow 256 for the ct.

I guess I'll try my hand at modifying it and recompiling... then I'll test and let you know :)


...:: TnT Edit::...

Successfully edited... here's the fixed version.
I changed the version from 1.0.4 to 1.0.4a

Here's what it was:

set_T_restriction(bool:restrict)
{
new String:cmd[256];
if (restricted_T!=restrict)
{
restricted_T=restrict;

if (restrict)
{
// call sm_restrict_cmd_t
GetConVarString(sm_restrict_cmd_t, cmd, 128);
//PrintToServer("[wt_restrict] exec: %s", cmd);
ServerCommand("%s", cmd);
}
else
{
// call sm_unrestrict_cmd_t
GetConVarString(sm_unrestrict_cmd_t, cmd, 128);
//PrintToServer("[wt_restrict] exec: %s", cmd);
ServerCommand("%s", cmd);
}
}
}


Here's what it is:


set_T_restriction(bool:restrict)
{
new String:cmd[256];
if (restricted_T!=restrict)
{
restricted_T=restrict;

if (restrict)
{
// call sm_restrict_cmd_t
GetConVarString(sm_restrict_cmd_t, cmd, 256);
//PrintToServer("[wt_restrict] exec: %s", cmd);
ServerCommand("%s", cmd);
}
else
{
// call sm_unrestrict_cmd_t
GetConVarString(sm_unrestrict_cmd_t, cmd, 256);
//PrintToServer("[wt_restrict] exec: %s", cmd);
ServerCommand("%s", cmd);
}
}
}

TnTSCS
04-25-2011, 12:15
I think that the Winning Team Restrict could be enhanced to include a variable to allow the execution of a set of commands (similar to sm_restrict_cmd_ct/t) if 1/2 of a "blowout" limit is reached.

For example, add cvar to set the "blowout" limit. Say sm_restrict_blowout is set to 10, what that means is if a team is winning by 10 rounds it ends the map and forces the game to go to the next map.
If 1/2 of that blowout is reached it executes sm_restrict_cmd_blowout_ct/t, which admin could make whatever they wanted (pay loosing team, execute a scrample teams, whatever).

Example cvars:
sm_restrict_blowout 10 // (0-disable, number) If a team is winning by this number of rounds the map will end, and the next queued map will be executed
sm_restrict_cmd_blowout_ct "Command1;Command2" // Command to activate restrictions on Counter-Terrorist team (executed only once per map)
sm_restrict_cmd_blowout_t "Command1;Command2" // Command to activate restrictions on Terrorist team (executed only once per map)

ougogo
04-25-2011, 13:23
Hello,

being French, I do not really understand the use of this plugin.


Could I use it to restrict all weapons except the knife to the team that lost the round? That is to say from the time they lose and when the next round begins.


Sincerely,

Hugo

ougogo
04-26-2011, 10:11
Could you help me please ?

ougogo
04-27-2011, 15:28
Up please :s

TnTSCS
04-27-2011, 18:31
Hello,

being French, I do not really understand the use of this plugin.


Could I use it to restrict all weapons except the knife to the team that lost the round? That is to say from the time they lose and when the next round begins.


Sincerely,

Hugo

Are you wanting to keep teams from attacking each other at the end of a round?

ougogo
04-28-2011, 06:10
In fact I hope that the loser of the round with only the knife as a weapon. But only losers, no winners.

TnTSCS
04-28-2011, 09:49
I don't think this is the plugin for that... but I could be wrong, maybe someone else knows a plugin that will do what he wants, which is the loser of the round has their weapons stripped

ougogo
04-29-2011, 17:09
Arf, no news? :s

TnTSCS
04-29-2011, 17:45
This isn't what you are asking for, but it still punishes the losing team

http://forums.alliedmods.net/showthread.php?p=1254308

ougogo
04-30-2011, 14:40
No no, I really want a script so when the team loses the round, she found only with the knife. But only for a few seconds to end of round, not for the next round.


Sincerely,

Hugo

Sagenth
07-06-2011, 03:10
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#define PLUGIN_VERSION "1.0.4"




public Plugin:myinfo =
{
name = "HANSE WT-Restrict",
author = "red!",
description = "Provides winning team restrictions",
version = PLUGIN_VERSION,
url = "http://www.hanse-clan.de"
};

/* Handles to convars used by plugin */
new Handle:sm_wt_restrict_enable;
new Handle:sm_restrict_cmd_t;
new Handle:sm_restrict_cmd_ct;
new Handle:sm_unrestrict_cmd_t;
new Handle:sm_unrestrict_cmd_ct;
new Handle:sm_restrict_cmd_unrestrict_all;
new Handle:sm_wt_offset;
new Handle:sm_wt_offset_only;

public OnPluginStart()
{


// connect to the setting convars

sm_wt_restrict_enable = FindConVar("sm_wt_restrict_enable");
if (sm_wt_restrict_enable==INVALID_HANDLE) {
CreateConVar("sm_wt_restrict_enable", "1");
sm_wt_restrict_enable = FindConVar("sm_wt_restrict_enable");
}

sm_wt_offset = FindConVar("sm_wt_offset");
if (sm_wt_offset==INVALID_HANDLE) {
CreateConVar("sm_wt_offset", "0");
sm_wt_offset = FindConVar("sm_wt_offset");
}

sm_wt_offset_only = FindConVar("sm_wt_offset_only");
if (sm_wt_offset==INVALID_HANDLE) {
CreateConVar("sm_wt_offset_only", "0");
sm_wt_offset = FindConVar("sm_wt_offset_only");
}

sm_restrict_cmd_t = FindConVar("sm_restrict_cmd_t");
if (sm_restrict_cmd_t==INVALID_HANDLE) {
CreateConVar("sm_restrict_cmd_t", "");
sm_restrict_cmd_t = FindConVar("sm_restrict_cmd_t");
}
sm_restrict_cmd_ct = FindConVar("sm_restrict_cmd_ct");
if (sm_restrict_cmd_ct==INVALID_HANDLE) {
CreateConVar("sm_restrict_cmd_ct", "");
sm_restrict_cmd_ct = FindConVar("sm_restrict_cmd_ct");
}
sm_unrestrict_cmd_t = FindConVar("sm_unrestrict_cmd_t");
if (sm_unrestrict_cmd_t==INVALID_HANDLE) {
CreateConVar("sm_unrestrict_cmd_t", "");
sm_unrestrict_cmd_t = FindConVar("sm_unrestrict_cmd_t");
}
sm_unrestrict_cmd_ct = FindConVar("sm_unrestrict_cmd_ct");
if (sm_unrestrict_cmd_ct==INVALID_HANDLE) {
CreateConVar("sm_unrestrict_cmd_ct", "");
sm_unrestrict_cmd_ct = FindConVar("sm_unrestrict_cmd_ct");
}

sm_restrict_cmd_unrestrict_all = FindConVar("sm_restrict_cmd_unrestrict_all");
if (sm_restrict_cmd_unrestrict_all==INVALID_HAND LE) {
CreateConVar("sm_restrict_cmd_unrestrict_all", "");
sm_restrict_cmd_unrestrict_all = FindConVar("sm_restrict_cmd_unrestrict_all");
}

CreateConVar("wt_restrict_version", PLUGIN_VERSION, "Version of [HANSE] WT-Restrict", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_SPONLY);


// hook round start & round end events
//HookEvent("round_end",OnRoundEnd,EventHookMode_Post);
HookEvent("round_start",OnRoundStart);

RegConsoleCmd("sm_wtrestrict_status", debugPrint);
CreateTimer(5.0, OnRoundEnd, _, TIMER_REPEAT);
}

new bool:restricted_T=false;
new bool:restricted_CT=false;
new bool:bdebug=false;

public Action:debugPrint(client, args)
{
//PrintToConsole(client,"[wt_restrict] ct score %d, restriction %d, t score %d, restriction %d", GetTeamScore(TEAM_CT), restricted_CT, GetTeamScore(TEAM_T), restricted_T);
return Plugin_Handled;
}



set_T_restriction(bool:restrict)
{
new String:cmd[256];
if (restricted_T!=restrict)
{
restricted_T=restrict;

if (restrict)
{
// call sm_restrict_cmd_t
GetConVarString(sm_restrict_cmd_t, cmd, 128);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
else
{
// call sm_unrestrict_cmd_t
GetConVarString(sm_unrestrict_cmd_t, cmd, 128);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
}
}

set_CT_restriction(bool:restrict)
{
new String:cmd[256];
if (restricted_CT!=restrict)
{
restricted_CT=restrict;

if (restrict)
{
// call sm_restrict_cmd_ct
GetConVarString(sm_restrict_cmd_ct, cmd, 256);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
else
{
// call sm_unrestrict_cmd_ct
GetConVarString(sm_unrestrict_cmd_ct, cmd, 256);
//PrintToServer("[wt_restrict] exec: %s", cmd);
//ServerCommand("%s", cmd);
}
}
}

#define TEAM_T 2
#define TEAM_CT 3

public Action:OnRoundEnd(Handle: timer)
{
// break if plugin is disabled
if (GetConVarInt(sm_wt_restrict_enable)==0)
{
set_CT_restriction(false);
set_T_restriction(false);
return;
}

// evaluate teams to actiavte restrictions for
if(GetTeamScore(TEAM_T) > GetTeamScore(TEAM_CT))
{//Terrorists are in the lead
if((GetTeamScore(TEAM_T) - GetTeamScore(TEAM_CT)) >= GetConVarInt(sm_wt_offset))
{//Terrorirsts need to be restricted
set_CT_restriction(false);
set_T_restriction(true);
}
else if(GetConVarInt(sm_wt_offset_only) != 0)
{//Terrorists no longer need restriction
set_T_restriction(false);
}
}
else if(GetTeamScore(TEAM_CT) > GetTeamScore(TEAM_T))
{//CT team is in the lead
if((GetTeamScore(TEAM_CT) - GetTeamScore(TEAM_T)) >= GetConVarInt(sm_wt_offset))
{//CT team needs to be restricted
set_CT_restriction(true);
set_T_restriction(false);
}
else if(GetConVarInt(sm_wt_offset_only) != 0)
{//CT team no longer needs restriction
set_CT_restriction(false);
}
}
else//Even game
{
set_CT_restriction(false);
set_T_restriction(false);
}
if(bdebug)
PrintToChatAll("exit");
}

public OnRoundStart(Handle: event , const String: name[] , bool: dontBroadcast)
{
// announcements
if(restricted_T)
{
PrintToChatAll("\x04Terrorists: Awp/Auto Restriction = 0");
PrintToChatAll("\x04Counter-Terrorists: Awp/Auto Restriction = 2");
}
else if(restricted_CT)
{
PrintToChatAll("\x04Terrorists: Awp/Auto Restriction = 2");
PrintToChatAll("\x04Counter-Terrorists: Awp/Auto Restriction = 0");
}
else
{
PrintToChatAll("\x04Terrorists: Awp/Auto Restriction = 2");
PrintToChatAll("\x04Counter-Terrorists: Awp/Auto Restriction = 2");
}
}

public OnMapStart()
{
set_CT_restriction(false);
set_T_restriction(false);

//new String:cmd[256];
//GetConVarString(sm_restrict_cmd_unrestrict_al l, cmd, 256);
//ServerCommand("%s", cmd);
}


I don't fully understand why this mod was broken, but I've fixed it with a timer. I spent 5 hours and didn't fix anything, I ended up replacing the OnRoundEnd event hook with a timer of the same name.

For some strange reason it was rarely completing the call "onroundend" which resulted in one debug print actually being printed, but no others.
I was able to figure out it happened usually on a function call or during a "new" identifier

Anyways here is the code, and here is the .smx
It is hardcoded for every 5 seconds. If you don't want it to run its checks every 5 seconds just open up the source and find 5.0 change it and put it into the compiler on the sourcemod homepage.

Edit: Removed inconsistencies in colour formatting and removed some debugging information.

I forgot to mention earlier that I have also hardcoded the announcements to say awp and auto restricted to 2 or 0 depending on the winning team or if the teams are even. I just didn't care for the regular ones, they are still there but commented. "//ServerCommand("%s", cmd);" remove the //

My announcements are in OnRoundStart

TnTSCS
07-06-2011, 10:11
Sagenth: I think I'll try your OnRoundEnd sample - it looks a little cleaner at first glance

Also, you should change
GetConVarString(sm_restrict_cmd_t, cmd, 128); and GetConVarString(sm_unrestrict_cmd_t, cmd, 128);
to
GetConVarString(sm_restrict_cmd_t, cmd, 256); and GetConVarString(sm_unrestrict_cmd_t, cmd, 128);
because the two for cmd_ct are set to 256 and 128 wasn't enough for me since I wanted four lines of text to let everyone know weapons had been restricted and the loosing team was awarded cash.

And the hard coded AWP/Auto message is fine for you, but this plugin was meant to be a low level plugin and completely dependent on other plugins - it wasn't necessarily meant to restrict awps/autos (even though that's what I use it for ;)) If someone wanted to restrict awps/autos to 3 per team, I guess all they'd have to do is alter the hard coded message and change the 2 to a 3

Also, next time, just upload the .sp file and this forum will create the .smx for you :)

...:: TnT Edit ::...
The current OnRoundEnd on original plugin is kinda junky... thanks for your cleaner code (although the original code has worked for me flawlessly)

public OnRoundEnd(Handle: event , const String: name[] , bool: dontBroadcast)
{
// count scores
new winner = GetEventInt(event, "winner");

if (winner==TEAM_T) score_t++;
if (winner==TEAM_CT) score_ct++;


// break if plugin is disabled
if (GetConVarInt(sm_wt_restrict_enable)==0)
{
set_CT_restriction(false);
set_T_restriction(false);
return;
}


new offset = GetConVarInt(sm_wt_offset);

// evaluate teams to actiavte restrictions for
if ((score_t+offset>=score_ct) && (score_ct+offset>=score_t)) {
set_CT_restriction(false);
set_T_restriction(false);
} else if (score_t>score_ct) {
set_CT_restriction(false);
set_T_restriction(true);
} else if (score_t<score_ct) {
set_CT_restriction(true);
set_T_restriction(false);
}
}

red!
03-29-2012, 17:50
updated plugin