View Single Post
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 05-13-2021 , 04:14   Re: [REQ][TF2] Block renamed weapons
Reply With Quote #2

I'm not aware of any method that allows you to view or edit the name of a weapon. However, you should be able to replace any renamed weapon you find with a stock version.

There are 29 renamed weapons in the game. You could replace some or all of them with their stock version. Here's example code to replace the 3 Scout renamed weapons. Note: I have not tested this.

Example code:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#include <tf2_stocks>

#pragma newdecls required

#define PLUGIN_VERSION "1.0"

public Plugin myinfo =
{
    
name "[TF2] Block Renamed Weapons",
    
author "Sreaper",
    
description "Replace Renamed weapons with stock versions",
    
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_Scout)
    {
        
int myslot0 GetIndexOfWeaponSlot(client0);
        if(
myslot0 == 200)//Renamed Scattergun
        
{
            
TF2_RemoveWeaponSlot(client0);
            
CreateWeapon(client"tf_weapon_scattergun"136);
        }
        
        
int myslot1 GetIndexOfWeaponSlot(client1);
        if(
myslot1 == 209)//Renamed Pistol
        
{
            
TF2_RemoveWeaponSlot(client1);
            
CreateWeapon(client"tf_weapon_pistol"236);
        }

        
int myslot2 GetIndexOfWeaponSlot(client2);
        if(
myslot2 == 190)//Renamed Bat
        
{
            
TF2_RemoveWeaponSlot(client2);
            
CreateWeapon(client"tf_weapon_bat"06);
        }        
    }
}

bool CreateWeapon(int clientchar[] classnameint itemindexint qualityint level 0)
{
    
int weapon CreateEntityByName(classname);
    
    if (!
IsValidEntity(weapon))
    {
        return 
false;
    }
    
    
char entclass[64];
    
GetEntityNetClass(weaponentclasssizeof(entclass));
    
SetEntProp(weaponProp_Send"m_iItemDefinitionIndex"itemindex);     
    
SetEntProp(weaponProp_Send"m_bInitialized"1);
    
SetEntData(weaponFindSendPropInfo(entclass"m_iEntityQuality"), quality);    

    if (
level)
    {
        
SetEntProp(weaponProp_Send"m_iEntityLevel"level);
    }
    else
    {
        
SetEntProp(weaponProp_Send"m_iEntityLevel"GetRandomUInt(1,99));
    }

    
DispatchSpawn(weapon);
    
EquipPlayerWeapon(clientweapon);     
    
    return 
true;    
}

stock bool IsValidClient(int client)

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

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

stock int GetClientCloakIndex(int iClient)
{
    return 
GetWeaponIndex(GetPlayerWeaponSlot(iClientTFWeaponSlot_Watch));
}

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

stock int GetActiveIndex(int iClient)
{
    return 
GetWeaponIndex(GetEntPropEnt(iClientProp_Send"m_hActiveWeapon"));
}

stock bool IsWeaponSlotActive(int iClientint iSlot)
{
    return 
GetPlayerWeaponSlot(iClientiSlot) == GetEntPropEnt(iClientProp_Send"m_hActiveWeapon");
}

stock bool IsIndexActive(int iClientint iIndex)
{
    return 
iIndex == GetWeaponIndex(GetEntPropEnt(iClientProp_Send"m_hActiveWeapon"));
}

stock bool IsSlotIndex(int iClientint iSlotint iIndex)
{
    return 
iIndex == GetIndexOfWeaponSlot(iClientiSlot);
}

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

stock int GetSlotFromPlayerWeapon(int iClientint iWeapon)
{
    for (new 
0<= 5i++)
    {
        if (
iWeapon == GetPlayerWeaponSlot(iClienti))
        {
            return 
i;
        }
    }
    return -
1;
}

int GetRandomUInt(int minint max)
{
    return 
RoundToFloor(GetURandomFloat() * (max min 1)) + min;

PC Gamer is offline