Raised This Month: $12 Target: $400
 3% 

Solved [TF2] Create Invisible Weapons


Post New Thread Reply   
 
Thread Tools Display Modes
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
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 08-01-2019 , 03:56   Re: [TF2] Create Invisible Weapons
Reply With Quote #2

Set all weapons' definition index to 5 (Fists). You can also hook "player_death" event and change kill icon to fists. This method is used by VSH and FF2.
__________________
My plugins:
*None for now*


Steam:
naydef
Naydef is offline
Theon32
Member
Join Date: Sep 2018
Location: mvm_isolation_rc3
Old 08-01-2019 , 11:31   Re: [TF2] Create Invisible Weapons
Reply With Quote #3

Oh thanks man! Originally I also changed the classname to tf_weapon_fists but that's what caused the swinging animation to break, I didn't think just changing the index would fix that.
__________________
I like to try and learn off of other people's work and only like to make forum posts when absolutely necessary.
Theon32 is offline
Touric
Junior Member
Join Date: Jul 2018
Old 08-23-2019 , 14:23   Re: [TF2] Create Invisible Weapons
Reply With Quote #4

Is there an alternative way to do this for primary and secondary weapons?
Setting def index to 5 works, the weapon is invisible but for weapons who needs a def index (like force-a-nature) it wont work
Touric is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:50.


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