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.
Force wearing of specific clothing item
Discussion in 'Rust Development' started by Nick Holmes, Sep 25, 2015.
-
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?
-
-
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;
-
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? -
player.inventory.containerWear.SetFlag(BasePlayer.Flag.IsLocked, true);Last edited by a moderator: Sep 26, 2015 -
`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);
Code:error CS1503: Argument `#1' cannot convert `BaseEntity.Flags' expression to type `ItemContainer.Flag'
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'
-
-
SOLVED
this code works nice and does the work:
Code:player.inventory.containerWear.SetFlag(ItemContainer.Flag.IsLocked, true);
also there was problem with BaseContainer.Flags, it has to be ItemContainer.Flag
[DOUBLEPOST=1443301967][/DOUBLEPOST]
Code:player.playerInventory.containerWear.SetFlag(BasePlayer.Flags.IsLocked, true);
-
-
-
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);
It's possible to switch the current value ofCode:player.inventory.containerWear.canAcceptItem
Code:Func<Item, Bool>
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...