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

[CS:GO] Change players knife without creating a new entity


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hlstriker
Green Gaben
Join Date: Mar 2006
Location: OH-IO!
Old 07-07-2015 , 23:56   [CS:GO] Change players knife without creating a new entity
Reply With Quote #1

Warning: Valve does not want you changing weapons into an economy item (this means changing to any of the cool knives.)

Read this post before venturing further into the tutorial!

Well, now that you're not supposed to use plugins that change your weapons to be something from the economy I'll go ahead and show you how to change your weapons to be something from the economy.. without creating a new entity! Whatever you do don't use this tutorial to change your weapons to be something from the economy. May your !knife server crashes be a thing of the past (which should be a thing of the past anyway since you're not running those plugins anymore, right?)

Note this is not complete code and is merely used to demonstrate how you can gracefully change a weapon based on its item definition index. Obviously it's not limited to knives only. Try turning your AK into a knife!

PHP Code:
new const g_iItemDefinitionIndexes[] =
{
    
59,    // T Default
    
42,    // CT Default
    
512,    // Falchion
    
500,    // Bayonet
    
508,    // M9 Bayonet
    
506,    // Gut
    
505,    // Flip
    
507,    // Karambit
    
509,    // Huntsman
    
515    // Butterfly
};

public 
OnClientPutInServer(iClient)
{
    
SDKHook(iClientSDKHook_WeaponEquipPostOnWeaponEquip_Post);
}

public 
OnWeaponEquip_Post(iClientiWeapon)
{
    static 
bSkipNextEquip[MAXPLAYERS+1];
    if(
bSkipNextEquip[iClient])
        return;
    
    
// Call RemovePlayerItem() so we never see the original knife model.
    
RemovePlayerItem(iClientiWeapon);
    
    
// Set the definition index between RemovePlayerItem() and EquipPlayerWeapon().
    
SetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex"g_iItemDefinitionIndexes[A_FANCY_INDEX]);
    
    
// We must call EquipPlayerWeapon() again to fix the animations and because we called RemovePlayerItem().
    // Make sure we skip the next equip hook so we don't infinitely loop!
    
bSkipNextEquip[iClient] = true;
    
EquipPlayerWeapon(iClientiWeapon);
    
bSkipNextEquip[iClient] = false;

And now you're smart, good job!
hlstriker is offline
SM9
Veteran Member
Join Date: Sep 2013
Location: United Kingdom
Old 07-25-2015 , 07:58   Re: [CS:GO] Change players knife without creating a new entity
Reply With Quote #2

You may want to change this to a PreHook, Otherwise Falchion and Butterfly will have bugged animations.

It took me a while to figure out that it was just a simple change to prehook.

Edit: (Its really as simple as this and you will get perfect results everytime without glitches)

PHP Code:
public OnWeaponEquip_Pre(iClientiWeapon)
{
    
RemovePlayerItem(iClientiWeapon);
    
SetEntProp(iWeaponProp_Send"m_iItemDefinitionIndex"g_iItemDefinitionIndexes[A_FANCY_INDEX]);


Last edited by SM9; 07-25-2015 at 08:06.
SM9 is offline
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 10-31-2016 , 19:59   Re: [CS:GO] Change players knife without creating a new entity
Reply With Quote #3

If I use this on my mod my server will get banned?
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
sneaK
SourceMod Moderator
Join Date: Feb 2015
Location: USA
Old 10-31-2016 , 20:33   Re: [CS:GO] Change players knife without creating a new entity
Reply With Quote #4

Quote:
Originally Posted by _GamerX View Post
If I use this on my mod my server will get banned?
Yes.
__________________
sneaK is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 11-01-2016 , 01:36   Re: [CS:GO] Change players knife without creating a new entity
Reply With Quote #5

I built an API for this before GSLT came in...


https://forums.alliedmods.net/showthread.php?p=2307658
__________________
Neuro Toxin 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 08:12.


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