ok, this is the module level script. It allows you to restrict equipping items to companions based on tags. Thus, hypothetically we could allow Okku to wear armor made for a bear, but prevent our player from wearing it because they can't wear something made for a bear (we'd also have to adjust Okku's level up script so it doesn't remove his fighter proficiencies in addition to this script).
It also allows you to make whole categories of items that are not cursed, but only specific npcs can use, no matter how high the UMD scores of other companions, without having to write item scripts for each possible item. Instead you make pseudo categories based on tag prefixes. The most obvious example would be to have race specific armor without necessitating new baseitems entries for light/medium/heavy armor for every player race.
//::///////////////////////////////////////////////
/*
This module player equip script uses modified code from MoTB for handling Okku and the other companions who can't equip all item slots in order to
allow for groups of restricted items without needing to write equip scripts for each item individually.
this allows you to make your own item categories, such as gnome specific armor that no other race can wear no matter what their UMD skill is.
*/
//:://////////////////////////////////////////////
#include "x2_inc_switches"
// #include "x2_inc_intweapon" //necessary for intelligent weapons
#include "ginc_item"
const int STR_REF_NOT_ALLOWED = 210757;
void main()
{
object oItem = GetPCItemLastEquipped();
object oPC = GetPCItemLastEquippedBy();
int bEquipForbidden = FALSE;
// here's where we handle companions who are restricted from wearing items in given slots, for instance no usable off arm slot for a one armed companion
string sTag = GetTag(oPC);
if ((sTag == "companion_1")
|| (sTag == "companion_2")
|| (sTag == "companion_3"))
{
int nSlot = GetSlotOfEquippedItem(oItem, oPC);
// for creatures like Okku where all non-creature items forbidden by default, Okku can never weild a weapon
//you would leave this in to block a creature from equipping in any non creature slot
if (!GetIsCreatureSlot(nSlot))
{
// bEquipForbidden = TRUE;
}
// Now for slot based exceptions, for instance Okku is allowed to wear rings and amulets, so for our hypothetical one armed companion we would
//block INVENTORY_SLOT_LEFTHAND
//forbidden = False means it's allowed.
if ( (sTag == "companion_1")
|| (sTag == "companion_2")
|| (sTag == "companion_3"))
{
if ((nSlot == INVENTORY_SLOT_NECK)
|| (nSlot == INVENTORY_SLOT_LEFTRING)
|| (nSlot == INVENTORY_SLOT_RIGHTRING))
{
bEquipForbidden = FALSE;
}
}
}
// by default this will never be happen in this example as we've commented out above the only condition where it can be set to true.
// But we could add conditions as we like.
// in this case, the creature can not wear any items other than in the specified slots.
if (bEquipForbidden == TRUE)
{
AssignCommand(oPC, ActionUnequipItem(oItem));
SendMessageToPCByStrRef(oPC, STR_REF_NOT_ALLOWED);
return;
}
// tag based scripting :-)
if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
{
SetUserDefinedItemEventNumber(X2_ITEM_EVENT_EQUIP);
int nRet = ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
if (nRet == X2_EXECUTE_SCRIPT_END)
{
return;
}
/*
new stuff, we are going to use tag based scripts to make race specific armor and enforce it, no :"use magical device" exception. kamal
we want our companions like to be restricted to armor made specifically for them, and no humanoids to be able to wear it
likewise, Okku can't wear people armor
*/
string sTag = GetTag (oItem);
int nAppearance = GetAppearanceType(oPC);
SendMessageToPC (GetFirstPC(FALSE), "nAppearance is " +IntToString(nAppearance));
if (nAppearance == 12) //we could add other appearances here, maybe dire bears or something
{
// 181 is bear_black, while technically this is available as appearance_type_bear_black, using the number shows emphasizes we
// need to look at the nwn2 appearances.2da since a lot of the appearance_type_ globals are nwn1 leftovers
if (FindSubString(sTag, "bd_bearitem_") == -1)
{
AssignCommand(oPC, ActionUnequipItem(oItem));
SendMessageToPCByStrRef(oPC, STR_REF_NOT_ALLOWED);
return;
}
}
else //if you wanted to have multiple different restrictions by appearance type, you could do else if's as above, however you'd else with this else
{
if (FindSubString(sTag, "bd_bearitem_") != -1)
{
AssignCommand(oPC, ActionUnequipItem(oItem));
SendMessageToPCByStrRef(oPC, STR_REF_NOT_ALLOWED);
return;
}
}
}
ExecuteScript("x2_mod_def_equ", OBJECT_SELF);
}
DM : I don't care what your UMD score is gnome, you can't wear armor made for a bear.