AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   TF2 get demoman secondary (https://forums.alliedmods.net/showthread.php?t=339921)

Telepathic Walrus 10-09-2022 11:28

TF2 get demoman secondary
 
Hi, I am trying to get the type of shield that a client is using on the server. using GetPlayerWeaponSlot for secondary doesn't seem to work.
Looking online this seems to be because the shield is classed as a wearable. After trying to search for the specific wearable, using FindEntityByClassname(iEntity, "tf_wearable_demoshield"), I still cant seem to get it working. I need to basically decide if the demoman has the tide turner equipped or not. Is there any way to do this.

Thanks

Telepathic Walrus 10-09-2022 12:34

Re: TF2 get demoman secondary
 
I got it working if anyone is interested I can post update later when im on my pc

PC Gamer 10-09-2022 15:16

Re: TF2 get demoman secondary
 
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); 




All times are GMT -4. The time now is 12:08.

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