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

Changing a weapon with TF2 items.


Post New Thread Reply   
 
Thread Tools Display Modes
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-26-2012 , 02:04   Re: [TF2] Changing a weapon with TF2 items.
Reply With Quote #11

Quote:
Originally Posted by Leonardo View Post
PHP Code:
public Action:TF2Items_OnGiveNamedItemiClientString:strClassname[], iItemDefinitionIndex, &Handle:hItem )
{
    if( 
StrContainsstrClassname"tf_wearable"false ) == )
    {
        return 
Plugin_Handled;
    }
    return 
Plugin_Continue;

That'd also block hats and misc items.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 06-26-2012 , 02:13   Re: [TF2] Changing a weapon with TF2 items.
Reply With Quote #12

BTW Powerlord, your way works correctly. I don't understand why it doesn't work with RemoveWeaponSlot or RemoveAllWeapons

Last edited by ReFlexPoison; 06-26-2012 at 02:14.
ReFlexPoison is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-26-2012 , 02:58   Re: [TF2] Changing a weapon with TF2 items.
Reply With Quote #13

Quote:
Originally Posted by ReFlexPoison View Post
BTW Powerlord, your way works correctly. I don't understand why it doesn't work with RemoveWeaponSlot or RemoveAllWeapons
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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 06-26-2012 at 03:03.
Powerlord is offline
FlaminSarge
Veteran Member
Join Date: Jul 2010
Old 06-28-2012 , 18:32   Re: Changing a weapon with TF2 items.
Reply With Quote #14

Code:
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.
__________________
Bread EOTL GunMettle Invasion Jungle Inferno will break everything. Don't even ask.

All plugins: Randomizer/GiveWeapon, ModelManager, etc.
Post in plugin threads with questions.
Steam is for playing games.
You will be fed to javalia otherwise.
Psyduck likes replays.
FlaminSarge 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 00:26.


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