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

[TF2] [Question] How to spawn a demoman shield


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Athena AI
Junior Member
Join Date: Jul 2018
Old 08-22-2019 , 21:32   [TF2] [Question] How to spawn a demoman shield
Reply With Quote #1

I've been trying lately to spawn a shield via this Spawn Weapon stock I found. But nothing I try its working and it keeps crashing the server if anyone can help it would be appreciated a lot.

Code:
stock SpawnWeapon(client, String:name[], index, level, qual, String:att[])
{
	new Handle:hWeapon=TF2Items_CreateItem(OVERRIDE_ALL|FORCE_GENERATION);
	if(hWeapon==INVALID_HANDLE)
	{
		return -1;
	}

	TF2Items_SetClassname(hWeapon, name);
	TF2Items_SetItemIndex(hWeapon, index);
	TF2Items_SetLevel(hWeapon, level);
	TF2Items_SetQuality(hWeapon, qual);
	new String:atts[32][32];
	new count=ExplodeString(att, ";", atts, 32, 32);

	if(count % 2)
	{
		--count;
	}

	if(count>0)
	{
		TF2Items_SetNumAttributes(hWeapon, count/2);
		new i2;
		for(new i; i<count; i+=2)
		{
			new attrib=StringToInt(atts[i]);
			if(!attrib)
			{
				LogError("Bad weapon attribute passed: %s ; %s", atts[i], atts[i+1]);
				CloseHandle(hWeapon);
				return -1;
			}

			TF2Items_SetAttribute(hWeapon, i2, attrib, StringToFloat(atts[i+1]));
			i2++;
		}
	}
	else
	{
		TF2Items_SetNumAttributes(hWeapon, 0);
	}

	new entity=TF2Items_GiveNamedItem(client, hWeapon);
	CloseHandle(hWeapon);
	EquipPlayerWeapon(client, entity);
	return entity;
}
Athena AI is offline
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 08-23-2019 , 07:41   Re: [TF2] [Question] How to spawn a demoman shield
Reply With Quote #2

This is what i use to create demoshield, just change the definition index and the model path
Code:
public void OnPluginStart(){
	Handle hGameConf = LoadGameConfigFile("tf2.wearables");
	if (hGameConf == null) return;
	StartPrepSDKCall(SDKCall_Player);
	PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "CTFPlayer::EquipWearable");
	PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
	hSDKEquipWearable = EndPrepSDKCall();
}

void CreateShield(int client){
	TF2_RemoveWeaponSlot(client, 1);
	int ent = CreateEntityByName("tf_wearable_demoshield");
	SetEntProp(ent, Prop_Send, "m_nModelIndexOverrides", PrecacheModel("models/weapons/c_models/c_persian_shield/c_persian_shield_all.mdl"));
	SetEntProp(ent, Prop_Send, "m_iItemDefinitionIndex", 406);
	DispatchSpawn(ent);
	SDKCall(hSDKEquipWearable, client, ent);
}
And here is tf2.wearables.txt
Code:
"Games"
{
	"tf"
	{
		"Offsets"
		{
			"CTFPlayer::EquipWearable"
			{
				"windows"	"430"
				"linux"		"431"
				"mac"		"431"
			}
		}
	}
}
It doesnt work and it crashes your server because a demoshield is considered as a wearable, and not a weapon, thats why
__________________
My Steam I take private requests if related with TF2
My Plugins
Facksy is offline
Athena AI
Junior Member
Join Date: Jul 2018
Old 08-23-2019 , 17:39   Re: [TF2] [Question] How to spawn a demoman shield
Reply With Quote #3

Huh interesting but is there any way to edit its attributes and assign custom ones as well? And does it also charge and keep its normal attrributes?

Last edited by Athena AI; 08-23-2019 at 17:40.
Athena AI is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 08-24-2019 , 00:36   Re: [TF2] [Question] How to spawn a demoman shield
Reply With Quote #4

I did this a different way. I used TF2Items Give Weapon and TF2Attributes, but I ran into a problem.

I am unable to set attributes on the shield after it is given.

Code:
GiveFestiveTarge(client)
{
	if (IsValidClient(client))
	{
		TF2_RemoveWeaponSlot(client, 1);
		TF2Items_GiveWeapon(client, 1144);
		new weapon = GetPlayerWeaponSlot(client, 1); 
		TF2Attrib_SetByName(weapon, "charge time increased", 2.0);
		TF2Attrib_SetByName(weapon, "charge recharge rate increased", 2.0);
		TF2Attrib_SetByName(weapon, "charge impact damage increased", 2.0);	
		TF2Attrib_SetByName(weapon, "mult charge turn control", 5.0);
	}
}
It gives the weapon, and I can apply attributes to any other slot except slot 1. Once slot 1 is removed any attempt to set an attribute on slot 1 results in Ivalid entity (iEntity=-1). I'm using slot 1 since the TF2 Wiki (link: https://wiki.alliedmods.net/Team_For....5BSlot_1.5D_4 ) shows demoshields belong in slot 1.

Does anyone know how to apply attributes to a demoshield after it is given?
PC Gamer is offline
Facksy
Senior Member
Join Date: Apr 2017
Location: +2+2
Old 08-24-2019 , 07:29   Re: [TF2] [Question] How to spawn a demoman shield
Reply With Quote #5

Quote:
Originally Posted by PC Gamer View Post
I did this a different way. I used TF2Items Give Weapon and TF2Attributes, but I ran into a problem.

I am unable to set attributes on the shield after it is given.

Code:
GiveFestiveTarge(client)
{
	if (IsValidClient(client))
	{
		TF2_RemoveWeaponSlot(client, 1);
		TF2Items_GiveWeapon(client, 1144);
		new weapon = GetPlayerWeaponSlot(client, 1); 
		TF2Attrib_SetByName(weapon, "charge time increased", 2.0);
		TF2Attrib_SetByName(weapon, "charge recharge rate increased", 2.0);
		TF2Attrib_SetByName(weapon, "charge impact damage increased", 2.0);	
		TF2Attrib_SetByName(weapon, "mult charge turn control", 5.0);
	}
}
It gives the weapon, and I can apply attributes to any other slot except slot 1. Once slot 1 is removed any attempt to set an attribute on slot 1 results in Ivalid entity (iEntity=-1). I'm using slot 1 since the TF2 Wiki (link: https://wiki.alliedmods.net/Team_For....5BSlot_1.5D_4 ) shows demoshields belong in slot 1.

Does anyone know how to apply attributes to a demoshield after it is given?
The demoshield is not considered as a weapon, but as a wearable ("tf_wearable_demoshield"), so GetPlayerWeaponSlot() will return -1 since thats not a weapon, if you want to modify attibutes, you can loop through all entities with classname "tf_wearable_demoshield", check the "m_hOwnerEntity", and then you can apply attributes on the shield, tested and it works for me
__________________
My Steam I take private requests if related with TF2
My Plugins
Facksy is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 08-24-2019 , 14:32   Re: [TF2] [Question] How to spawn a demoman shield
Reply With Quote #6

Thanks Facksy, that helped!

Athena AI... The attached code will allow you to give a Festive Targe with sample attributes to a target player. I'm trying to improve my coding skills so please feel free to edit/critique.

Solution:
Code:
GiveFestiveTarge(client)
{
	if (IsValidClient(client))
	{
		TF2_RemoveWeaponSlot(client, 1);
		TF2Items_GiveWeapon(client, 1144);
		
		new iEntity = -1;
		while ((iEntity = FindEntityByClassname(iEntity, "tf_wearable_demoshield")) != -1)
		{
			if (client == GetEntPropEnt(iEntity, Prop_Data, "m_hOwnerEntity"))
			{
				TF2Attrib_SetByName(iEntity, "charge time increased", 4.0);
				TF2Attrib_SetByName(iEntity, "charge recharge rate increased", 3.0);
				break;
			}
		}			
	}
}
Plugin Command: givetarge
can target self or others
to target self: !givetarge
to target others: !givetarge playername

Enjoy!
Attached Files
File Type: sp Get Plugin or Get Source (givetarge.sp - 99 views - 3.7 KB)
File Type: smx givetarge.smx (7.1 KB, 87 views)

Last edited by PC Gamer; 08-24-2019 at 14:33.
PC Gamer is offline
Athena AI
Junior Member
Join Date: Jul 2018
Old 08-24-2019 , 20:18   Re: [TF2] [Question] How to spawn a demoman shield
Reply With Quote #7

Hey, that's pretty cool thanks a lot for it, man!
Athena AI is offline
Reply


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 08:14.


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