Item equipping restrictions by tag

I just have a question about this. I already have a solution, but I’m not so fond of it, although I guess it might be the only way to do it.

It seems that you can’t do a restriction on an item based on the tag of a creature, right? I have an armor that I would like only to be equippable by a companion with a certain tag. Of course I can make the item cursed, and I’ve used something like this script here:

// i_temp_eq
/*
   
   Template for an Equip item script.
   This script will run each time the item is equipped.
   
   How to use this script:
   Replace the word "temp" (in line 1) with the tag of the item.  Rename the script with this name.  
    
   Additional Info:
   In general, all the item "tag-based" scripts will be named as follows:
   - a prefix ("i_" by defualt)
   - the tag of the item
   - a postfix indicating the item event.
   
   This script will be called automatically (by defualt) whether it exists or not.  If if does not exist, nothing happens.
   
   Note: this script runs on the module object, an important consideration for assigning actions.
   -ChazM   
*/
// Name_Date

void main()
{
    object oPC      = GetPCItemLastEquippedBy();
    object oItem    = GetPCItemLastEquipped();

 	object oJanine = GetObjectByTag("janine");
	object oPC1 = GetFirstPC();
	
	if(oPC != oJanine)
	{
	
	AssignCommand(oPC1,SpeakString("Only Janine can use this armor."));	
	return;

	}

	
}

So, ok, I guess this works, but what I would really like (I guess that’s impossible) is to have the armor being red (unusable) when it lands in the PCs inventory. Right now I think it will only be so that if the PC tries to equip the armor it will say that you can’t equip it.

andgalf… I’ve done this but it all depends on the PC’s class, just put a class restriction on the item that’s the same as the companion you want to use it.

Use the script and the restriction and you’re more likely to get away with it

Precisely. There’s a big chance the player has the same class so…

You could try putting multiple ‘use limitation’ properties on the armor. For example, you could put these properties on the item with the specific character’s parameters:
Use Limitation: Class
Use Limitation: Racial Type
Use Limitation: Specific Alignment

The chances of the player having the exact parameters is very slim, thus preventing anyone else from equipping the item.

Hmm, ok. Maybe…The player having the exact same parameters are slim, but not that slim, since there are already a few restrictions for playing the module in the first place because of the story but…well, ok. I’m still a bit bummed that there’s no other way of making the armor “red” with the tag thing.

andgalf… If you can put in a conversation somewhere after the armour gets given, check if the companion has it and if not have her demand it from the PC. Or not talk again until she gets it, I did a similar thing with an amulet for a companion, she’s useless without it and the quest wont finish.

Or as travus said make it really difficult to match her stats make her racial type an ooze or a plant nobody can start a game as one of them.

Yeah, that’s one way to do it, I guess. It doesn’t feel right with that kind of dialogue here in this module though…

I have it at one point the the whole party gets stripped of all items when they get thrown in jail. Then they find all the items in a chest (just like the script I showed you) and that’s why you can as the PC put it in your inventory. Well, I think I’ll go with the restrictions and my equip script, to be on the safe side.

// i_itemtag_aq
/*
	Add the item's tag to the name of this script so it uses tag based scripting once it is acquired.
	e.g. If the tag of the item is 'excalibur', then the name of this script must be exactly "i_excalibur_aq".
	This will make the item unuseable (red icon in inventory) by anybody accept by the designated tag. 
*/
	
#include "x2_inc_craft"

void main()
{
	object oPC = GetModuleItemAcquiredBy();
	object oItem = GetModuleItemAcquired();

	if (GetTag(oPC) == "casavir")	// change tag to the character that can use the item
	{
		MakeItemUseableByClass(CLASS_TYPE_PALADIN, oItem);	// change CLASS_TYPE_* to the class of the
															// character that can use the item
	}

	else
	{
		AssignCommand(oPC, SpeakString("<color=yellow>Only Casavir can equip this")); 
		MakeItemUseableByClass(CLASS_TYPE_COMMONER, oItem);
	}
}

andgalf. I’m throwing my people in jail too and then worse things happen ! Do you think it’s some sort of subconscious thing that at some point we get fed up with the people we create ?

Actually now I think about it every mod I’ve made has involved people getting thrown in jail or turned into slaves so it probably is !

Going back to your armour issue, you could restrict it as much as possible then delete it before the strip, make a new one and give it back to the companion ( after finding the chest ) using the script you just gave me that way you can curse it.

Interesting script you got there, @travus. I’ll try it out and see what happens.

So even if the PC is say a paladin according to your script, it will still be “red” for the PC? Ah wait…now I think I get it. Once the module aquires the item which it does as soon as you load the module (?) it’s only usable by the paladin with the tag casavir, otherwise it will only be able to be used by a commoner?

Yes, the item will be set to useable only by a commoner if the tag of the acquiring character is not correct. Because only commoners can use it, it’ll show up as red in the party’s inventory.
If the tag does match, then it’ll be set to the class of the character in question, thus allowing that character to use the item.
Should the item later be given to the wrong character, it’ll again be set to useable by a commoner only, thus preventing anybody else from using it.

1 Like

Sounds great and exactly what I needed. I’ll try it out. Thanks!

Hmm, when testing it didn’t seem to work quite as advertised with the armor being “red” but I may have made some mistake. I’ll test it more tomorrow. At least you can’t equip the armor if you’re the PC but…

I’ll edit the script with your answers…
What is the tag of the item?
What is the tag of the character who can use the item?
What is the class of the character who can use the item?

You can use tag based scripting to do this. i did it for for some NPC in BGR.

The basic idea is to unequip or detroy/recreate the item n the inventory based on conditions, you call the script with the generic module script corresponding at the actions you wish to check. There is a lot of explanation on NWN script and ressource on tag based scripting.

@travus - I’ve looked into it some more and I think I know what the problem is now. The armor is first on the NPC, in this case a fighter, and when that happens I look at the armor in her inventory and it says: Only useable by fighter. So far so good. Then when I move her armor to the PC, who is also a fighter, it says on the armor: Only useable by Fighter AND Only useable by Commoner. So I think we need to somehow reset the thing when it’s transfered between characters. The message with “Only “charactername” can use this” pops up every time the item is transfered to the PC, so that’s all good.

EDIT: Problem is, I can’t find any function in the Script Assist that makes the item unuseable for a class. If such a function exists then I think that would solve the whole thing.

EDIT 2: I think I’ve solved it! I found a script by @kevL_s for my previous module. I extracted some of his code from there (Thank you kevL_s!) and applied to this, and as far as I can see it works splendidly ingame. Let me know if there are any caveats to have in mind, or else I will go with this. Here’s the script now:

// i_itemtag_aq
/*
	Add the item's tag to the name of this script so it uses tag based scripting once it is acquired.
	This will make the item unuseable (red icon in inventory) by anybody accept by the designated tag. 

    Script by travus. Modified by andgalf by using code from another script by kevL_s.
*/
	
#include "x2_inc_craft"

void main()
{
	object oPC = GetModuleItemAcquiredBy();
	object oItem = GetModuleItemAcquired();

	if (GetTag(oPC) == "janine")	// change tag to what you need
	{
		itemproperty ip = GetFirstItemProperty(oItem); // iterate over all IPs on 'oItem'
		while (GetIsItemPropertyValid(ip))
		{
			if (GetItemPropertyType(ip) == ITEM_PROPERTY_USE_LIMITATION_CLASS) 
			{
			RemoveItemProperty(oItem, ip);
			ip = GetFirstItemProperty(oItem); 
			}
		else ip = GetNextItemProperty(oItem);
		}
	
		MakeItemUseableByClass(CLASS_TYPE_FIGHTER, oItem);	// change class type to what you need
	}

	else
	{
		AssignCommand(oPC, SpeakString("<color=yellow>Only Janine can equip this"));
		
		itemproperty ip = GetFirstItemProperty(oItem); // iterate over all IPs on 'oItem'
		while (GetIsItemPropertyValid(ip))
		{
			if (GetItemPropertyType(ip) == ITEM_PROPERTY_USE_LIMITATION_CLASS) 
			{
			RemoveItemProperty(oItem, ip);
			ip = GetFirstItemProperty(oItem); 
			}
		else ip = GetNextItemProperty(oItem);
		}
		
		MakeItemUseableByClass(CLASS_TYPE_COMMONER, oItem);
	}
}
1 Like

//i_npsw02_eq

void main()
{
object oPC = GetPCItemLastEquippedBy();
object oItem = GetPCItemLastEquipped();

//Your code goes here

if(GetTag(oPC) != "yoshim"){
	
	SendMessageToPC(GetFirstPC(FALSE),"This blade, although only lightly enchanted, has achieved a semblance of awareness, enough so that it allows only the thief known as Yoshimo to wield it.  Any other than he cannot use this flawless katana in battle.");
	DelayCommand(0.1,AssignCommand(oPC,ClearAllActions(TRUE)));
  	DelayCommand(0.2,AssignCommand(oPC,ActionUnequipItem(oItem)));

}

}

Your code here corresponds to what I did first, only that you unequip the item after, but as I said (and as you see this has already been solved, so it doesn’t matter anymore) I wanted the armor to be “red” when you have it in the PCs inventory, like I said in my first post.

I have item restrictions by tag in Bedine for the dog companions. Many items for normal creatures can’t be used by the dogs, and vice versa. Mask of the Betrayer also does item restriction for Okku.

And how is it done there then? Are the items “red” so to speak? I mean, of course I could have done it the way Shallina does it and like in my original script (even though there was a bit of code there that needed to be added) but then the items aren’t “red” when you put it into your inventory. I like the “red” thing because it becomes really clear that you can’t use the items.

Ah, what the heck. The matter has been solved. No need for an endless debate, I guess.