PDA

View Full Version : Changing a weapon with TF2 items.


ReFlexPoison
06-25-2012, 04:23
Now I am very unfamiliar with TF2Items and I've been programming a new deathrun beta for my gaming community, is it possible to exchange weapons for others. I do apologize if this question has been raised before, but atm, I'm throwing out a couple of posts before I get some sleep. :oops:

Thanks in advance.

Leonardo
06-25-2012, 06:40
um
wait
deathrun...
with weapon...
DA HELL?!

ReFlexPoison
06-25-2012, 12:27
um
wait
deathrun...
with weapon...
DA HELL?!

I can go into great details in why we use melee weapons, but, atm, it is all stock, meaning hats are disabled. I'm mainly asking so I can disable certain weapons and return it to something else so, for example, demomans can't charge.

Leonardo
06-25-2012, 13:08
remove chargin targe - and demo can't charge.
simple?
tf2_stocks has TF2_RemoveWeaponSlot (http://docs.sourcemod.net/api/index.php?fastload=show&id=857&)();
not a big deal

ReFlexPoison
06-25-2012, 15:12
remove chargin targe - and demo can't charge.
simple?
tf2_stocks has TF2_RemoveWeaponSlot (http://docs.sourcemod.net/api/index.php?fastload=show&id=857&)();
not a big deal

doesn't work as shields aren't actual weapon slots.

Leonardo
06-25-2012, 16:08
did you test that?

ReFlexPoison
06-25-2012, 16:40
did you test that?

yes? i don't think i'm missing anything when i do it, but yes, i removed all slots except melee

Thrawn2
06-25-2012, 16:59
take a look at the modules from tNoUnlocksPls (http://forums.alliedmods.net/showthread.php?t=140045).

Powerlord
06-25-2012, 17:38
doesn't work as shields aren't actual weapon slots.

That's something that annoyed me when I was testing GetPlayerWeaponSlot with TF2 Item indexes. tf_wearable and tf_wearable_demoshield don't appear as standard items, and you instead have to block them via TF2Items_OnGiveNamedItem and returning Plugin_Handled to prevent it from being given to them.

Something like this:


public Action:TF2Items_OnGiveNamedItem(client, String:classname[], iItemDefinitionIndex, &Handle:hItem)
{
if (StrEqual(classname, "tf_wearable_demoshield"))
{
return Plugin_Handled;
}
}

This doesn't use item indexes because Valve could add more demoshields than the two that already exist.

Leonardo
06-26-2012, 00:12
public Action:TF2Items_OnGiveNamedItem( iClient, String:strClassname[], iItemDefinitionIndex, &Handle:hItem )
{
if( StrContains( strClassname, "tf_wearable", false ) == 0 )
{
return Plugin_Handled;
}
return Plugin_Continue;
}
http://wiki.teamfortress.com/w/images/thumb/0/05/Pipboy_Engineer.png/120px-Pipboy_Engineer.png

Powerlord
06-26-2012, 02:04
public Action:TF2Items_OnGiveNamedItem( iClient, String:strClassname[], iItemDefinitionIndex, &Handle:hItem )
{
if( StrContains( strClassname, "tf_wearable", false ) == 0 )
{
return Plugin_Handled;
}
return Plugin_Continue;
}
http://wiki.teamfortress.com/w/images/thumb/0/05/Pipboy_Engineer.png/120px-Pipboy_Engineer.png

That'd also block hats and misc items.

ReFlexPoison
06-26-2012, 02:13
BTW Powerlord, your way works correctly. I don't understand why it doesn't work with RemoveWeaponSlot or RemoveAllWeapons :grrr:

Powerlord
06-26-2012, 02:58
BTW Powerlord, your way works correctly. I don't understand why it doesn't work with RemoveWeaponSlot or RemoveAllWeapons :grrr:

Valve's code doesn't consider them weapons is why.

Instead, they're stored in the m_hMyWearables list-type thingy along with hats and miscs. Sadly, this isn't accessible via the player entity; m_hMyWearables shows up as offset 0. It's a shame, since it's presumably just a list of entity references.

FlaminSarge
06-28-2012, 18:32
stock RemovePlayerTarge(client)
{
new edict = MaxClients+1;
while((edict = FindEntityByClassname2(edict, "tf_wearable_demoshield")) != -1)
{
new idx = GetEntProp(edict, Prop_Send, "m_iItemDefinitionIndex");
if ((idx == 131 || idx == 406) && GetEntPropEnt(edict, Prop_Send, "m_hOwnerEntity") == client && !GetEntProp(edict, Prop_Send, "m_bDisguiseWearable"))
{
AcceptEntityInput(edict, "Kill");
}
}
}
stock FindPlayerTarge(client)
{
new edict = MaxClients+1;
while((edict = FindEntityByClassname2(edict, "tf_wearable_demoshield")) != -1)
{
new idx = GetEntProp(edict, Prop_Send, "m_iItemDefinitionIndex");
if ((idx == 131 || idx == 406) && GetEntPropEnt(edict, Prop_Send, "m_hOwnerEntity") == client && !GetEntProp(edict, Prop_Send, "m_bDisguiseWearable"))
{
return edict;
}
}
return -1;
}
stock GetPlayerWeaponSlot_Wearable(client, slot)
{
new edict = MaxClients+1;
if (slot == TFWeaponSlot_Secondary)
{
while((edict = FindEntityByClassname2(edict, "tf_wearable_demoshield")) != -1)
{
new idx = GetEntProp(edict, Prop_Send, "m_iItemDefinitionIndex");
if ((idx == 131 || idx == 406) && GetEntPropEnt(edict, Prop_Send, "m_hOwnerEntity") == client && !GetEntProp(edict, Prop_Send, "m_bDisguiseWearable"))
{
return edict;
}
}
}
edict = MaxClients+1;
while((edict = FindEntityByClassname2(edict, "tf_wearable")) != -1)
{
decl String:netclass[32];
if (GetEntityNetClass(edict, netclass, sizeof(netclass)) && StrEqual(netclass, "CTFWearable"))
{
new idx = GetEntProp(edict, Prop_Send, "m_iItemDefinitionIndex");
if (((slot == TFWeaponSlot_Primary && (idx == 405 || idx == 608)) || (slot == TFWeaponSlot_Secondary && (idx == 57 || idx == 133 || idx == 231 || idx == 444))) && GetEntPropEnt(edict, Prop_Send, "m_hOwnerEntity") == client && !GetEntProp(edict, Prop_Send, "m_bDisguiseWearable"))
{
return edict;
}
}
}
return -1;
}
stock FindEntityByClassname2(startEnt, const String:classname[])
{
/* If startEnt isn't valid shifting it back to the nearest valid one */
while (startEnt > -1 && !IsValidEntity(startEnt)) startEnt--;
return FindEntityByClassname(startEnt, classname);
}
There's others e.g. ones tuned to non-demoshield wearable weapons, but you can figure those out easily.