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

157 lines
5.7 KiB
Plaintext

// Cloak Exchanger Script
// By: Rose
// Date: December 13, 2015
#include "prc_x2_itemprop"
void RoseCopyProps(object oOld, object oNew)
{
if (GetIsObjectValid(oOld) && GetIsObjectValid(oNew))
{
itemproperty ip = GetFirstItemProperty(oOld);
while (GetIsItemPropertyValid(ip))
{
AddItemProperty(DURATION_TYPE_PERMANENT,ip,oNew);
ip = GetNextItemProperty(oOld);
}
}
}
object MyDyeArmor(object oItem, int nColorType, int nColor)
{
object oRet = CopyItemAndModify(oItem,ITEM_APPR_TYPE_ARMOR_COLOR,nColorType,nColor,TRUE);
if (GetIsObjectValid(oRet))
DestroyObject(oItem); // remove old item
else
oRet = oItem; // failed, just return the original
return oRet; //return new item
}
void main()
{
object oPC = GetLastUsedBy();
object oCloak = GetItemInSlot(INVENTORY_SLOT_CLOAK,oPC);
// Comment this section out if using an item instead of a placeable
PlaySound("as_sw_lever1");
ActionPlayAnimation (ANIMATION_PLACEABLE_ACTIVATE);
ActionPlayAnimation (ANIMATION_PLACEABLE_DEACTIVATE);
// if cloak in cloak slot
if (GetIsObjectValid(oCloak) && GetIsObjectValid(oPC))
{
string sResRef = GetResRef(oCloak);
string sName = GetName(oCloak);
string sTag = GetTag(oCloak);
string sNewResRef;
int iModelNum;
int iColor;
int iWingType;
int iMaxModelNum = 124;
int iMinModelNum = 0;
// If we have a resref.
if (sResRef != "")
{
// Instance the invisible IP work container
object oContainer = IPGetIPWorkContainer();
// Build the new ResRef
if (GetStringLeft(sResRef,9) != "basecloak")
sNewResRef = "basecloak00" + IntToString(iMinModelNum);
else
{
iModelNum = StringToInt(GetStringRight(sResRef,3)) + 1;
if (iModelNum < iMinModelNum || iModelNum > iMaxModelNum)
iModelNum = iMinModelNum;
if (iModelNum < 10)
sNewResRef = "basecloak00" + IntToString(iModelNum);
else if (iModelNum < 100 && iModelNum > 9)
sNewResRef = "basecloak0" + IntToString(iModelNum);
else
sNewResRef = "basecloak" + IntToString(iModelNum);
}
// Create new cloak template in invisible container
object oNew = CreateItemOnObject (sNewResRef,oContainer);
if (GetIsObjectValid(oNew))
{
SendMessageToPC(oPC,"New Appearance will be " + GetName(oNew) + "");
// remove all permanent item properties present on the template cloak
// Base Cloaks don't have properties but just in case...
IPRemoveAllItemProperties(oNew,DURATION_TYPE_PERMANENT);
// instead, add the item properties from the current cloak
RoseCopyProps(oCloak,oNew);
// sync colors from old cloak
iColor = GetItemAppearance(oCloak, ITEM_APPR_TYPE_ARMOR_COLOR, ITEM_APPR_ARMOR_COLOR_LEATHER1);
oNew = MyDyeArmor(oNew, ITEM_APPR_ARMOR_COLOR_LEATHER1, iColor);
iColor = GetItemAppearance(oCloak, ITEM_APPR_TYPE_ARMOR_COLOR, ITEM_APPR_ARMOR_COLOR_LEATHER2);
oNew = MyDyeArmor(oNew, ITEM_APPR_ARMOR_COLOR_LEATHER2, iColor);
iColor = GetItemAppearance(oCloak, ITEM_APPR_TYPE_ARMOR_COLOR, ITEM_APPR_ARMOR_COLOR_CLOTH1);
oNew = MyDyeArmor(oNew, ITEM_APPR_ARMOR_COLOR_CLOTH1, iColor);
iColor = GetItemAppearance(oCloak, ITEM_APPR_TYPE_ARMOR_COLOR, ITEM_APPR_ARMOR_COLOR_CLOTH2);
oNew = MyDyeArmor(oNew, ITEM_APPR_ARMOR_COLOR_CLOTH2, iColor);
iColor = GetItemAppearance(oCloak, ITEM_APPR_TYPE_ARMOR_COLOR, ITEM_APPR_ARMOR_COLOR_METAL1);
oNew = MyDyeArmor(oNew, ITEM_APPR_ARMOR_COLOR_METAL1, iColor);
iColor = GetItemAppearance(oCloak, ITEM_APPR_TYPE_ARMOR_COLOR, ITEM_APPR_ARMOR_COLOR_METAL2);
oNew = MyDyeArmor(oNew, ITEM_APPR_ARMOR_COLOR_METAL2, iColor);
// sync other properties
SetName(oNew,sName);
SetIdentified(oNew,GetIdentified(oCloak));
SetPlotFlag(oNew,GetPlotFlag(oCloak));
SetStolenFlag(oNew,GetStolenFlag(oCloak));
SetItemCursedFlag(oNew,GetItemCursedFlag(oCloak));
SetDroppableFlag(oNew,GetDroppableFlag(oCloak));
SetItemCharges(oNew, GetItemCharges(oCloak));
// create a copy of the new cloak on the player
// Change from CopyItem to copy object so we can set the tag at the same time
// object oNewCloak = CopyItem(oNew, oPC, TRUE);
object oNewCloak = CopyObject(oNew, GetLocation(oPC), oPC, sTag);
// destroy the old cloak
DestroyObject(oCloak);
// destroy the copy template to prevent cluttingring up the item property container
DestroyObject(oNew);
// force player to equip new cloak.
// Put in a pause in case the pc has wings
// There seems to be some sort of bug where the wings disappear if you exchange too quickly
AssignCommand(oPC,ClearAllActions(TRUE));
DelayCommand(1.00,AssignCommand(oPC,ActionEquipItem(oNewCloak, INVENTORY_SLOT_CLOAK)));
}
else
{
SendMessageToPC(oPC,"Failed to create item with resref " + sResRef + ".");
return;
}
}
else
{
// error message, we need a resref to update the cloak, if no resref exist, we can't do that.
SendMessageToPC(oPC,"Could not convert " + GetName (oCloak) + ", this can only be done by the module author.");
return;
}
}
else
{
// Inform player of no cloak present
SendMessageToPC(oPC,"You must equip the cloak you want to change.");
}
}