Skip to content

Hide/show cloak/helm via OnPlayerChat

Just figured I'd share what I've done with my OnPlayerChat event to hide or show cloaks and helms simply by typing it. "/hide helm", "/show helm", "/hide cloak", "/show cloak". I also took into account a variable stored on the item that prevents it from being shown or hidden. If it helps anyone, awesome. If not, no harm done.

else if (sSaid == "/hide helm") { object oHelm = GetItemInSlot(INVENTORY_SLOT_HEAD, oSpeaker); if (!GetIsObjectValid(oHelm)) SendMessageToPC(oSpeaker, "You do not have a head item equipped."); else if (GetLocalInt(oHelm, "NO_HIDE")) SendMessageToPC(oSpeaker, "This item can not be hidden."); else if(!GetHiddenWhenEquipped(oHelm)) SetHiddenWhenEquipped(oHelm, TRUE); else SendMessageToPC(oSpeaker, "This item is already hidden."); SetPCChatMessage(""); } else if (sSaid == "/show helm") { object oHelm = GetItemInSlot(INVENTORY_SLOT_HEAD, oSpeaker); if (!GetIsObjectValid(oHelm)) SendMessageToPC(oSpeaker, "You do not have a head item equipped."); else if (GetLocalInt(oHelm, "HIDDEN")) SendMessageToPC(oSpeaker, "This item can not be shown."); else if (GetHiddenWhenEquipped(oHelm)) SetHiddenWhenEquipped(oHelm, FALSE); else SendMessageToPC(oSpeaker, "This item is already being shown."); SetPCChatMessage(""); } else if (sSaid == "/hide cloak") { object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK, oSpeaker); if (!GetIsObjectValid(oCloak)) SendMessageToPC(oSpeaker, "You do not have a cloak item equipped."); else if (GetLocalInt(oCloak, "NO_HIDE")) SendMessageToPC(oSpeaker, "This item can not be hidden."); else if(!GetHiddenWhenEquipped(oCloak)) SetHiddenWhenEquipped(oCloak, TRUE); else SendMessageToPC(oSpeaker, "This item is already hidden."); SetPCChatMessage(""); } else if (sSaid == "/show cloak") { object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK, oSpeaker); if (!GetIsObjectValid(oCloak)) SendMessageToPC(oSpeaker, "You do not have a cloak item equipped."); else if (GetLocalInt(oCloak, "HIDDEN")) SendMessageToPC(oSpeaker, "This item can not be shown."); else if (GetHiddenWhenEquipped(oCloak)) SetHiddenWhenEquipped(oCloak, FALSE); else SendMessageToPC(oSpeaker, "This item is already being shown."); SetPCChatMessage(""); }

Comments

  • RananRanan Member Posts: 34
    This is really awesome, I'm definitely going to implement this into my Module
  • BalanorBalanor Member Posts: 176
    Here is another option for player voice commands. For full disclosure though, the inspiration for this came from the OP. This version can do clothing, helms, and cloaks by typing !hide or !show followed by the item name (helm, helmet, armor, clothes, cloak, etc, etc). Just posting it here for further inspiration/revision/use.
    void MakeEquippedItemVisible(object oPC, string sSlot, int iVisible=TRUE)
    {
      int iSlot = -1;
      if (GetStringLeft(sSlot, 1) == " ") sSlot = GetStringRight(sSlot, GetStringLength(sSlot)-1); //Take either "armor" or " armor", for example
      if (sSlot == "clothes" || sSlot == "armor" || sSlot == "outfit") iSlot = INVENTORY_SLOT_CHEST; //Comment out this line to disable the ability to hide equipped chest items for all players
      if (sSlot == "helm" || sSlot == "helmet") iSlot = INVENTORY_SLOT_HEAD; //Comment out this line to disable the ability to hide equipped helms for all players
      if (sSlot == "cloak") iSlot = INVENTORY_SLOT_CLOAK; //Comment out this line to disable the ability to hide equipped cloaks for all players
    
      object oEquippedItem = GetItemInSlot(iSlot, oPC);
    
      if (!GetIsObjectValid(oEquippedItem) || iSlot == -1) SendMessageToPC(oPC, "You do not have a visible or hidden item equipped in that inventory slot.");
      else {
        if (iVisible) { //Show the item
          if (GetLocalInt(oEquippedItem, "ItemCannotBeShown")) SendMessageToPC(oPC, "That item cannot be shown."); //Allow Designer/DM restriction so an item will never be shown if the ItemCannotBeShown int is on it
          else if (GetHiddenWhenEquipped(oEquippedItem)) SetHiddenWhenEquipped(oEquippedItem, FALSE);
          else SendMessageToPC(oPC, "That item is already visible.");
        }
        else { //Hide the item
          if (GetLocalInt(oEquippedItem, "ItemCannotBeHidden")) SendMessageToPC(oPC, "That item cannot be hidden."); //Allow Designer/DM restriction so an item will never be hidden if the ItemCannotBeHidden int is on it
          else if (!GetHiddenWhenEquipped(oEquippedItem)) SetHiddenWhenEquipped(oEquippedItem, TRUE);
          else SendMessageToPC(oPC, "That item is already hidden.");
        }
      }
    
      SetPCChatMessage("");
    }
    
    void main()
    {
      object oPC = GetPCChatSpeaker();
      string sChat = GetPCChatMessage();
      if (GetStringLeft(sChat, 5) == "!hide") MakeEquippedItemVisible(oPC, GetStringRight(sChat, GetStringLength(sChat)-5), FALSE);
      if (GetStringLeft(sChat, 5) == "!show") MakeEquippedItemVisible(oPC, GetStringRight(sChat, GetStringLength(sChat)-5));
    }
  • fkirenicusfkirenicus Member Posts: 331
    edited January 2018
    @Balanor : is this generic in the sense that this will work for everyone as it is? And I should put it in the OnPlayer chat event, I presume?
  • BalanorBalanor Member Posts: 176
    Yes, it will work for everyone as-is. You can just copy and paste the entire thing into a script in your OnPlayerChat event.
  • LordLestatLordLestat Member Posts: 17
    You should upload this to the Vault. I bet a lot of folks would love to have it.
  • Sylvus_MoonbowSylvus_Moonbow Member Posts: 1,085
    Love to have it but useless since the OP never provided the wrapper or include script that GetHiddenWhenEquipped() and SetHiddenWhenEquipped() come from as they are custom and not standard functions in stock toolset script language. Compiler will stop at the first line it hits with that code and return UNKNOWN STATE IN COMPILER.
  • BalanorBalanor Member Posts: 176

    Love to have it but useless since the OP never provided the wrapper or include script that GetHiddenWhenEquipped() and SetHiddenWhenEquipped() come from as they are custom and not standard functions in stock toolset script language. Compiler will stop at the first line it hits with that code and return UNKNOWN STATE IN COMPILER.

    Incorrect. They are among some of the first new standard functions added to EE. The OP's example will require merging it into an existing OnPlayChat script, while the one I provided will compile as-is if you create a new script - so long as you are compiling either one using the EE toolset.
  • Sylvus_MoonbowSylvus_Moonbow Member Posts: 1,085
    Thank-you for that information as I checked with 1.69 toolset version.
  • LordLestatLordLestat Member Posts: 17
    This how I put it in my mods on chat script.

    else if (sCommand == "hidehelm")
    {
    object oHelm = GetItemInSlot(INVENTORY_SLOT_HEAD, oPC);
    if (!GetIsObjectValid(oHelm))
    {
    SendMessageToPC(oPC, "You do not have a head item equipped.");
    }
    else if (GetLocalInt(oHelm, "NO_HIDE"))
    {
    SendMessageToPC(oPC, "This item can not be hidden.");
    }
    else if(!GetHiddenWhenEquipped(oHelm))
    {
    SetHiddenWhenEquipped(oHelm, TRUE);
    }
    else
    {
    SendMessageToPC(oPC, "This item is already hidden.");
    }
    return;
    }
    else if (sCommand == "showhelm")
    {
    object oHelm = GetItemInSlot(INVENTORY_SLOT_HEAD, oPC);
    if (!GetIsObjectValid(oHelm))
    {
    SendMessageToPC(oPC, "You do not have a head item equipped.");
    }
    else if (GetLocalInt(oHelm, "HIDDEN"))
    {
    SendMessageToPC(oPC, "This item can not be shown.");
    }
    else if (GetHiddenWhenEquipped(oHelm))
    {
    SetHiddenWhenEquipped(oHelm, FALSE);
    }
    else
    {
    SendMessageToPC(oPC, "This item is already being shown.");
    }
    return;
    }
    else if (sCommand == "hidecloak")
    {
    object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC);
    if (!GetIsObjectValid(oCloak))
    {
    SendMessageToPC(oPC, "You do not have a cloak item equipped.");
    }
    else if (GetLocalInt(oCloak, "NO_HIDE"))
    {
    SendMessageToPC(oPC, "This item can not be hidden.");
    }
    else if(!GetHiddenWhenEquipped(oCloak))
    {
    SetHiddenWhenEquipped(oCloak, TRUE);
    }
    else
    {
    SendMessageToPC(oPC, "This item is already hidden.");
    }
    return;
    }
    else if (sCommand == "showcloak")
    {
    object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK, oPC);
    if (!GetIsObjectValid(oCloak))
    {
    SendMessageToPC(oPC, "You do not have a cloak item equipped.");
    }
    else if (GetLocalInt(oCloak, "HIDDEN"))
    {
    SendMessageToPC(oPC, "This item can not be shown.");
    }
    else if (GetHiddenWhenEquipped(oCloak))
    {
    SetHiddenWhenEquipped(oCloak, FALSE);
    }
    else
    {
    SendMessageToPC(oPC, "This item is already being shown.");
    }
    return;
    }
  • NeverwinterWightsNeverwinterWights Member Posts: 339
    Since it's been brought up again I have since changed the way I originally did this by doing something more similar to what @Balanor did but still inside the OnPlayerChat event. I also meshed it with the renaming of items.

    else if (sCommand == "/hide" || sCommand == "/show" || sCommand == "/rename") { string sBreak = StringRemoveParsed(sSaid, sCommand, " "); string sSlot = StringParse(sBreak, " "); string sName = StringRemoveParsed(sBreak, sSlot, " "); int iSlot = -1; if (sSlot == "head" || sSlot == "helm") iSlot = INVENTORY_SLOT_HEAD; if (sSlot == "cloak" || sSlot == "cape") iSlot = INVENTORY_SLOT_CLOAK; if (sSlot == "ring1" || sSlot == "rightring") iSlot = INVENTORY_SLOT_RIGHTRING; if (sSlot == "ring2" || sSlot == "leftring") iSlot = INVENTORY_SLOT_LEFTRING; if (sSlot == "boots") iSlot = INVENTORY_SLOT_BOOTS; if (sSlot == "belt") iSlot = INVENTORY_SLOT_BELT; if (sSlot == "righthand" || sSlot == "mainhand") iSlot = INVENTORY_SLOT_RIGHTHAND; if (sSlot == "lefthand" || sSlot == "offhand") iSlot = INVENTORY_SLOT_LEFTHAND; if (sSlot == "chest" || sSlot == "armor" || sSlot == "robes") iSlot = INVENTORY_SLOT_CHEST; if (sSlot == "arms" || sSlot == "gloves" || sSlot == "bracers") iSlot = INVENTORY_SLOT_ARMS; if (sSlot == "neck" || sSlot == "necklace") iSlot = INVENTORY_SLOT_NECK; if (sSlot == "bullets") iSlot = INVENTORY_SLOT_BULLETS; if (sSlot == "arrows") iSlot = INVENTORY_SLOT_ARROWS; if (sSlot == "bolts") iSlot = INVENTORY_SLOT_BOLTS; if (iSlot > -1) { object oItem = GetItemInSlot(iSlot, oSpeaker); if (GetIsObjectValid(oItem)) { if (sCommand == "/hide") { if (GetLocalInt(oItem, "NO_HIDE")) { SendMessageToPC(oSpeaker, "This item can not be hidden."); } else { if (!GetHiddenWhenEquipped(oItem)) SetHiddenWhenEquipped(oItem, TRUE); else SendMessageToPC(oSpeaker, "This item is already hidden."); } } if (sCommand == "/show") { if (GetLocalInt(oItem, "NO_SHOW")) { SendMessageToPC(oSpeaker, "This item can not be shown."); } else { if (GetHiddenWhenEquipped(oItem)) SetHiddenWhenEquipped(oItem, FALSE); else SendMessageToPC(oSpeaker, "This item is already shown."); } } if (sCommand == "/rename") { if (sName != "") { SetName(oItem, sName); SendMessageToPC(oSpeaker, "Your item has been renamed."); } else { SendMessageToPC(oSpeaker, "You didn't type anything to name your item."); } } } else { SendMessageToPC(oSpeaker, "There is no item in that slot."); } } else { SendMessageToPC(oSpeaker, "That is not a valid item slot for items that can be hidden or shown."); } }
  • VifurPLVifurPL Member Posts: 23
    How should the script be modifyed to be used in conversation with NPC?
    "Show my helmet"
    "Hide my helmet"
    "Show my cloak"
    "Hide my cloak"
Sign In or Register to comment.