Author Topic: Making an item that cannot be unequipped?  (Read 1026 times)

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Making an item that cannot be unequipped?
« on: July 09, 2012, 02:41:32 pm »


                Just a quick on here - is there a way to create a "cursed" item that cannot be unequpped until certain conditions are met, Baldur's Gate-style? The standard "cursed" funtion only seems to stop the PC from dropping or selling a given item; I need a certain item (a cursed amulet) to stay in its slot until the relevant quest is finished.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #1 on: July 09, 2012, 02:46:35 pm »


               of course, you can re-equip the item in the OnUnEquip event
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #2 on: July 09, 2012, 04:59:07 pm »


               Here's my item_equip script:

#include "inc_functions"
void main()
{
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();
string sTag = GetTag(oItem);
////////////////////////////////////////////////////////////////////////////////
if (!GetIsCursed(oPC) && sTag == "grandeepee16")
 {
 SetLocalInt(oPC, "cursed", 1);
 SetBerserk(oPC);
 }
else if (!GetIsCursed(oPC) && sTag == "ceinture23")
 {
 SetLocalInt(oPC, "cursed", 1);
 SetLocalInt(oPC, "apparence", GetAppearanceType(oPC));
 if (GetGender(oPC) == GENDER_MALE) SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_FEMALE_01);
 else if (GetGender(oPC) == GENDER_FEMALE) SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_MALE_01);
 }
//
if (GetIsCursed(oItem))
 {
 SetLocalInt(oPC, "cursed", 1);
 SetLocalInt(oItem, "cursed", 2);
 }
}

My item_unequip script:

#include "inc_functions"
void main()
{
object oPC = GetPCItemLastUnequippedBy();
object oItem = GetPCItemLastUnequipped();
string sTag = GetTag(oItem);
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetIsCursed(oItem))
 {
 int nSlot = GetItemSlot(oItem);
 AssignCommand(oPC, ClearAllActions(TRUE));
 AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
 SendMessageToPC(oPC, "Cet objet est maudit!");
 DelayCommand(0.1, SetCommandable(FALSE, oPC));
 DelayCommand(2.0, SetCommandable(TRUE, oPC));
 }
else if (!GetIsCursed(oPC) && GetIsCursed(oItem) && GetTag(oItem) == "ceinture23") SetCreatureAppearanceType(oPC, GetLocalInt(oPC, "apparence"));
if (!GetIsCursed(oPC) && GetIsCursed(oItem)) SetLocalInt(oItem, "cursed", 1);
}

My item_unacquire script:

#include "inc_functions"
void main()
{
object oPC = GetModuleItemLostBy();
object oItem = GetModuleItemLost();
string sTag = GetTag(oItem);
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetLocalInt(oItem, "cursed") == 2)
 {
 int nSlot = GetItemSlot(oItem);
 AssignCommand(oPC, ClearAllActions(TRUE));
 AssignCommand(oPC, ActionPickUpItem(oItem));
 AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
 SendMessageToPC(oPC, "Cet objet est maudit!");
 DelayCommand(0.1, SetCommandable(FALSE, oPC));
 DelayCommand(2.0, SetCommandable(TRUE, oPC));
 }
}

And the two custom functions in my include:

int GetItemSlot(object oItem)
{
int nType = GetBaseItemType(oItem);
if (nType == BASE_ITEM_AMULET) return INVENTORY_SLOT_NECK;
else if (nType == BASE_ITEM_ARMOR) return INVENTORY_SLOT_CHEST;
else if (nType == BASE_ITEM_BASTARDSWORD ||
         nType == BASE_ITEM_BATTLEAXE ||
         nType == BASE_ITEM_CLUB ||
         nType == BASE_ITEM_DAGGER ||
         nType == BASE_ITEM_DIREMACE ||
         nType == BASE_ITEM_DOUBLEAXE ||
         nType == BASE_ITEM_DWARVENWARAXE ||
         nType == BASE_ITEM_GREATAXE ||
         nType == BASE_ITEM_GREATSWORD ||
         nType == BASE_ITEM_HALBERD ||
         nType == BASE_ITEM_HANDAXE ||
         nType == BASE_ITEM_HEAVYCROSSBOW ||
         nType == BASE_ITEM_HEAVYFLAIL ||
         nType == BASE_ITEM_KAMA ||
         nType == BASE_ITEM_KATANA ||
         nType == BASE_ITEM_KUKRI ||
         nType == BASE_ITEM_LIGHTCROSSBOW ||
         nType == BASE_ITEM_LIGHTFLAIL ||
         nType == BASE_ITEM_LIGHTHAMMER ||
         nType == BASE_ITEM_LIGHTMACE ||
         nType == BASE_ITEM_LONGBOW ||
         nType == BASE_ITEM_LONGSWORD ||
         nType == BASE_ITEM_MAGICROD ||
         nType == BASE_ITEM_MAGICSTAFF ||
         nType == BASE_ITEM_MAGICWAND ||
         nType == BASE_ITEM_MORNINGSTAR||
         nType == BASE_ITEM_QUARTERSTAFF ||
         nType == BASE_ITEM_RAPIER ||
         nType == BASE_ITEM_SCIMITAR ||
         nType == BASE_ITEM_SCYTHE ||
         nType == BASE_ITEM_SHORTBOW ||
         nType == BASE_ITEM_SHORTSPEAR ||
         nType == BASE_ITEM_SHORTSWORD ||
         nType == BASE_ITEM_SICKLE ||
         nType == BASE_ITEM_SLING ||
         nType == BASE_ITEM_TRIDENT ||
         nType == BASE_ITEM_TWOBLADEDSWORD ||
         nType == BASE_ITEM_WARHAMMER ||
         nType == BASE_ITEM_WHIP) return INVENTORY_SLOT_RIGHTHAND;
else if (nType == BASE_ITEM_BELT) return INVENTORY_SLOT_BELT;
else if (nType == BASE_ITEM_BOOTS) return INVENTORY_SLOT_BOOTS;
else if (nType == BASE_ITEM_BRACER ||
         nType == BASE_ITEM_GLOVES) return INVENTORY_SLOT_ARMS;
else if (nType == BASE_ITEM_CLOAK) return INVENTORY_SLOT_CLOAK;
else if (nType == BASE_ITEM_HELMET) return INVENTORY_SLOT_HEAD;
else if (nType == BASE_ITEM_LARGESHIELD ||
         nType == BASE_ITEM_SMALLSHIELD ||
         nType == BASE_ITEM_TOWERSHIELD) return INVENTORY_SLOT_RIGHTHAND;
else if (nType == BASE_ITEM_RING) return INVENTORY_SLOT_LEFTRING;
else return -1;
}

int GetIsCursed(object oObject)
{
if (GetLocalInt(oObject, "cursed") != 0) return TRUE;
return FALSE;
}


The only problem is with a ring in the right slot, it will be reequiped in the left slot... Otherwise it works pretty well for what you want to do. And in my spellhook, casting remove curse delete the local int on the pc or the item (depends on what you cast it). Of course for this to work you need to set the variable "cursed" to 1 on the item you want to be cursed!
               
               

               


                     Modifié par Krevett, 09 juillet 2012 - 04:07 .
                     
                  


            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #3 on: July 09, 2012, 05:07:25 pm »


               

Krevett wrote...

Here's my item_equip script:

#include "inc_functions"
void main()
{
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();
string sTag = GetTag(oItem);
////////////////////////////////////////////////////////////////////////////////
if (!GetIsCursed(oPC) && sTag == "grandeepee16")
 {
 SetLocalInt(oPC, "cursed", 1);
 SetBerserk(oPC);
 }
else if (!GetIsCursed(oPC) && sTag == "ceinture23")
 {
 SetLocalInt(oPC, "cursed", 1);
 SetLocalInt(oPC, "apparence", GetAppearanceType(oPC));
 if (GetGender(oPC) == GENDER_MALE) SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_FEMALE_01);
 else if (GetGender(oPC) == GENDER_FEMALE) SetCreatureAppearanceType(oPC, APPEARANCE_TYPE_MALE_01);
 }
//
if (GetIsCursed(oItem))
 {
 SetLocalInt(oPC, "cursed", 1);
 SetLocalInt(oItem, "cursed", 2);
 }
}

My item_unequip script:

#include "inc_functions"
void main()
{
object oPC = GetPCItemLastUnequippedBy();
object oItem = GetPCItemLastUnequipped();
string sTag = GetTag(oItem);
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetIsCursed(oItem))
 {
 int nSlot = GetItemSlot(oItem);
 AssignCommand(oPC, ClearAllActions(TRUE));
 AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
 SendMessageToPC(oPC, "Cet objet est maudit!");
 DelayCommand(0.1, SetCommandable(FALSE, oPC));
 DelayCommand(2.0, SetCommandable(TRUE, oPC));
 }
else if (!GetIsCursed(oPC) && GetIsCursed(oItem) && GetTag(oItem) == "ceinture23") SetCreatureAppearanceType(oPC, GetLocalInt(oPC, "apparence"));
if (!GetIsCursed(oPC) && GetIsCursed(oItem)) SetLocalInt(oItem, "cursed", 1);
}

My item_unacquire script:

#include "inc_functions"
void main()
{
object oPC = GetModuleItemLostBy();
object oItem = GetModuleItemLost();
string sTag = GetTag(oItem);
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetLocalInt(oItem, "cursed") == 2)
 {
 int nSlot = GetItemSlot(oItem);
 AssignCommand(oPC, ClearAllActions(TRUE));
 AssignCommand(oPC, ActionPickUpItem(oItem));
 AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
 SendMessageToPC(oPC, "Cet objet est maudit!");
 DelayCommand(0.1, SetCommandable(FALSE, oPC));
 DelayCommand(2.0, SetCommandable(TRUE, oPC));
 }
}

And the two custom functions in my include:

int GetItemSlot(object oItem)
{
int nType = GetBaseItemType(oItem);
if (nType == BASE_ITEM_AMULET) return INVENTORY_SLOT_NECK;
else if (nType == BASE_ITEM_ARMOR) return INVENTORY_SLOT_CHEST;
else if (nType == BASE_ITEM_BASTARDSWORD ||
         nType == BASE_ITEM_BATTLEAXE ||
         nType == BASE_ITEM_CLUB ||
         nType == BASE_ITEM_DAGGER ||
         nType == BASE_ITEM_DIREMACE ||
         nType == BASE_ITEM_DOUBLEAXE ||
         nType == BASE_ITEM_DWARVENWARAXE ||
         nType == BASE_ITEM_GREATAXE ||
         nType == BASE_ITEM_GREATSWORD ||
         nType == BASE_ITEM_HALBERD ||
         nType == BASE_ITEM_HANDAXE ||
         nType == BASE_ITEM_HEAVYCROSSBOW ||
         nType == BASE_ITEM_HEAVYFLAIL ||
         nType == BASE_ITEM_KAMA ||
         nType == BASE_ITEM_KATANA ||
         nType == BASE_ITEM_KUKRI ||
         nType == BASE_ITEM_LIGHTCROSSBOW ||
         nType == BASE_ITEM_LIGHTFLAIL ||
         nType == BASE_ITEM_LIGHTHAMMER ||
         nType == BASE_ITEM_LIGHTMACE ||
         nType == BASE_ITEM_LONGBOW ||
         nType == BASE_ITEM_LONGSWORD ||
         nType == BASE_ITEM_MAGICROD ||
         nType == BASE_ITEM_MAGICSTAFF ||
         nType == BASE_ITEM_MAGICWAND ||
         nType == BASE_ITEM_MORNINGSTAR||
         nType == BASE_ITEM_QUARTERSTAFF ||
         nType == BASE_ITEM_RAPIER ||
         nType == BASE_ITEM_SCIMITAR ||
         nType == BASE_ITEM_SCYTHE ||
         nType == BASE_ITEM_SHORTBOW ||
         nType == BASE_ITEM_SHORTSPEAR ||
         nType == BASE_ITEM_SHORTSWORD ||
         nType == BASE_ITEM_SICKLE ||
         nType == BASE_ITEM_SLING ||
         nType == BASE_ITEM_TRIDENT ||
         nType == BASE_ITEM_TWOBLADEDSWORD ||
         nType == BASE_ITEM_WARHAMMER ||
         nType == BASE_ITEM_WHIP) return INVENTORY_SLOT_RIGHTHAND;
else if (nType == BASE_ITEM_BELT) return INVENTORY_SLOT_BELT;
else if (nType == BASE_ITEM_BOOTS) return INVENTORY_SLOT_BOOTS;
else if (nType == BASE_ITEM_BRACER ||
         nType == BASE_ITEM_GLOVES) return INVENTORY_SLOT_ARMS;
else if (nType == BASE_ITEM_CLOAK) return INVENTORY_SLOT_CLOAK;
else if (nType == BASE_ITEM_HELMET) return INVENTORY_SLOT_HEAD;
else if (nType == BASE_ITEM_LARGESHIELD ||
         nType == BASE_ITEM_SMALLSHIELD ||
         nType == BASE_ITEM_TOWERSHIELD) return INVENTORY_SLOT_RIGHTHAND;
else if (nType == BASE_ITEM_RING) return INVENTORY_SLOT_LEFTRING;
else return -1;
}

int GetIsCursed(object oObject)
{
if (GetLocalInt(oObject, "cursed") != 0) return TRUE;
return FALSE;
}


The only problem is with a ring in the right slot, it will be reequiped in the left slot... Otherwise it works pretty well for what you want to do. And in my spellhook, casting remove curse delete the local int on the pc or the item (depends on what you cast it).

Thanks, I read through that and it looks just about perfect. I'm kind of ashamed to have been scripting for a good four years and still being unable to do such basic stuff! 
               
               

               


                     Modifié par Mr. Versipellis, 09 juillet 2012 - 04:46 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #4 on: July 09, 2012, 05:16:58 pm »


               I was just a perfect beginner two years ago (in the toolset) and it took me a while putting this to work '<img'> so bad that cursed items can't be done more easily!! I didn't put the SetBerserk function but you might guess what it's about!!!
               
               

               
            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #5 on: July 09, 2012, 05:47:55 pm »


               

Krevett wrote...

I was just a perfect beginner two years ago (in the toolset) and it took me a while putting this to work '<img'> so bad that cursed items can't be done more easily!! I didn't put the SetBerserk function but you might guess what it's about!!!

How times change! I think the beserk thing is a bit much - this is for story reasons (the amulet I'm working with is part of a magical crystal which is embedded in the PC's chest until the end of the quest, when it gets removed.) I'm still a little confused -  where would I need to put each script and where which variables need changing to get it working properly? 
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #6 on: July 09, 2012, 06:35:28 pm »


               these three scripts each go in the corresponding module event (OnPlayerEquipItem, OnPlayerUnEquipItem, OnUnAcquireItem).
Also if you just want an item that cannot be removed you can just use these:

OnEquip:
#include "inc_functions"
void main()
{
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oItem))
{
SetLocalInt(oPC, "cursed", 1);
SetLocalInt(oItem, "cursed", 2);
}
}


OnUnEquip:
#include "inc_functions"
void main()
{
object oPC = GetPCItemLastUnequippedBy();
object oItem = GetPCItemLastUnequipped();
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetIsCursed(oItem))
{
int nSlot = GetItemSlot(oItem);
AssignCommand(oPC, ClearAllActions(TRUE));
AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
SendMessageToPC(oPC, "Cet objet est maudit!");
DelayCommand(0.1, SetCommandable(FALSE, oPC));
DelayCommand(2.0, SetCommandable(TRUE, oPC));
}
if (!GetIsCursed(oPC) && GetIsCursed(oItem)) SetLocalInt(oItem, "cursed", 1);
}

OnUnAcquire:
#include "inc_functions"
void main()
{
object oPC = GetModuleItemLostBy();
object oItem = GetModuleItemLost();
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetLocalInt(oItem, "cursed") == 2)
{
int nSlot = GetItemSlot(oItem);
AssignCommand(oPC, ClearAllActions(TRUE));
AssignCommand(oPC, ActionPickUpItem(oItem));
AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
SendMessageToPC(oPC, "Cet objet est maudit!");
DelayCommand(0.1, SetCommandable(FALSE, oPC));
DelayCommand(2.0, SetCommandable(TRUE, oPC));
}
}

And when creating your amulet put a local variable "cursed" on it set to 1.
You will also need the two functions GetItemSlot and GetIsCursed of course!
               
               

               


                     Modifié par Krevett, 09 juillet 2012 - 05:38 .
                     
                  


            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #7 on: July 09, 2012, 11:09:31 pm »


               

Krevett wrote...

these three scripts each go in the corresponding module event (OnPlayerEquipItem, OnPlayerUnEquipItem, OnUnAcquireItem).
Also if you just want an item that cannot be removed you can just use these:

OnEquip:
#include "inc_functions"
void main()
{
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oItem))
{
SetLocalInt(oPC, "cursed", 1);
SetLocalInt(oItem, "cursed", 2);
}
}


OnUnEquip:
#include "inc_functions"
void main()
{
object oPC = GetPCItemLastUnequippedBy();
object oItem = GetPCItemLastUnequipped();
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetIsCursed(oItem))
{
int nSlot = GetItemSlot(oItem);
AssignCommand(oPC, ClearAllActions(TRUE));
AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
SendMessageToPC(oPC, "Cet objet est maudit!");
DelayCommand(0.1, SetCommandable(FALSE, oPC));
DelayCommand(2.0, SetCommandable(TRUE, oPC));
}
if (!GetIsCursed(oPC) && GetIsCursed(oItem)) SetLocalInt(oItem, "cursed", 1);
}

OnUnAcquire:
#include "inc_functions"
void main()
{
object oPC = GetModuleItemLostBy();
object oItem = GetModuleItemLost();
////////////////////////////////////////////////////////////////////////////////
if (GetIsCursed(oPC) && GetLocalInt(oItem, "cursed") == 2)
{
int nSlot = GetItemSlot(oItem);
AssignCommand(oPC, ClearAllActions(TRUE));
AssignCommand(oPC, ActionPickUpItem(oItem));
AssignCommand(oPC, ActionEquipItem(oItem, nSlot));
SendMessageToPC(oPC, "Cet objet est maudit!");
DelayCommand(0.1, SetCommandable(FALSE, oPC));
DelayCommand(2.0, SetCommandable(TRUE, oPC));
}
}

And when creating your amulet put a local variable "cursed" on it set to 1.
You will also need the two functions GetItemSlot and GetIsCursed of course!

I think I get it. Wouldn't it be more simple just to do a tag-based script that re-equipped the item, though?
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #8 on: July 09, 2012, 11:17:07 pm »


               The problem lies in the unacquire then... It probably needs some testing but I think that if you just make the item beeing re-equipped on unequipping it and the player tries to drop it directly the item get dropped on the ground. That's why I dit the script that way, but anyway it could be tagbased with some small change ;-)
               
               

               
            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #9 on: July 09, 2012, 11:22:50 pm »


               

Krevett wrote...

The problem lies in the unacquire then... It probably needs some testing but I think that if you just make the item beeing re-equipped on unequipping it and the player tries to drop it directly the item get dropped on the ground. That's why I dit the script that way, but anyway it could be tagbased with some small change ;-)

Ah, in that case, I'll just go with your version - it's not that there was anything wrong with it, I just like to find the very best way of doing such things! Thanks terribly for the fast replies, if you ever need help with anything NWN-related, don't hesitate to ask c:
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #10 on: July 10, 2012, 12:01:17 am »


               I also like to find an optimal way to do things but unfortunatly haven't found something better for now (and it works well for what I want to do so...) anyway a pleasure to help!! Good night for those other frenchies here!!
               
               

               
            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #11 on: July 10, 2012, 02:13:26 am »


               Why are you not using GetItemCursedFlag(object oItem) and SetItemCursedFlag(object oItem, int nCursed) functions to make the item not dropable?
               
               

               
            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #12 on: July 10, 2012, 08:04:25 am »


               Because I want the item to be droppable if not equipped
               
               

               
            

Legacy_Mr. Versipellis

  • Full Member
  • ***
  • Posts: 236
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #13 on: July 10, 2012, 05:12:35 pm »


               Hmm... I can't seem to get these working. I did what you said, and when I unequip the item, I get the message. However, at the same time, it appears normally in my inventory, and as a kind of "ghost image" in the neck slot. Any clue what's causing this?
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Making an item that cannot be unequipped?
« Reply #14 on: July 10, 2012, 05:32:52 pm »


               The GUI is not updating on the screen.   Close your character sheet and reopen it, to see where your items really are.