Alangara_PRC8/_module/nss/mn_i_util.nss
Jaysyn904 86feb9ca6f Initial commit
Initial commit.
2024-06-05 21:21:06 -04:00

279 lines
7.2 KiB
Plaintext

// Create an item, supplying a new name and description.
void CreateItem(object oTarget, string sResRef, int nStackSize=1, string sNewTag="", string sNewName="", string sNewDescription="");
// Destroy a specific item, even if plot flag is set
void DestroyItem(object oTarget);
// Remove (destroy) an item from an object, identified by a specific tag
int RemoveAllItemsByTag(object oTarget, string sTag, int bRemoveFromEquipped=FALSE);
// Remove (destroy) an item from an object, identified by a specific ResRef
int RemoveAllItemsByResRef(object oTarget, string sResref, int bRemoveFromEquipped=FALSE);
// Remove (destroy) a specific number of an object, identified by tag
int RemoveXItemsByTag(object oTarget, string sTag, int amount);
// Remove (destroy) a specific number of an object, identified by ResRef
int RemoveXItemsByResRef(object oTarget, string sResRef, int amount);
// Count number of items by tag (ignores equipped items)
int CountItemsByTag(object oTarget, string sTag);
// Count number of items by ResRef (ignores equipped items)
int CountItemsByResRef(object oTarget, string sResRef);
// Display a message to a player
void Msg(object oPC, string message, int nActionQueue = FALSE);
// Destroys all items in the inventory of the target
void RemoveAllItems(object oTarget, int bRemoveFromEquipped=FALSE);
// Sets the PCs level
void SetPCLevel(object oPC, int level);
void DestroyItem(object oTarget)
{
if (GetIsObjectValid(oTarget))
{
SetPlotFlag(oTarget,FALSE);
DestroyObject(oTarget);
}
}
void CreateItem(object oTarget, string sResRef, int nStackSize=1, string sNewTag="", string sNewName="", string sNewDescription="")
{
if (GetIsObjectValid(oTarget))
{
object oObject = CreateItemOnObject(sResRef, oTarget, nStackSize, sNewTag);
if (GetIsObjectValid(oObject))
{
SetName(oObject, sNewName);
SetDescription(oObject, sNewDescription);
}
}
}
int RemoveAllItemsByResRef(object oTarget, string sResRef, int bRemoveFromEquipped=FALSE)
{
int bRemovedItem = FALSE;
if (GetIsObjectValid(oTarget))
{
// Check general Inventory and clear it out.
object oItem = GetFirstItemInInventory(oTarget);
while(GetIsObjectValid(oItem))
{
if (GetResRef(oItem) == sResRef)
{
DestroyItem(oItem);
bRemovedItem = TRUE;
}
oItem = GetNextItemInInventory(oTarget);
}
if (bRemoveFromEquipped && (GetIsPC(oTarget) || GetObjectType(oTarget)==OBJECT_TYPE_CREATURE))
{
// Check Equip Items and get rid of them
int i;
for(i=0; i<14; i++)
{
object oEquip = GetItemInSlot(i,oTarget);
if(GetIsObjectValid(oEquip) && GetResRef(oEquip) == sResRef)
{
DestroyItem(oEquip);
bRemovedItem = TRUE;
}
}
}
}
return bRemovedItem;
}
int RemoveAllItemsByTag(object oTarget, string sTag, int bRemoveFromEquipped=FALSE)
{
int bRemovedItem = FALSE;
if (GetIsObjectValid(oTarget))
{
// Check general Inventory and clear it out.
object oItem = GetFirstItemInInventory(oTarget);
while(GetIsObjectValid(oItem))
{
if (GetTag(oItem) == sTag)
{
DestroyItem(oItem);
bRemovedItem = TRUE;
}
oItem = GetNextItemInInventory(oTarget);
}
if (bRemoveFromEquipped && (GetIsPC(oTarget) || GetObjectType(oTarget)==OBJECT_TYPE_CREATURE))
{
// Check Equip Items and get rid of them
int i;
for(i=0; i<14; i++)
{
object oEquip = GetItemInSlot(i,oTarget);
if(GetIsObjectValid(oEquip) && GetTag(oEquip) == sTag)
{
DestroyItem(oEquip);
bRemovedItem = TRUE;
}
}
}
}
return bRemovedItem;
}
void Msg(object oPC, string message, int nActionQueue = FALSE)
{
if (nActionQueue)
{
AssignCommand(oPC, ActionDoCommand(FloatingTextStringOnCreature(message, oPC, FALSE)));
}
else
{
FloatingTextStringOnCreature(message, oPC, FALSE);
}
}
void SetPCLevel(object oPC, int level)
{
if (GetIsObjectValid(oPC) && GetIsPC(oPC))
{
int nXP = ((level*(level - 1))/2)*1000;
SetXP(oPC,nXP);
}
}
void RemoveAllItems(object oTarget, int bRemoveFromEquipped=FALSE)
{
if (GetIsObjectValid(oTarget) && GetHasInventory(oTarget))
{
object oItem = GetFirstItemInInventory();
if(GetIsObjectValid(oItem))
{
while(GetIsObjectValid(oItem))
{
DestroyItem(oItem);
oItem = GetNextItemInInventory();
}
}
if (bRemoveFromEquipped && (GetIsPC(oTarget) || GetObjectType(oTarget)==OBJECT_TYPE_CREATURE))
{
// Check Equip Items and get rid of them
int i;
for(i=0; i<14; i++)
{
object oEquip = GetItemInSlot(i,oTarget);
if(GetIsObjectValid(oEquip))
{
DestroyItem(oItem);
}
}
}
}
}
int RemoveXItemsByTag(object oTarget, string sTag, int amount)
{
int bRemovedItems = FALSE;
object oItem = GetFirstItemInInventory(oTarget);
while(GetIsObjectValid(oItem) && amount > 0)
{
if (GetTag(oItem) == sTag)
{
int nStackSize = GetItemStackSize(oItem);
if (nStackSize>amount && nStackSize>1)
{
SetItemStackSize(oItem, nStackSize-amount);
amount = 0;
bRemovedItems = TRUE;
}
else
{
DestroyItem(oItem);
amount=amount-nStackSize;
bRemovedItems = TRUE;
}
}
oItem = GetNextItemInInventory(oTarget);
}
return bRemovedItems;
}
int RemoveXItemsByResRef(object oTarget, string sResRef, int amount)
{
int bRemovedItems = FALSE;
object oItem = GetFirstItemInInventory(oTarget);
while(GetIsObjectValid(oItem) && amount > 0)
{
if (GetResRef(oItem) == sResRef)
{
int nStackSize = GetItemStackSize(oItem);
if (nStackSize>amount && nStackSize>1)
{
SetItemStackSize(oItem, nStackSize-amount);
amount = 0;
bRemovedItems = TRUE;
}
else
{
DestroyItem(oItem);
amount=amount-nStackSize;
bRemovedItems = TRUE;
}
}
oItem = GetNextItemInInventory(oTarget);
}
return bRemovedItems;
}
int CountItemsByTag(object oTarget, string sTag)
{
int nNumberOfItems;
object oItem = GetFirstItemInInventory(oTarget);
while(GetIsObjectValid(oItem))
{
if (GetTag(oItem) == sTag)
{
int nStackSize = GetItemStackSize(oItem);
nNumberOfItems=nNumberOfItems+nStackSize;
}
oItem = GetNextItemInInventory(oTarget);
}
return nNumberOfItems;
}
int CountItemsByResRef(object oTarget, string sResRef)
{
int nNumberOfItems;
object oItem = GetFirstItemInInventory(oTarget);
while(GetIsObjectValid(oItem))
{
if (GetResRef(oItem) == sResRef)
{
int nStackSize = GetItemStackSize(oItem);
nNumberOfItems=nNumberOfItems+nStackSize;
}
oItem = GetNextItemInInventory(oTarget);
}
return nNumberOfItems;
}
//void main(){}