@Wulf
there are three hooks for reloading weapons
OnReloadWeapon - when reload starts
OnSwitchAmmo - if player switched ammo, fired before OnReloadWeapon
OnReloadMagazine - in the end, right before calling Reload() function that finds ammo and puts it in the magazine, but there is one bad thing with it - in Reload() if it doesn't find current ammoType, it will search for any other possible ammoTypes for this weapon
so say, you have 10 ammo in AK and current ammoType = ammo.rifle, you press reload and drop your ammo.rifle, having ammo.rifle.explosive in the inventory, it will be reloaded in the weapon, but all three hooks won't ever know about this because of mentioned above code.Code:public bool Reload(BasePlayer owner) { List<Item> list1 = owner.inventory.FindItemIDs(this.ammoType.itemid).ToList<Item>(); if (list1.Count == 0) { List<Item> list2 = new List<Item>(); owner.inventory.FindAmmo(list2, this.definition.ammoTypes); if (list2.Count == 0) return false; list1 = owner.inventory.FindItemIDs(list2[0].info.itemid).ToList<Item>(); if (list1 == null || list1.Count == 0) return false; if (this.contents > 0) { owner.GiveItem(ItemManager.CreateByItemID(this.ammoType.itemid, this.contents, 0UL), BaseEntity.GiveItemReason.Generic); this.contents = 0; } this.ammoType = list1[0].info; }
So is there any chance to fix this? maybe fire additional hook OnSwitchAmmo when no such amo found? or else method?
there is one bad method how this can be coded without hook changes, but...
and thanks for your time reading this
OnReloadWeapon hook
Discussion in 'Rust Development' started by wazzzup, Jun 9, 2018.