AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   TF2Items (https://forums.alliedmods.net/forumdisplay.php?f=146)
-   -   Changing a weapon with TF2 items. (https://forums.alliedmods.net/showthread.php?t=188320)

Powerlord 06-26-2012 02:04

Re: [TF2] Changing a weapon with TF2 items.
 
Quote:

Originally Posted by Leonardo (Post 1736287)
PHP Code:

public Action:TF2Items_OnGiveNamedItemiClientString:strClassname[], iItemDefinitionIndex, &Handle:hItem )
{
    if( 
StrContainsstrClassname"tf_wearable"false ) == )
    {
        return 
Plugin_Handled;
    }
    return 
Plugin_Continue;


http://wiki.teamfortress.com/w/image...y_Engineer.png

That'd also block hats and misc items.

ReFlexPoison 06-26-2012 02:13

Re: [TF2] Changing a weapon with TF2 items.
 
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

Re: [TF2] Changing a weapon with TF2 items.
 
Quote:

Originally Posted by ReFlexPoison (Post 1736312)
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

Re: Changing a weapon with TF2 items.
 
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.


All times are GMT -4. The time now is 21:14.

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