How to get ammo Item class ?

HOOK:void OnPlayerAttack(BasePlayer attacker, HitInfo info)

ItemDefinition itemDefinition = info.Weapon.GetEntity().GetComponent<BaseProjectile>()?.primaryMagazine.ammoType;

I need to get the Item Class for ammo...

or itemDefinition  How to cast Item ???

What original problem are you trying to solve? If you want to know what type of ammo was used, you can check the item id or short name of the item definition.

I need to modify the properties of each bullet ...

 1. Generate special bullets (eg: frozen bullets)
 2. Equipment: Freeze Bullet
 3. Hook OnPlayerAttack() .. Determine bullets type and execute Effect .. 

so  I don't know how to get bullet type。。。

A common approach for this sort of thing is to upload any random skin to workshop (even a t shirt) with a custom icon (there are YouTube tutorials for this) that looks like your freeze bullet. Then use a plugin to give players ammo with that skin id. Then check item.skin to determine if it's a "freeze bullet" based on whether the skin matches that number.

Yes  But I can only get ItemDefinition ... This Class none skin() function ... 

Ah, right. Come to think of it, I think I've seen this question before, but I don't recall how people solved it. There are some things you can try off the top of my head.

  • You could use the HitInfo argument to determine the InitiatorPlayer and then get their active item. This isn't perfect because they could have switched weapons, or even be dead, but this would generally work. Just make sure the code verifies that they are still holding the same weapon.
  • You could try something more convoluted such as attaching a custom ItemMod to the item definition that you intend to skin, so that you can detect when the item is created, in order to get a reference to the held entity, which you can attach a component to. When detecting a hit, you can check for that component on the held entity. For an example of using a custom ItemMod, see the General Item Modifier plugin.

yes,Thank you for your patience to help me with the answer

I tried to add it ItemMod , but All of the itemDefinitions change accordingly 。。。 

I implemented it in a different way,Replace consumption with other items ,It's like a magic item,is besuccessful