1. I've been trying to change the type of ammunition a weapon holds/accepts and so far I'm able to spawn in weapons that can hold non-vanilla-compatible types of ammunition. Here's the problem, though.

    Assume the following scenario:

    Instead of 24 bullets of "5.56 Rifle Ammo" my "Assault Rifle" holds 24 bullets of "Pistol Bullets" when crafted.

    I can use those 24 bullets of "Pistol Bullets" just fine, but when I run out of bullets I cannot reload the weapon unless I meet the following 2 requirements:
    • I have at least 1 vanilla-compatible type ("5.56 Rifle Ammo"/"Incendiary 5.56 Rifle Ammo"/"Explosive 5.56 Rifle Ammo") of ammunition inside my inventory.
    • I have at least 1 "Pistol Bullet" inside my inventory.
    If I fail to meet the first requirement, but meet the second one, my weapon will not reload at all.
    If I fail to meet the second requirement, but meet the first one, my weapon will show a reload animation, but no ammunition gets actually added to my weapon's magazine.

    So reloading is somewhat possible...switching between my non-vanilla-compatible types of ammunition is not possible, at all.

    Here is the relevant code-snippet of my plugin:
    (1# Note: I attached the whole plugin, as well.)
    (2# Note: I hard-coded some of the values for testing purposes.)


    Code:
    using Rust;namespace Oxide.Plugins
    {
        [Info("Test", "Tuntenfisch", 0.1)]
        [Description("Test")]
        public class Test : RustPlugin
        {
            Item GetItem(string shortname, int amount)
            {
                var item = ItemManager.CreateByName(shortname, amount);            if (item == null) return null;            if (item.GetHeldEntity() is BaseProjectile)
                {
                    var heldEntity = item.GetHeldEntity() as BaseProjectile;                heldEntity.primaryMagazine.ammoType = ItemManager.CreateByName("ammo.pistol", 1).info;                AmmoTypes ammoTypes = 0;
                    heldEntity.primaryMagazine.definition.ammoTypes = ammoTypes;
                    SetFlag(heldEntity.primaryMagazine, AmmoTypes.PISTOL_9MM, true);
                    ItemModProjectile component =               heldEntity.primaryMagazine.ammoType.GetComponent<ItemModProjectile>();
                    if (component != null)
                    {
                        component.ammoType = ammoTypes;
                    }
                }            return item;
            }        public void SetFlag(BaseProjectile.Magazine m, AmmoTypes f, bool b)
            {
                if (!b)
                {
                    BaseProjectile.Magazine mag = m;
                    mag.definition.ammoTypes = mag.definition.ammoTypes & ~f;
                }
                else
                {
                    BaseProjectile.Magazine mag1 = m;
                    mag1.definition.ammoTypes = mag1.definition.ammoTypes | f;
                }
            }
        }
    }
    My question is, is it possible to change the type of ammunition a weapon holds/accepts with a plugin or are some parts of the weapon-reload-mechanic handled by the client, hence inaccessible?

    Thanks for your help! :)
    [DOUBLEPOST=1443562731,1443480810][/DOUBLEPOST]Bump
     

    Attached Files:

    • Test.cs
      File size:
      3.9 KB
      Views:
      23
  2. Calytic

    Calytic Community Admin Community Mod

    I'm going to venture a guess, without having tested your code, that this is like many other things that very creative people such as yourself have run into.

    It is not possible at the moment. Sorry.

    Why?

    Well, a good majority of the code that you are messing with server-side also exists client-side. Meaning that, unless the client accepts and updates client-side values from the server - changing said values server-side will either a) have no effect or b) creating confusing results (such as those you are experiencing). So, your only course of action (assuming the above is true) is to wait patiently for Facepunch to improve the parity between client and server-side variables. There is no guarantee that they will do this particular thing, however you may want to keep testing this bi-weekly, with maybe the slim chance that a patch will fix this issue.
     
  3. Like Calytic said, the biggest issue with Rust modding right now is that it isn't officially supported. Oxide and other modding platforms are pretty much hacking the server files to get their job done, patching and modifying DLL's from the game. A proper modding platform would have client and server side support so that modders can control both sides, but if Oxide were to start hacking files client side we'd run into problems with EAC/VAC before too long, not counting all the drama from people not wanting their client modified for privacy/paranoia reasons, etc.

    Hopefully Garry and the team will eventually work on proper modding support, but we aren't there yet.