AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [CS:GO] Change players knife without creating a new entity (https://forums.alliedmods.net/showthread.php?t=265955)

hlstriker 07-07-2015 23:56

[CS:GO] Change players knife without creating a new entity
 
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!

SM9 07-25-2015 07:58

Re: [CS:GO] Change players knife without creating a new entity
 
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]);



_GamerX 10-31-2016 19:59

Re: [CS:GO] Change players knife without creating a new entity
 
If I use this on my mod my server will get banned?

sneaK 10-31-2016 20:33

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

Originally Posted by _GamerX (Post 2466733)
If I use this on my mod my server will get banned?

Yes.

Neuro Toxin 11-01-2016 01:36

Re: [CS:GO] Change players knife without creating a new entity
 
I built an API for this before GSLT came in...


https://forums.alliedmods.net/showthread.php?p=2307658


All times are GMT -4. The time now is 18:36.

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