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[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client) && TF2_GetPlayerClass(client) == TFClass_DemoMan && !IsFakeClient(client))
{
int myslot1 = GetIndexOfWeaponSlot(client, 1);
if (myslot1 == -1)
{
int iEntity = -1;
while ((iEntity = FindEntityByClassname(iEntity, "tf_wearable_demoshield")) != -1)
{
if (client == GetEntPropEnt(iEntity, Prop_Data, "m_hOwnerEntity"))
{
myslot1 = GetEntProp(iEntity, Prop_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 <= 0 || client > MaxClients)
{
return false;
}
return IsClientInGame(client);
}
int GetIndexOfWeaponSlot(int iClient, int iSlot)
{
return GetWeaponIndex(GetPlayerWeaponSlot(iClient, iSlot));
}
int GetWeaponIndex(int iWeapon)
{
return IsValidEnt(iWeapon) ? GetEntProp(iWeapon, Prop_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[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(GetEventInt(event, "userid"));
if (IsValidClient(client) && TF2_GetPlayerClass(client) == TFClass_DemoMan && !IsFakeClient(client))
{
int slotentity = TF2Util_GetPlayerLoadoutEntity(client, 1);
int myslot1 = GetEntProp(slotentity, Prop_Send, "m_iItemDefinitionIndex");
if (myslot1 != -1)
{
char itemname[64];
TF2Econ_GetItemName(myslot1, itemname, sizeof(itemname));
PrintToChat(client, "%N Has Item %i, %s equipped in secondary slot", client, myslot1, itemname);
}
}
}
bool IsValidClient(int client)
{
if (client <= 0 || client > MaxClients)
{
return false;
}
return IsClientInGame(client);
}