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

[CS:GO] GiveNamedItemEx 1.0.8


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Plugin ID:
4677
Plugin Version:
1.0.8
Plugin Category:
General Purpose
Plugin Game:
Counter-Strike: GO
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Allows plugins to update classname and paintkits with ease
    Unapprover:
    Reason for Unapproving:
    https://www.mail-archive.com/[email protected]/msg11235.html
    Old 06-14-2015 , 00:13   [CS:GO] GiveNamedItemEx 1.0.8
    Reply With Quote #1

    This plugin parses a forward to other plugins which allows them to edit weapon classnames and paintkits before they spawn.

    This was made to resolve issues where knife and paintkit plugins cause crashes on certain server types.

    Note: This plugin on it's own doesn't do anything. It requires another plugin to actually edit the hook properties.

    It's made for Dummies and is really simple to use.

    Requires: The latest DHooks - Make sure you have the latest version

    Below is the example plugin:

    Code:
    #include <givenameditem>
    #include <cstrike>
    
    public OnLibraryRemoved(const String:name[])
    {
        if (StrEqual(name, "givenameditem"))
        {
            SetFailState("Required plugin 'givenameditem.smx' has been removed");
        }
    }
    
    public OnGiveNamedItemEx(int client, const char[] classname)
    {
        if (StrContains(classname, "weapon_") != 0)
            return;
    
        if (IsFakeClient(client))
            return;
            
        int itemdefinition = GiveNamedItemEx.GetItemDefinitionByClassname(classname);
        
        if (itemdefinition == -1)
            return;
        
        // Change all knives to butterfly knives
        if (GiveNamedItemEx.IsItemDefinitionKnife(itemdefinition))
        {
            GiveNamedItemEx.ItemDefinition = 515;
            GiveNamedItemEx.SetClassname("weapon_knife_butterfly");
            GiveNamedItemEx.EntityQuality = 3;
        }
        
        // Make all weapons stattrak
        GiveNamedItemEx.Paintkit = PAINTKIT_PLAYERS;
        GiveNamedItemEx.Kills = 666;
        
        // Always weapon skins
        int weaponteam = GiveNamedItemEx.GetWeaponTeamByItemDefinition(itemdefinition);
        int playerteam = GetClientTeam(client);
        if (weaponteam != CS_TEAM_NONE && playerteam != weaponteam)
        {
            GiveNamedItemEx.SetClassname(classname);
            GiveNamedItemEx.TeamSwitch = true;
        }
        
        // Change all M4A4/1-s's to vanilla stattrak M4A1-S's
        if (itemdefinition == 16 || itemdefinition == 60)
        {
            GiveNamedItemEx.Paintkit = PAINTKIT_VANILLA;
            GiveNamedItemEx.Seed = 100;
            GiveNamedItemEx.Wear = 0.0001;
            GiveNamedItemEx.Kills = 666;
            GiveNamedItemEx.ItemDefinition = 60;
            GiveNamedItemEx.SetClassname("weapon_m4a1_silencer");
            GiveNamedItemEx.TeamSwitch = true;
            GiveNamedItemEx.EntityQuality = 1;
            GiveNamedItemEx.AccountID = GetSteamAccountID(client);
        }
        
        // Test items api
        char classnamecheck[64];
        GiveNamedItemEx.GetClassnameByItemDefinition(itemdefinition, classnamecheck, sizeof(classnamecheck));
        bool knifebyitemdefinition = GiveNamedItemEx.IsItemDefinitionKnife(itemdefinition);
        bool knifebyclassname = GiveNamedItemEx.IsClassnameKnife(classname);
        PrintToConsole(client, "--==> OnGiveNamedItemEx_Check(classname=%s, itemdefinition=%d, classnamecheck=%s, knifebyitemdefinition=%d, knifebyclassname=%d)", 
                                        classname, itemdefinition, classnamecheck, knifebyitemdefinition, knifebyclassname);
    }
    As you can see, you just include the givenameditem include file and your ready to go. The include uses a methodmap that is linked to natives to do the work so it feels like true OOP. There is no need to return any values as the hook itself will detect and process any hook properties you update.

    Update 1.0.1
    - Added Items API for classname vs item definition lookups
    - Added IsKnife lookups for classnames and item definitions
    - Updated example plugin

    Update 1.0.3
    - Improved support for PAINTKIT_VANILLA
    - Added GiveNamedItemEx.TeamSwitch which switches a players team when the weapon is spawned
    - Added GiveNamedItemEx.GetWeaponTeamByItemDefinition (int) support
    - Added command sm_givenameditem_weaponprops.
    - Optimised plugin
    - Fixed a few small bugs
    - Updated example plugin

    Update 1.0.4
    - Improved support for PAINTKIT_PLAYERS
    - Fixed bug in GiveNamedItemEx.GetWeaponTeamByItemDefinition

    Update 1.0.5
    - Added GiveNamedItemEx.InUse

    Update 1.0.6
    - Fixed GiveNamedItemEx.InUse
    - Improved method to force weapons to be active (thanks xCoderx)

    Update 1.0.8
    -
    Fixed dependency and option requirements
    - Forced hook override to GiveNamedItem instead of GivePlayerItem
    - Improved support for Always Weapon Skins

    Special thanks
    xCoderx!, Drifter and all the feedback contributors in this thread.

    This was specially built for people like: Franc1sco, Klexen and Dr. API
    Attached Files
    File Type: zip givenameditem-100.zip (19.2 KB, 293 views)
    File Type: zip givenameditem-101.zip (21.3 KB, 230 views)
    File Type: zip givenameditem-103.zip (26.5 KB, 207 views)
    File Type: zip givenameditem-104.zip (26.4 KB, 215 views)
    File Type: zip givenameditem-105.zip (26.5 KB, 295 views)
    File Type: zip givenameditem-106.zip (26.6 KB, 340 views)
    File Type: zip givenameditem-108.zip (27.3 KB, 918 views)
    __________________

    Last edited by Neuro Toxin; 07-12-2015 at 09:44.
    Neuro Toxin is offline
    Neuro Toxin
    Veteran Member
    Join Date: Oct 2013
    Location: { closing the void; }
    Old 06-14-2015 , 00:13   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #2

    Plugins using this forward:
    Always Weapon Skins
    Good Practice:
    * Never call GivePlayerItem or GiveNamedItem inside this hook!
    * Only call GiveNamedItemEx.SetClassname where you intend to change the weapon that is spawning!
    * Only set GiveNamedItemEx.Paintkit where you intend to change the paint!
    * Only use GiveNamedItemEx.GetItemDefinitionByClassname once!
    * Avoid classname lookup's as they are expensive!
    Q&A

    Q: Do I have to set all the default settings like in your example plugin code?
    A: No, while it doesn't ultimately matter:- you should only set the properties for what you plan to change.

    Q: How do I get the item definition of the classname being spawned?
    A: Use
    GiveNamedItemEx.GetItemDefinitionByClassname( const char[] classname). This is an expensive lookup function, so try and avoid using it more than once.

    Q: Is there an easy way to know if a knife is being spawned?
    A: Use
    GiveNamedItemEx.IsItemDefinitionKnife(int itemdefinition). This is an expensive lookup function, so try and avoid using it more than once.

    Q: When I change the classname, the players receive their original paintkit with the new weapon.
    A: You need to set GiveNamedItemEx.Paintkit to PAINTKIT_VANILLA.

    Q: Why cant I return Plugin_Stop?
    A: There should never be a need to do this.

    Q: I'm not getting StatTrak items when I set GiveNamedItemEx.Kills?
    A: GiveNamedItemEx.Kills requires
    GiveNamedItemEx.Paintkit to be set. If you don't want to set a paintkit, try using PAINTKIT_VANILLA or PAINTKIT_PLAYERS.
    __________________

    Last edited by Neuro Toxin; 06-27-2015 at 09:31.
    Neuro Toxin is offline
    TheWho
    AlliedModders Donor
    Join Date: Jul 2012
    Old 06-14-2015 , 00:21   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #3

    Well done!

    Could you please tell me what the m_nFallbackSeed is?
    Is it maybe the position of the pattern?
    TheWho is offline
    Neuro Toxin
    Veteran Member
    Join Date: Oct 2013
    Location: { closing the void; }
    Old 06-14-2015 , 00:26   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #4

    Quote:
    Originally Posted by TheWho View Post
    Well done!

    Could you please tell me what the m_nFallbackSeed is?
    Is it maybe the position of the pattern?
    You are correct, it's the start position of the paintkit on the weapon.

    An example is: 100 seed for a fade paintkit is 100% fade!
    __________________
    Neuro Toxin is offline
    TheWho
    AlliedModders Donor
    Join Date: Jul 2012
    Old 06-14-2015 , 00:30   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #5

    So is the Seed a value from 0-100 or can it be 0-752 at another skin?
    TheWho is offline
    Neuro Toxin
    Veteran Member
    Join Date: Oct 2013
    Location: { closing the void; }
    Old 06-14-2015 , 00:32   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #6

    Good question. I'm not exactly sure.

    I personally only allow values from 0-100 in my paintkits plugin.

    Edit: This hook doesn't validate the value you set, so you can try any value you like
    __________________

    Last edited by Neuro Toxin; 06-14-2015 at 00:32.
    Neuro Toxin is offline
    TheWho
    AlliedModders Donor
    Join Date: Jul 2012
    Old 06-14-2015 , 00:48   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #7

    When it's really only from 0-100, that would mean that only 100 different patterns of a skin exist.
    But I don't believe this, it would be to static for valve, I'm sure that there is some float value.

    One more thing is, does people who are fresh connected see the faked item or is it more luck to see someones fake skin after joining?

    With the old method it was for me like when the client didn't received the info that this item got edited he didn't saw the skin clientside then.
    Ex.: I had a huge lag clientside when I spawned, and I didn't received the info then and I had vanilla skin (It was serverside edited, and people even told me).

    Or sometimes, when I stay over 30 min afk it feels like the steam server went down and up again (the only logically thing for me) and so they told me to update the skin and I got my one selected in the inventory when I was alive and had the weapon selected..
    TheWho is offline
    Neuro Toxin
    Veteran Member
    Join Date: Oct 2013
    Location: { closing the void; }
    Old 06-14-2015 , 01:08   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #8

    None of your concerns happen with this hook.

    It's all smooth. EIconView is not edited, it uses the fallback props which is what your after from what I understand in your last post.
    __________________

    Last edited by Neuro Toxin; 06-14-2015 at 01:09.
    Neuro Toxin is offline
    TheWho
    AlliedModders Donor
    Join Date: Jul 2012
    Old 06-14-2015 , 01:11   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #9

    Oh fine I understand.
    Thanks for sharing your hard coded work!
    TheWho is offline
    Dr. Api
    BANNED
    Join Date: Mar 2015
    Location: France
    Old 06-14-2015 , 04:16   Re: [CS:GO] GiveNamedItem Hook
    Reply With Quote #10

    Nice work! you always do I would like to use yout OnGiveNamedItemEx with my snippet: https://forums.alliedmods.net/showthread.php?t=264254 to see if I hav the same issues with machines guns and aug/sg556 but I'm too lazy
    Dr. Api is offline
    Reply


    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 09:04.


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