View Single Post
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 10-09-2022 , 15:16   Re: TF2 get demoman secondary
Reply With Quote #3

I put this together for you as a possible way to determine what is equipped in a DemoMan's secondary slot.

PHP Code:
#include <tf2_stocks>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

public Plugin myinfo =
{
    
name "[TF2] Check for Shield Type",
    
author "PC Gamer",
    
description "Determine type of shield equipped",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.net"
}

public 
void OnPluginStart()
{
    
HookEvent("post_inventory_application"EventInventoryApplication);    
}

public 
void EventInventoryApplication(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if (
IsValidClient(client) && TF2_GetPlayerClass(client) == TFClass_DemoMan && !IsFakeClient(client))
    {
        
int myslot1 GetIndexOfWeaponSlot(client1);
        
        if (
myslot1 == -1)
        {
            
int iEntity = -1;
            while ((
iEntity FindEntityByClassname(iEntity"tf_wearable_demoshield")) != -1)
            {
                if (
client == GetEntPropEnt(iEntityProp_Data"m_hOwnerEntity"))
                {
                    
myslot1 GetEntProp(iEntityProp_Send"m_iItemDefinitionIndex");
                }
            }            
        }
        
        switch (
myslot1)
        {
        case 
131:
            {
            
PrintToChat(client"I equipped The Chargin' Targe shield");                
            }
        case 
406:
            {
                
PrintToChat(client"I equipped The Splendid Screen shield");                
            }            
        case 
1099:
            {
                
PrintToChat(client"I equipped The Tide Turner shield");                
            }
        case 
1144:
            {
                
PrintToChat(client"I equipped The Festive Targe shield");                
            }
        default:
            {
                
PrintToChat(client"I equipped item index: %i"myslot1);                
            }
        }
    }
}

bool IsValidClient(int client)

    if (
client <= || client MaxClients)
    {
        return 
false
    }
    return 
IsClientInGame(client); 
}  

int GetIndexOfWeaponSlot(int iClientint iSlot)
{
    return 
GetWeaponIndex(GetPlayerWeaponSlot(iClientiSlot));
}

int GetWeaponIndex(int iWeapon)
{
    return 
IsValidEnt(iWeapon) ? GetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex"):-1;
}

bool IsValidEnt(int iEnt)
{
    return 
iEnt MaxClients && IsValidEntity(iEnt);

You can make this easier if you are using TF Econ Data and TF2Utils, both by nosoop.
TF Econ Data link: https://forums.alliedmods.net/showthread.php?t=315011
TF2Utils link: https://forums.alliedmods.net/showthread.php?t=338773

Here's a working example using nosoop's includes:
PHP Code:
#include <tf_econ_data>
#include <tf2utils>

#pragma semicolon 1
#pragma newdecls required

#define PLUGIN_VERSION "1.0"

public Plugin myinfo =
{
    
name "[TF2] Check for Shield Type via TF Econ Data",
    
author "PC Gamer",
    
description "Determine type of shield equipped",
    
version PLUGIN_VERSION,
    
url "www.sourcemod.net"
}

public 
void OnPluginStart()
{
    
HookEvent("post_inventory_application"EventInventoryApplication);    
}

public 
void EventInventoryApplication(Handle event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(GetEventInt(event"userid"));
    if (
IsValidClient(client) && TF2_GetPlayerClass(client) == TFClass_DemoMan && !IsFakeClient(client))
    {
        
int slotentity TF2Util_GetPlayerLoadoutEntity(client1);

        
int myslot1 GetEntProp(slotentityProp_Send"m_iItemDefinitionIndex");    
        
        if (
myslot1 != -1)
        {
            
char itemname[64];
            
TF2Econ_GetItemName(myslot1itemnamesizeof(itemname));
            
PrintToChat(client"%N Has Item %i, %s equipped in secondary slot"clientmyslot1itemname);        
        }
    }
}

bool IsValidClient(int client)

    if (
client <= || client MaxClients)
    {
        return 
false
    }
    return 
IsClientInGame(client); 


Last edited by PC Gamer; 10-09-2022 at 19:01.
PC Gamer is offline