Help with fucntion/script

I don’t get it. I have an custom armor that the PC can buy. If a different companions wear it I wanted different properties added. So I found the function AddItemProperty, but somehow I write the script wrong since it won’t compile. I don’t really understand it. Can you help me? It looks something like this:

// 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 oMarcus = GetObjectByTag("marcus");
	
	if(oPC == oMarcus)
	{
		AddItemProperty(DURATION_TYPE_PERMANENT,IP_CONST_FEAT_ALERTNESS,oItem);
	}	
	

	
}

I don’t think I understand how this function is supposed to be written.

Hmm. I think I might have been able to solve it:

// 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 oMarcus = GetObjectByTag("marcus");
	
	if(oPC == oMarcus)
	{
		AddItemProperty(DURATION_TYPE_PERMANENT,ItemPropertyAttackBonus(5),oItem);
	}	
	

	
}

Yes, you are adding an “item property” property. :slight_smile:

However, you will need to remove the property if you want the same armour to no longer have the property if someone else uses it instead (after Marcus has worn it).

You may be better adding/removing any properties via the acquire/unacquire hook instead.

Cheers, Lance.

It may be overkill for what you need, but here is my function/script for what I call “levelling items” in The Scroll. It is module specific, so just look at it as an example.:-

////////////////////////////////////////////////////////////////////////////////
// ITEM UPGRADE SCRIPT - IMPROVE WITH THE PC
// MUST RECOMPILE AFTER ALTERING THIS SCRIPT !!!!
////////////////////////////////////////////////////////////////////////////////

#include "x2_inc_itemprop"

void SetLevelItem(object oPC, object oItem, int InformPlayer = 0)
{	
	string sTag = GetTag(oItem); // "alb_lvl_"
	
	if(GetStringLeft(sTag, 8) == "alb_lvl_")
	{	
		// CURRENT ITEM VALUE
		int iCURRENT = GetLocalInt(oItem, "LEVELITEMVALUE");		
		if(iCURRENT == 0){iCURRENT = 1;}
		
		// THE UPGRADE IMPROVEMENT VALUE
		int iNEWVALUE = 1 + GetTotalLevels(oPC, FALSE)/4;
		
		////////////////////////////////////////////////////////////////////////////////
		// ONLY APPLY IF DIFFERENT FROM CURRENT SETTING
		////////////////////////////////////////////////////////////////////////////////
		
		if(iCURRENT != iNEWVALUE)
		{		
			// FIND OUT WHICH CHANGES ARE REQUIRED FOR ITEM & REMOVE ANY EXISTING
			string sBONUSTYPE = "WEAPON"; 
			itemproperty ipProperty = ItemPropertyEnhancementBonus(iNEWVALUE);
			
			itemproperty ipLoop = GetFirstItemProperty(oItem);
						
			while (GetIsItemPropertyValid(ipLoop))
			{
				// WEAPON ENHANCEMENT UPGRADE REQUIRED
				if(GetItemPropertyType(ipLoop) == ITEM_PROPERTY_ENHANCEMENT_BONUS)
				{RemoveItemProperty(oItem, ipLoop); break;}
				
				// ARMOUR AC BONUS UPGRADE REQUIRED
				else if(GetItemPropertyType(ipLoop) == ITEM_PROPERTY_AC_BONUS)
				{RemoveItemProperty(oItem, ipLoop); sBONUSTYPE = "ARMOUR"; break;}
				
			   	ipLoop = GetNextItemProperty(oItem);
			}
			
			////////////////////////////////////////////////////////////////////////////////
			// WEAPON ENHANCEMENT DEFAULT ELSE ARMOUR AC BONUS
			////////////////////////////////////////////////////////////////////////////////
			
			if(sBONUSTYPE == "ARMOUR"){ipProperty = ItemPropertyACBonus(iNEWVALUE);}
					
			AddItemProperty(DURATION_TYPE_PERMANENT, ipProperty, oItem);		
			
			////////////////////////////////////////////////////////////////////////////////
			// FEEDBACK FOR LEVEL CHANGES ON LEVELLING PCS 
			////////////////////////////////////////////////////////////////////////////////
			
			// ALLOW DESCRIPTION UPDATE
			DeleteLocalString(oItem, "ITEMDECS");			
			
			string sNAME = GetStringUpperCase(GetName(oItem));
			
			if(iNEWVALUE > iCURRENT)
			{			
				SetNoticeText(oPC, "<<< EQUIPPED ITEM LEVEL IMPROVEMENT >>>");
				SendMessageToPC(oPC, "EQUIPPED ITEM LEVEL IMPROVED: " + sNAME);
			}
			
			else if(iNEWVALUE < iCURRENT)
			{			
				SetNoticeText(oPC, "<<< EQUIPPED ITEM LEVEL DEGRADED >>>");
				SendMessageToPC(oPC, "EQUIPPED ITEM LEVEL DEGRADED: " + sNAME);
			}
			
			////////////////////////////////////////////////////////////////////////////////
			// STORE NEW VALUE
			////////////////////////////////////////////////////////////////////////////////
			
			SetLocalInt(oItem, "LEVELITEMVALUE", iNEWVALUE);
		}
	}

}

Thanks so much for the reply, Lance! After it turned out I can change the looks of cloaks, I will use that instead for what I need. It’s so much easier. And you’re right, I realize I have to remove properties I’ve added if I were to put the same cloak on other characters. The script will get a bit complicated (or maybe just a lot to write) if I’m to do that even if it’s doable.

I’ll have in mind to use something like your script via the acquire/unaquire instead, if I go back to using this thing instead of the cloaks. Again, thanks for all the help! I greatly appreciate all the advice you give, and that you answer so many of my questions!

1 Like