Raised This Month: $120 Target: $400

TF2 Weapon Ban Code [Ya gotta help me]

Post New Thread Reply   
Thread Tools Display Modes
Author Message
Junior Member
Join Date: Sep 2018
Old 09-15-2018 , 18:09   TF2 Weapon Ban Code [Ya gotta help me]
Reply With Quote #1

The snippet of code below is supposed to do 3 things, can you guess what they are? Because the game can't:
public Action OnPlayerSpawn(Handle event, const char[] name, bool dontBroadcast)
	int client = GetClientOfUserId(GetEventInt(event, "userid"));
	TFClassType class = TF2_GetPlayerClass(client);
	TFTeam team = TF2_GetClientTeam(client);
	if(class == TFClass_Scout)
		int weaponone = GetPlayerWeaponSlot(client, 0);
		int weapontwo = GetPlayerWeaponSlot(client, 1);
		int weaponthree = GetPlayerWeaponSlot(client, 2);
		int oneindex = GetEntProp(weaponone, Prop_Send, "m_iItemDefinitionIndex");
		int twoindex = GetEntProp(weapontwo, Prop_Send, "m_iItemDefinitionIndex");
		int threeindex = GetEntProp(weaponthree, Prop_Send, "m_iItemDefinitionIndex");
		PrintToChat(client, "Scout: Current weapon indexes are %i, %i, and %i", oneindex, twoindex, threeindex);
		if(team == TFTeam_Blue)
                        SetEntPropEnt(client, Prop_Send, "m_hActiveWeapon", weaponthree);
			TF2_RemoveWeaponSlot(client, 0);
			if(twoindex != 46 || 163 || 222 || 812 || 833 || 1121 || 1145)
				TF2_RemoveWeaponSlot(client, 1);
Thing Number One: If the player is a Blu Scout, switch their active weapon slot to melee (slot 2)
Thing Number Two: If the player is a Blu Scout, remove their primary weapon (slot 0)
Thing Number Three: If the weapon index doesn't match the indexes of any of these weapons (46, 163, 222, 812, 833, 1121, 1145), remove their secondary weapon (slot 1)

(Those weapon indexes are Bonk!, Mad Milk, and anything else that isn't a pistol)

Simple right? That's what I thought. Here's what happens when I test it:

Problem Number One: Though it does remove weapon slot 0, and does switch the player's active weapon to slot 1, it doesn't do it immediately. Instead of spawning the Scout with weapon slot 1 active, it spawns him with weapon slot 0 active, then switches to weapon slot 1. Since there's no weapon in slot 0, you have blank hands and a t-posing Scout for the remainder of the switch time, every time you hit a resupply locker.

Problem Number Two: Though the game detects the weapon indexes correctly (tested with that PrintToChat line), it does diddly jack to the if statement. So the game knows what weapon the Scout has equipped in slot 1, but removes slot 1 regardless of whether the weapon index matches any of the given exceptions. Now what's that all about?

Problem Number Three: is a hypothetical issue. What if I decide that the Wrap Assassin is just too good, and needs to be banned? If I used the same method as Thing Number Three (given I can make it work), then Scout has the possibility of spawning with no weapons at all! That's a Texas sized problem if you ask me! How can I make it so a Scout with the Wrap Assassin equipped can spawn and have that sucker replaced with the default bat?

I should also mention real quick that OnPlayerSpawn is actually hooked to post_inventory_application, so if that's part of the problem, tell me, but I'd like this to update when you hit a resupply locker or manually select a loadout.

If possible, I would like to contain this all in a plugin, not in a server config file. This is part of a larger plugin, and I like clean, all-in-one packages.

Last edited by ABNTGeneric; 09-17-2018 at 04:14.
ABNTGeneric is offline
Veteran Member
Join Date: Jun 2016
Location: Catlands
Old 09-15-2018 , 19:20   Re: TF2 Weapon Ban Code [Ya gotta help me]
Reply With Quote #2

MoveThread(this, "SourceMod")
Have A Relaxing Day | Wiki
Relaxing is offline
Junior Member
Join Date: Sep 2018
Old 09-17-2018 , 04:01   Re: TF2 Weapon Ban Code [Ya gotta help me]
Reply With Quote #3

Originally Posted by Relaxing View Post
MoveThread(this, "SourceMod")
Wow, I can't believe I didn't notice that sooner. I feel like such an idiot, lol
ABNTGeneric is offline

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 19:09.

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