Raised This Month: $32 Target: $400
 8% 

Solved TF2 - Replacing weapons


Post New Thread Reply   
 
Thread Tools Display Modes
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 11-29-2020 , 21:47   Re: TF2 - Replacing weapons
Reply With Quote #21

Quote:
Originally Posted by StrikeR14 View Post
I liked your solution PC Gamer, you should use SetEntProp with Prop_Send instead of SetEntData. It does not crash servers now.
Interesting... Is there a performance or stability advantage to using SentEntProp over SetEntData?

Here's an example using the suggestion from SrikeR14. Code tested and working in TF2. Gives Sniper rifle to Human Scout players.
PHP Code:
#include <sourcemod>
#include <tf2_stocks>

Handle g_hWeaponEquip;
Handle g_hGameConfig;

public 
void OnPluginStart()
{
    
HookEvent("post_inventory_application"player_inv);
    
g_hGameConfig LoadGameConfigFile("give.bots.weapons");
    
    if (!
g_hGameConfig){
        
SetFailState("Failed to find give.bots.weapons.txt gamedata! Can't continue.");
    }
    
    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(g_hGameConfigSDKConf_Virtual"WeaponEquip");
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer);
    
g_hWeaponEquip EndPrepSDKCall();
    
    if (!
g_hWeaponEquip){
        
SetFailState("Failed to prepare the SDKCall for giving weapons. Try updating gamedata or restarting your server.");
    }
}

public 
void player_inv(Handle event, const char[] namebool dontBroadcast){
    
    
int userd GetEventInt(event"userid");
    
int iClient GetClientOfUserId(userd);
    
    if (!
IsFakeClient(iClient) && TF2_GetPlayerClass(iClient) == TFClass_Scout){
        
PrintToServer("%N selected Scout class."iClient);
        
        
TF2_RemoveWeaponSlot(iClient0);
        
int weaponprimary CreateEntityByName("tf_weapon_sniperrifle");
        
char entclass[64];
        
GetEntityNetClass(weaponprimaryentclasssizeof(entclass));
        
SetEntProp(weaponprimaryProp_Send"m_iItemDefinitionIndex"14);     
        
SetEntProp(weaponprimaryProp_Send"m_bInitialized"1);
        
SetEntProp(weaponprimaryProp_Send"m_iEntityLevel"100);
        
SetEntProp(weaponprimaryProp_Send"m_iEntityQuality"5);

        
DispatchSpawn(weaponprimary);
        
SDKCall(g_hWeaponEquipiClientweaponprimary);        
    }


PC Gamer is offline
StrikeR14
AlliedModders Donor
Join Date: Apr 2016
Location: Behind my PC
Old 11-30-2020 , 12:27   Re: TF2 - Replacing weapons
Reply With Quote #22

Quote:
Originally Posted by PC Gamer View Post
Interesting... Is there a performance or stability advantage to using SentEntProp over SetEntData?
Yeah, SetEntProp is safer and faster than SetEntData.
__________________
Currently taking TF2/CSGO paid private requests!

My Plugins | My Discord Account
StrikeR14 is offline
gvngngr
Junior Member
Join Date: Nov 2020
Old 11-30-2020 , 17:03   Re: TF2 - Replacing weapons
Reply With Quote #23

Thank you both for your replies.
I tried the last code you wrote, PC Gamer, but unfortunately it did not work in TF2Classic.

There is an improvement though: I indeed have the primary weapon of Scout removed this time. But I don't have any weapon equipped in the primary slot, i.e. I only have the pistol and the bat.

The error I get in the server is pointing out to m_bInitialized property even more explicitly this time:


And when I dump a network properties file using the sm_dump_netprops command and look into that text file, there is indeed no property such as m_bInitialized.

I don't understand technically what "properties" and such definitions in sourcemod coding really mean, but at this point, I assume it is a restriction due to the differences of TF2 and TF2Classic? Is there an alternative way to achieve this?
gvngngr is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 12-01-2020 , 00:14   Re: TF2 - Replacing weapons
Reply With Quote #24

Quote:
Originally Posted by gvngngr View Post
I assume it is a restriction due to the differences of TF2 and TF2Classic? Is there an alternative way to achieve this?
The netprop may not be valid for TF2C. The addresses used in your gamedata file may not be valid for TF2C.

I would normally check the gamedata address by using the VTable Dumper developed by Asherkin (link: https://asherkin.github.io/vtable/ ) However, TF2 Classic wasn't listed as a game, and I didn't have a TF2C .so file to drop.

I'm unable to assist further since I don't run a TF2 Classic server. Many people won't view this thread since it is already marked solved. I would start a new post in the scripting section asking how to give a weapon to players in TF2 Classic.
PC Gamer is offline
Reply



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 06:00.


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