AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [TF2] Create Invisible Weapons (https://forums.alliedmods.net/showthread.php?t=317835)

Theon32 07-31-2019 18:45

[TF2] Create Invisible Weapons
 
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

Naydef 08-01-2019 03:56

Re: [TF2] Create Invisible Weapons
 
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.

Theon32 08-01-2019 11:31

Re: [TF2] Create Invisible Weapons
 
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.

Touric 08-23-2019 14:23

Re: [TF2] Create Invisible Weapons
 
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


All times are GMT -4. The time now is 11:46.

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