1. Hi All

    I'm having some issues and wondering if this either not possible or I'm going about it the wrong way.

    I'm trying to access the GunItemEquippedState in order to update AmmoCount and HasReloaded - which will end up triggering on client spawn/kit being provided. Reason for this is the autokit provides a gun which needs reloading every spawn.

    So far... I've got the Gun from the player inventory/Items object..

    Code:
    var pInventory = session.WorldPlayerEntity.GetComponent<PlayerInventory>();
    var items = pInventory.Items[0]; //First slot. Gun - returns ItemInstance
    
    Within ItemInstance we can use Item (returning IItem) fine but i'm trying to use ItemState, which returns an object (type GunItem) which I cast to GunItem ..

    Code:
    GunItem gunItemObj = (GunItem)items.Item.ItemState;
    hurt.SendChatMessage(session, string.Format("Value is {0}",gunItemObj.GetClipSize()));
    Unfortunately I cant get much further..

    The next step though would be to get to GunItemEquippedState, if there's an easier route I'd appreciate a point in the right direction :)

    Has anyone achieved this? if so, would you mind pointing out where i'm being stupid...
     
  2. Clip ammo is currently stored in ItemInstance.AuxData (a single byte - so your clip size cannot be greater than 255). Note that this is a temporary solution for item instance data and will be changed at some point in the future. Have a look at GunItem.ReloadServer.

    It looks like ItemState is unused, so won't provide you with anything valuable. If you want to do something whenever a player equips an item, use EquipServer. If you want to arbitrarily get the current GunItemEquippedState, use BaseItem.EquippedState(EquippedHandlerBase player). EquippedHandlerBase is a component that can be found on the player gameobject with a GetComponent.
     
  3. You should be able to see what you need in Unlimited Ammo too.
     
  4. Code:
    var weapon = itemInstance.Item as IProjectileBasedWeapon;
    if(weapon != null) itemInstance.AuxData = (byte)weapon.GetClipSize();
     
  5. Thanks all! a bit of a delayed response - apologies. Yes i've subsequently seen UnlimitedAmmo but still had issues with initial spawn as the gun wasn't loaded. I couldnt find a solution there but will have a look at cowtrix's suggestion around ReloadServer. thanks again, will mark as solved!