View Single Post
Author Message
Theon32
Member
Join Date: Sep 2018
Location: mvm_isolation_rc3
Old 07-31-2019 , 18:45   [TF2] Create Invisible Weapons
Reply With Quote #1

So I did some research and couldn't find any results. I'm trying to make all players on Red Team spawn with their class's default stock melee weapon except it is invisible to make it appear as if they have fists for melee instead of stuff like a bat or a fireaxe. I've gotten everything to work except for firstperson. In firstperson as Scout, I still have a bat. This is what I got.

PHP Code:
#include <sourcemod>
#include <tf2>
#include <tf2items>
#include <tf2_stocks>

public Plugin:myinfo =
{
    
name        "[TF2] Fists",
    
author      "Theon32",
    
description "Melee is fists only.",
    
version     "1.0",
    
url         "https://forums.alliedmods.net/member.php?u=287995"
}

public 
OnPluginStart()
{
    
HookEvent("post_inventory_application"Event_PIA);
}

public 
Event_PIA(Event event, const char[] namebool dontBroadcast)
{
    
int iClient GetClientOfUserId(event.GetInt("userid"));
    
    if (
TF2_GetClientTeam(iClient) == TFTeam_Red)
    {
        new 
Handle:hWeapon;
        
hWeapon TF2Items_CreateItem(OVERRIDE_ALL|FORCE_GENERATION|PRESERVE_ATTRIBUTES);
        switch (
TF2_GetPlayerClass(iClient))
        {
            case 
TFClass_Scout:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_bat");
                
TF2Items_SetItemIndex(hWeapon0);
            }
            case 
TFClass_Soldier:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_shovel");
                
TF2Items_SetItemIndex(hWeapon6);
            }
            case 
TFClass_Pyro:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_fireaxe");
                
TF2Items_SetItemIndex(hWeapon2);
            }
            case 
TFClass_DemoMan:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_bottle");
                
TF2Items_SetItemIndex(hWeapon1);
            }
            case 
TFClass_Heavy:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_fists");
                
TF2Items_SetItemIndex(hWeapon5);
            }
            case 
TFClass_Engineer:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_wrench");
                
TF2Items_SetItemIndex(hWeapon7);
            }
            case 
TFClass_Medic:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_bonesaw");
                
TF2Items_SetItemIndex(hWeapon8);
            }
            case 
TFClass_Sniper:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_club");
                
TF2Items_SetItemIndex(hWeapon3);
            }
            case 
TFClass_Spy:
            {
                
TF2Items_SetClassname(hWeapon"tf_weapon_knife");
                
TF2Items_SetItemIndex(hWeapon4);
            }
        }
        
TF2Items_SetLevel(hWeapon1);
        
TF2Items_SetQuality(hWeapon10);
        new 
String:att[] = "692 ; 1"
        
new String:atts[32][32];
        new 
count ExplodeString(att" ; "atts3232);
        
TF2Items_SetNumAttributes(hWeaponcount/2);
        new 
i2 0;
        for (new 
0counti+=2)
        {
            
TF2Items_SetAttribute(hWeaponi2StringToInt(atts[i]), StringToFloat(atts[i+1]));
            
i2++;
        }
        if (
hWeapon == INVALID_HANDLE)
            return -
1;
        new 
entity TF2Items_GiveNamedItem(iClienthWeapon);
        
CloseHandle(hWeapon);
        if (
IsValidEdict(entity))
        {
            
TF2_RemoveWeaponSlot(iClient2);
            
EquipPlayerWeapon (iCliententity);
        }
        
CreateTimer(1.0Timer_Delayentity);
    }
}

public 
Action:Timer_Delay(Handle:timerany:entity)
    
SetEntPropFloat(entityProp_Send"m_flModelScale"0.0); 
Thanks!
-Theon
__________________
I like to try and learn off of other people's work and only like to make forum posts when absolutely necessary.

Last edited by Theon32; 08-01-2019 at 11:31.
Theon32 is offline