AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Unapproved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=109)
-   -   [CS:GO] GiveNamedItemEx 1.0.8 (https://forums.alliedmods.net/showthread.php?t=264320)

Neuro Toxin 06-14-2015 00:13

[CS:GO] GiveNamedItemEx 1.0.8
 
7 Attachment(s)
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

Neuro Toxin 06-14-2015 00:13

Re: [CS:GO] GiveNamedItem Hook
 
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.

TheWho 06-14-2015 00:21

Re: [CS:GO] GiveNamedItem Hook
 
Well done!

Could you please tell me what the m_nFallbackSeed is?
Is it maybe the position of the pattern?

Neuro Toxin 06-14-2015 00:26

Re: [CS:GO] GiveNamedItem Hook
 
Quote:

Originally Posted by TheWho (Post 2307660)
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!

TheWho 06-14-2015 00:30

Re: [CS:GO] GiveNamedItem Hook
 
So is the Seed a value from 0-100 or can it be 0-752 at another skin?

Neuro Toxin 06-14-2015 00:32

Re: [CS:GO] GiveNamedItem Hook
 
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

TheWho 06-14-2015 00:48

Re: [CS:GO] GiveNamedItem Hook
 
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..

Neuro Toxin 06-14-2015 01:08

Re: [CS:GO] GiveNamedItem Hook
 
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.

TheWho 06-14-2015 01:11

Re: [CS:GO] GiveNamedItem Hook
 
Oh fine I understand.
Thanks for sharing your hard coded work!

Dr. Api 06-14-2015 04:16

Re: [CS:GO] GiveNamedItem Hook
 
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 :bacon!:


All times are GMT -4. The time now is 14:15.

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