How to check clothing item is in lowest layer (check if would be nude if removed)

Hello

Another plea for help from this new Quest person:

How do I check that the clothing object to be removed would leave the player naked? The scenario is that the player needs to remove clothing and change into other clothing, but this can only be done in a specific location (a changing room).

I've read the wearable items tutorial but I'm not sure that what it suggests is what I need (and I don't fully understand it). What I need, I think, is something adding to the remove command, along the lines of:

If item to be removed is in the lowest layer and player is not in the changing room then say "you can't be naked here", else do the rest of the command. I suppose that what I really need to know is how to check than an item is in the lowest layer (I'm only using one slot). I've tried experimenting with GetOuter, TestGarment, TestRemove but I am lost.

Thanks!


I think you need to create a function TestRemove, which checks:

<function name="TestRemove" parameters="garment" type="boolean"><![CDATA[
  if (GetBoolean (game.pov.parent, "changingroom")) {
    return (true)
  }
  exposed_slots = NewStringList()
  foreach (slot, garment.wear_slots) {
    found_underwear = false
    foreach (obj, ScopeInventory()) {
      if (GetBoolean (obj, "worn")) {
        if (ListContains (obj.wear_slots, slot) and obj.wear_layer < garment.wear_layer) {
          found_underwear = true
        }
      }
    }
    if (not found_underwear) {
      list add (exposed_slots, slot)
    }
  }
  if (ListCount (exposed_slots) = 0) {
    return (true)
  }
  else {
    msg ("You can't expose your " + FormatList (exposed_slots, ", ", ", and", "") + " here!")
    return (false)
  }
]]></function>

In this case, I'm assuming the changing rooms have an attribute changingroom set to true.

If you want to make it more nuanced, for example you can go topless in one area but can't take your pants off, it would be more like:

<function name="TestRemove" parameters="garment" type="boolean"><![CDATA[
  exposed_slots = NewStringList()
  foreach (slot, garment.wear_slots) {
    found_underwear = false
    foreach (obj, ScopeInventory()) {
      if (GetBoolean (obj, "worn")) {
        if (ListContains (obj.wear_slots, slot) and obj.wear_layer < garment.wear_layer) {
          found_underwear = true
        }
      }
    }
    if (not found_underwear) {
      list add (exposed_slots, slot)
    }
  }
  rooms = ListParents (game.pov)
  list add (rooms, game)
  foreach (room, rooms) {
    if (HasString (room, "can_expose")) {
      room.can_expose = Split (room.can_expose)
    }
    if (HasAttribute (room, "can_expose")) {
      exposed_slots = ListExclude (exposed_slots, room.can_expose)
    }
  }
  if (ListCount (exposed_slots) = 0) {
    return (true)
  }
  else {
    msg ("You can't expose your " + FormatList (exposed_slots, ", ", ", and", "") + " here!")
    return (false)
  }
]]></function>

This version lets you give each room, building, or the game itself an attribute can_expose, which is either a stringlist or a string like "head;feet;hands".

You could set game.can_expose to "head;feet;hands" to let the player take off their hat or gloves wherever they want; gym.can_expose to "chest" if people can work out topless, and changingroom.can_expose to a list of your other slots.


Wonderful, thanks: the first bit of code works perfectly for me, and I (almost) understand (most) of it!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums