Raised This Month: $ Target: $400
 0% 

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


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


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 18:36.


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