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

Solved TF2 - Replacing weapons


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 05-27-2016 , 15:30   TF2 - Replacing weapons
Reply With Quote #1

Is there a way to remove spy's knife and then replace it with the stock one without using TF2Items?
The only one I know of, is the following one, but it crashes the server. I dont want to use TF2Items because Im only replacing one weapon for one player(each round).

Code:
ReplaceKnife(i) {
    
    //TF2_RemoveWeaponSlot(i, 1); // Sapper
    TF2_RemoveWeaponSlot(i, 2); // Knife
                                        
    //following code doesnt work anymore - server crashes
    new knife=GivePlayerItem(i, "tf_weapon_knife");
    SetEntProp(knife, Prop_Send, "m_iItemDefinitionIndex", 4);
    SetEntProp(knife, Prop_Send, "m_iEntityLevel", 1);
    SetEntProp(knife, Prop_Send, "m_iEntityQuality", 0);

    EquipPlayerWeapon(i, knife); 

}
__________________

Last edited by luki1412; 09-23-2016 at 18:42.
luki1412 is offline
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 05-27-2016 , 15:57   Re: TF2 - Replacing weapons
Reply With Quote #2

Maybe?

Code:
ReplaceKnife(i) {
    
    //TF2_RemoveWeaponSlot(i, 1); // Sapper
    TF2_RemoveWeaponSlot(i, 2); // Knife
                                        
    //following code doesnt work anymore - server crashes
    new knife=CreateEntityByName("tf_weapon_knife");
    if(knife != -1)
    {
        DispatchSpawn(knife);
        SetEntProp(knife, Prop_Send, "m_iItemDefinitionIndex", 4);
        SetEntProp(knife, Prop_Send, "m_iEntityLevel", 1);
        SetEntProp(knife, Prop_Send, "m_iEntityQuality", 0);
        
        EquipPlayerWeapon(i, knife); 
    }
}
__________________

Last edited by Chaosxk; 05-27-2016 at 16:00.
Chaosxk is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 05-27-2016 , 16:23   Re: TF2 - Replacing weapons
Reply With Quote #3

Quote:
Originally Posted by Chaosxk View Post
Maybe?

Code:
ReplaceKnife(i) {
    
    //TF2_RemoveWeaponSlot(i, 1); // Sapper
    TF2_RemoveWeaponSlot(i, 2); // Knife
                                        
    //following code doesnt work anymore - server crashes
    new knife=CreateEntityByName("tf_weapon_knife");
    if(knife != -1)
    {
        DispatchSpawn(knife);
        SetEntProp(knife, Prop_Send, "m_iItemDefinitionIndex", 4);
        SetEntProp(knife, Prop_Send, "m_iEntityLevel", 1);
        SetEntProp(knife, Prop_Send, "m_iEntityQuality", 0);
        
        EquipPlayerWeapon(i, knife); 
    }
}
Nope, crashed.
__________________
luki1412 is offline
TheUnderTaker
Senior Member
Join Date: Dec 2013
Location: Israel
Old 05-28-2016 , 07:42   Re: TF2 - Replacing weapons
Reply With Quote #4

Feel free to use it https://forums.alliedmods.net/showthread.php?t=141962
__________________
SourcePawn, C# and C++ Programmer.

My plugin list
TheUnderTaker is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 05-28-2016 , 07:51   Re: TF2 - Replacing weapons
Reply With Quote #5

Quote:
Originally Posted by TheUnderTaker View Post
You didn't read my post, did you?
__________________
luki1412 is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 05-28-2016 , 09:35   Re: TF2 - Replacing weapons
Reply With Quote #6

You'll probably have to replicate the functionality of TF2Items_GiveNamedItem in SourceMod, in that case. Specifically this section. Which, from what I can tell, is not easily doable in SourceMod alone. (Did some testing, and no, at the very least you can't just set the m_bInitialized netprop to true and call it done.)

Personally, I think you'd be better off letting TF2Items handle the weapon granting. It's what it was made to do, after all, and you don't have to worry about any future changes from Valve other than dropping a new copy of the extension in every now and then.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop is offline
Requiesta
Senior Member
Join Date: May 2012
Location: Texas
Old 05-28-2016 , 11:17   Re: TF2 - Replacing weapons
Reply With Quote #7

Taken from The Hidden:

Quote:
TF2_RemoveWeaponSlot(i, 0); // Revolver
//TF2_RemoveWeaponSlot(i, 1); // Sapper
TF2_RemoveWeaponSlot(i, 2); // Knife
TF2_RemoveWeaponSlot(i, 3); // Disguise Kit
TF2_RemoveWeaponSlot(i, 4); // Invisibility Watch
TF2_RemoveWeaponSlot(i, 5); // Golden Machine Gun

// This will add the knife to the spy, even if he has another unlock
new knife=GivePlayerItem(i, "tf_weapon_knife");
SetEntProp(knife, Prop_Send, "m_iItemDefinitionIndex", 4);
SetEntProp(knife, Prop_Send, "m_iEntityLevel", 100);
SetEntProp(knife, Prop_Send, "m_iEntityQuality", 10);
SetEntProp(knife, Prop_Send, "m_bInitialized", 1);

// Also, I hate extensions :p
EquipPlayerWeapon(i, knife);
This is what people had to do before tf2items, you may now worship Asherkin.
__________________
YouTuber, Modder, Accountant, and somehow I still enjoy programming after all that.

Check out my YouTube Channel.

Last edited by Requiesta; 05-28-2016 at 11:19.
Requiesta is offline
Naydef
Senior Member
Join Date: Dec 2015
Location: Doom Town, Nevada
Old 05-28-2016 , 13:53   Re: TF2 - Replacing weapons
Reply With Quote #8

Don't use SetEntProp for setting m_iEntityQuality, use SetEntData, otherwise it won't change the quality. Also set properties before weapon DispatchSpawn():

PHP Code:
stock bool:CreateNamedItem(clientitemindexString:classname[], levelquality)
{
    if(
client<=|| client>MaxClients || ! IsClientInGame(client))
    {
        return 
false;
    }
    new 
weapon=CreateEntityByName(classname);
    if(!
IsValidEntity(weapon))
    {
        return 
false;
    }
    
SetEntProp(weaponProp_Send"m_iItemDefinitionIndex"itemindex);
    
SetEntProp(weaponProp_Send"m_bInitialized"1); // 3. Initialize the weapon.
    
SetEntProp(weaponProp_Send"m_iEntityLevel"level);
    new 
String:entclass[64];
    
GetEntityNetClass(weaponentclasssizeof(entclass));
    
SetEntData(weaponFindSendPropOffs(entclass"m_iEntityQuality"), quality);
    
DispatchSpawn(weapon);
    
EquipPlayerWeapon(clientweapon);
    return 
true;

__________________
My plugins:
*None for now*


Steam:
naydef

Last edited by Naydef; 05-28-2016 at 13:57.
Naydef is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 05-29-2016 , 07:20   Re: TF2 - Replacing weapons
Reply With Quote #9

Quote:
Originally Posted by Requiesta View Post
Taken from The Hidden:



This is what people had to do before tf2items, you may now worship Asherkin.
Yeah, Im aware of that code. It crashes the server now. It used to work like 3 years ago.
__________________
luki1412 is offline
luki1412
Veteran Member
Join Date: Oct 2008
Location: OnPluginStart()
Old 05-29-2016 , 07:22   Re: TF2 - Replacing weapons
Reply With Quote #10

Quote:
Originally Posted by Naydef View Post
Don't use SetEntProp for setting m_iEntityQuality, use SetEntData, otherwise it won't change the quality. Also set properties before weapon DispatchSpawn():

PHP Code:
stock bool:CreateNamedItem(clientitemindexString:classname[], levelquality)
{
    if(
client<=|| client>MaxClients || ! IsClientInGame(client))
    {
        return 
false;
    }
    new 
weapon=CreateEntityByName(classname);
    if(!
IsValidEntity(weapon))
    {
        return 
false;
    }
    
SetEntProp(weaponProp_Send"m_iItemDefinitionIndex"itemindex);
    
SetEntProp(weaponProp_Send"m_bInitialized"1); // 3. Initialize the weapon.
    
SetEntProp(weaponProp_Send"m_iEntityLevel"level);
    new 
String:entclass[64];
    
GetEntityNetClass(weaponentclasssizeof(entclass));
    
SetEntData(weaponFindSendPropOffs(entclass"m_iEntityQuality"), quality);
    
DispatchSpawn(weapon);
    
EquipPlayerWeapon(clientweapon);
    return 
true;

Still crashing the server.
__________________
luki1412 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 09:51.


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