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

Problems setting the weapons of a player.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Borlea
Junior Member
Join Date: May 2014
Old 05-24-2014 , 16:01   Problems setting the weapons of a player.
Reply With Quote #1

Trying to force a player to use a Eyelander and and Chargin' Targe, But having problems with my code. I make sure the class is a demoman before trying to set the weapons.

Heres the code
Code:
	new melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
	if (melee == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_weapon_sword");
		TF2Items_SetItemIndex(item, 132);
		melee = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, melee);
	}
	
	new secondary = GetPlayerWeaponSlot(client, TFWeaponSlot_Secondary);
		
	if (secondary == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_wearable_demoshield");
		TF2Items_SetItemIndex(item, 131);
		secondary = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, secondary);
	}
The location of where I got Item Index and ClassNames are from Here

MetaMod(1.10.0)
Sourcemod(1.5.3)
TF2Items(1.6.0)

Sorry if this is wrong place, kinda new here and just saw a whole section on the forums, and since I used TF2Items I'm just guessing this is the location to put this.
Borlea is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 05-24-2014 , 17:50   Re: Problems setting the weapons of a player.
Reply With Quote #2

Well, you have a check whether or not the player has secondary/melee weapons equipped.
Do you remove their weapons beforehand? If not, then that's your problem.
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
Borlea
Junior Member
Join Date: May 2014
Old 05-24-2014 , 17:57   Re: Problems setting the weapons of a player.
Reply With Quote #3

Quote:
Originally Posted by pcmaster View Post
Well, you have a check whether or not the player has secondary/melee weapons equipped.
Do you remove their weapons beforehand? If not, then that's your problem.
I think I'm not properly removing their weapons, lemme try and try some things.

Last edited by Borlea; 05-24-2014 at 17:58.
Borlea is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 05-24-2014 , 18:05   Re: Problems setting the weapons of a player.
Reply With Quote #4

Quote:
Originally Posted by Borlea View Post
I think I'm not properly removing their weapons, lemme try and try some things.
Yea, due to that:

Code:
if (melee == -1){
It doesn't even go into the block where it spawns the weapon.
Before them, you should do:

Code:
TF2_RemoveWeaponSlot(client, slot)
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
Borlea
Junior Member
Join Date: May 2014
Old 05-24-2014 , 18:09   Re: Problems setting the weapons of a player.
Reply With Quote #5

Quote:
Originally Posted by pcmaster View Post
-snip
Doing that seems to have removed the ability to select that slot at all, am I doing it wrong?
(sorry for being a noob)

Code:
	new melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Melee);
	if (melee == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_weapon_sword");
		TF2Items_SetItemIndex(item, 132);
		melee = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, melee);
	}
	
	new secondary = GetPlayerWeaponSlot(client, TFWeaponSlot_Secondary);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Secondary);
	if (secondary == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_wearable_demoshield");
		TF2Items_SetItemIndex(item, 131);
		secondary = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, secondary);
	}

Last edited by Borlea; 05-24-2014 at 18:09.
Borlea is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 05-24-2014 , 18:36   Re: Problems setting the weapons of a player.
Reply With Quote #6

Quote:
Originally Posted by Borlea View Post
Doing that seems to have removed the ability to select that slot at all, am I doing it wrong?
(sorry for being a noob)

Code:
	new melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Melee);
	if (melee == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_weapon_sword");
		TF2Items_SetItemIndex(item, 132);
		melee = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, melee);
	}
	
	new secondary = GetPlayerWeaponSlot(client, TFWeaponSlot_Secondary);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Secondary);
	if (secondary == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_wearable_demoshield");
		TF2Items_SetItemIndex(item, 131);
		secondary = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, secondary);
	}
try:

Code:
	new melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Melee);
	melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
	if (melee == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_weapon_sword");
		TF2Items_SetItemIndex(item, 132);
		melee = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, melee);
	}
	
	new secondary = GetPlayerWeaponSlot(client, TFWeaponSlot_Secondary);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Secondary);
	secondary = GetPlayerWeaponSlot(client, TFWeaponSlot_Secondary);
	if (secondary == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_ALL);
		TF2Items_SetClassname(item, "tf_wearable_demoshield");
		TF2Items_SetItemIndex(item, 131);
		secondary = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, secondary);
	}
[/QUOTE]

Last edited by WildCard65; 05-24-2014 at 18:36.
WildCard65 is offline
Borlea
Junior Member
Join Date: May 2014
Old 05-24-2014 , 18:40   Re: Problems setting the weapons of a player.
Reply With Quote #7

Quote:
Originally Posted by WildCard65 View Post
-snip
I did notice I was getting the weapon then removing the weapon, which did nothing cause code still thinks I had the weapon and ignored the if check again, but changing it around didn't fix it. Tried your code and it still didn't work sadly, just crashes the server
Borlea is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 05-24-2014 , 18:52   Re: Problems setting the weapons of a player.
Reply With Quote #8

try:

Code:
	new melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Melee);
	melee = GetPlayerWeaponSlot(client, TFWeaponSlot_Melee);
	if (melee == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_CLASSNAME|OVERRIDE_ITEM_DEF);
		TF2Items_SetClassname(item, "tf_weapon_sword");
		TF2Items_SetItemIndex(item, 132);
		melee = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, melee);
	}
	
	new secondary = GetPlayerWeaponSlot(client, TFWeaponSlot_Secondary);
	TF2_RemoveWeaponSlot(client, TFWeaponSlot_Secondary);
	secondary = GetPlayerWeaponSlot(client, TFWeaponSlot_Secondary);
	if (secondary == -1){
		new Handle:item = TF2Items_CreateItem(OVERRIDE_CLASSNAME|OVERRIDE_ITEM_DEF);
		TF2Items_SetClassname(item, "tf_wearable_demoshield");
		TF2Items_SetItemIndex(item, 131);
		secondary = TF2Items_GiveNamedItem(client, item);
		CloseHandle(item);
		EquipPlayerWeapon(client, secondary);
	}
WildCard65 is offline
Borlea
Junior Member
Join Date: May 2014
Old 05-24-2014 , 19:04   Re: Problems setting the weapons of a player.
Reply With Quote #9

Quote:
Originally Posted by WildCard65 View Post
-snip
Server is still crashing when I select a team, here I'll give more info on what I'm doing

The event I'm setting the weapons in is hooked by doing:
HookEvent("post_inventory_application", Event_Inventory);

I make sure the class is a demoman being setting the weapon to eyelander and chargin' targe


I set the player to a demoman on player spawn event which is hooked by doing:
HookEvent("player_spawn", Event_PlayerSpawn);

I change the class by doing this

Code:
TF2_SetPlayerClass(client, TFClass_DemoMan, false); 
		
TF2_RespawnPlayer(client);
TF2_RegeneratePlayer(client);

Then I have OnClientPutInServer, and set the players class as demoman via:
Code:
new TFClassType:class;
class = TFClass_DemoMan;
	
SetEntProp(client, Prop_Send, "m_iDesiredPlayerClass", class);

Last edited by Borlea; 05-24-2014 at 19:05.
Borlea is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-24-2014 , 22:30   Re: Problems setting the weapons of a player.
Reply With Quote #10

GetPlayerWeaponSlot won't give you the index of any items of the tf_wearable or tf_wearable_demoshield class. You'd need GetItemForLoadoutSlot for that, but that requires CTFPlayer GameData (a signature specifically).
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-24-2014 at 22:31.
Powerlord 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 22:08.


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