1. Hi all,

    Spent the last few days working on my Game Mode mod, and it's been going great so far. Lots of progress and having lots of fun too.

    However, now I am blocked on something that at looked like it would be relatively simply. In certain conditions, I want to force a player to wear a specific item of clothing. I can create the item, and place it into the correct item container, but is there is (hopefully painless) way to prevent them from removing it. (I will remove it when the right conditions are met).

    I'd also like to be able to prevent people from wearing the item when I don't want them too. I don't mind if they have it in their inventory, just that they can't wear it.

    Many thanks in advance for any pointers,

    Regards,
    Nick.
     
  2. Don't think there is a hook for that but you could simply use a timer to reorganize player inventories that dont match your ruleset every X seconds?
     
  3. Thanks - that will certainly get the job done for now. If I can find a more elegant way, I'll post it back here.
     
  4. emu

    emu

    ItemContainers like the players's clothing have a locked value. Set it to true.
    I'm not at my PC so im not sure if this works, but it was something like this:
    Code:
    player.playerInventory.containerWear.locked = true;
    player is a BasePlayer.
     
  5. error CS1061:

    Type `ItemContainer' does not contain a definition for `locked' a nd no extension method `locked' of type `ItemContainer' could be found. Are you missing an assembly reference?
     
  6. It is a Flag. So what you gotta do is:
    player.inventory.containerWear.SetFlag(BasePlayer.Flag.IsLocked, true);
     
    Last edited by a moderator: Sep 26, 2015
  7. error CS0117:
    `BaseEntity.Flags' does not contain a definition for `IsLocked'

    and also if i try:

    error CS0117:
    `BaseEntity.Flags' does not contain a definition for `locked'
    [DOUBLEPOST=1443299902][/DOUBLEPOST]now with this:
    Code:
    player.inventory.containerWear.SetFlag(BasePlayer.Flags.Locked, true);
    i get this:
    Code:
     error CS1503:
    Argument `#1' cannot convert `BaseEntity.Flags'  expression to type `ItemContainer.Flag'
    [DOUBLEPOST=1443300019][/DOUBLEPOST]also no luck with:
    Code:
    error CS0117: `ItemContainer' does not contain a definition for `Flags'error CS0117: `ItemContainer.Flag' does not contain a definition for `Locked'error CS0117: `ItemContainer.Flag' does not contain a definition for `isLocked'
     
  8. show me the exact line you are using
     
  9. SOLVED

    this code works nice and does the work:
    Code:
    player.inventory.containerWear.SetFlag(ItemContainer.Flag.IsLocked, true);
    * it is case sensitive, and no other combinations i tried before did work
    also there was problem with BaseContainer.Flags, it has to be ItemContainer.Flag
    [DOUBLEPOST=1443301967][/DOUBLEPOST]
    exact line was the one you've suggested:
    Code:
    player.playerInventory.containerWear.SetFlag(BasePlayer.Flags.IsLocked, true);
     
  10. Of course it is case sensitive. C# is a case sensitive language. I just mixed BasePlayer.Flag and ItemContainer.Flag up. Sorry about that
     
  11. yes and for me it started to be messy when BaseContainer contains "Flags" meanwhile ItemContainer has "Flag" only...
     
  12. You don't actually need to bother with the flags, as there is already a helper method on the ItemContainer;

    Code:
    player.inventory.containerWear.SetLocked(true);
    However, this doesn't really do what I need, because it locks the entire container, and not the just one specific item in the container.

    It's possible to switch the current value of
    Code:
    player.inventory.containerWear.canAcceptItem
    for a new
    Code:
    Func<Item, Bool>
    , but care needs to be taken to replace the original value if the plug-in is unloaded. Anyway, with this approach, I can now properly block any items of my choice from being worn.

    I'm now looking for a method of preventing things being removed from a container, but having been through the entire inventory handling code, it seems like no such replaceable predicate exists. The hunt goes on...