Another script not working

I made a script I thought would work, but it doesn’t seem to work. I want to check the entire party if someone has the spell Dispel Magic:

#include "ginc_var_ops"
#include "ginc_param_const"

int ItemsValid()
{
	 
   int bHasDispel = FALSE;
   object oPC = GetFirstPC();

   string sTag;
   
   	object oFM = GetFirstFactionMember(oPC,FALSE);

	while(GetIsObjectValid(oFM))
	{

   		object oItem = GetFirstItemInInventory();
    	while (GetIsObjectValid(oItem))
    	{
        	sTag = GetTag(oItem);
        	if (sTag == "nw_it_sparscr301")
        	{
             bHasDispel = TRUE;
        	}

        oItem = GetNextItemInInventory();
    	}
		
		oFM = GetNextFactionMember(oPC, FALSE);
	}

	if(bHasDispel)
	{
		return TRUE;
	}
	
	return FALSE;
}




int HasTheSpell()
{

	object oPC = GetFirstPC();
	int bHasSpell = FALSE;
	object oFM = GetFirstFactionMember(oPC,FALSE);

	while(GetIsObjectValid(oFM))
	{
	
		if(GetHasSpell(SPELL_DISPEL_MAGIC,oFM))
		{
			
			bHasSpell = TRUE;
			DecrementRemainingSpellUses(oFM, SPELL_DISPEL_MAGIC);
			
		}
		
		oFM = GetNextFactionMember(oPC, FALSE);
	}
	
	if(bHasSpell)
	{
		return TRUE;
	}
	
	return FALSE;

}


int StartingConditional()
{

	if(HasTheSpell() || ItemsValid())
	{
	
		 return TRUE;
	
	}
	
	return FALSE;

}

EDIT: So I modified the script with GetFirstPC(FALSE) and now it works if one of the characters have the spell as a spell slot, but if I pick up a scroll with Dispel Magic the script won’t recognize that. At first I thought it had to do with the tag being wrong but I corrected it and it still won’t recognize if you have the scroll in your inventory:

int ItemsValid()
{
	 
   int bHasDispel = FALSE;
   object oPC = GetFirstPC(FALSE);

   string sTag;
   
   	object oFM = GetFirstFactionMember(oPC,FALSE);

	while(GetIsObjectValid(oFM))
	{

   		object oItem = GetFirstItemInInventory();
    	while (GetIsObjectValid(oItem))
    	{
        	sTag = GetTag(oItem);
        	if (sTag == "NW_IT_SPARSCR301")
        	{
             bHasDispel = TRUE;
        	}

        oItem = GetNextItemInInventory();
    	}
		
		oFM = GetNextFactionMember(oPC, FALSE);
	}

	if(bHasDispel)
	{
		return TRUE;
	}
	
	return FALSE;
}




int HasTheSpell()
{

	object oPC = GetFirstPC(FALSE);
	int bHasSpell = FALSE;
	object oFM = GetFirstFactionMember(oPC,FALSE);

	while(GetIsObjectValid(oFM))
	{
	
		if(GetHasSpell(SPELL_DISPEL_MAGIC,oFM))
		{
			
			bHasSpell = TRUE;
			DecrementRemainingSpellUses(oFM, SPELL_DISPEL_MAGIC);
			
		}
		
		oFM = GetNextFactionMember(oPC, FALSE);
	}
	
	if(bHasSpell)
	{
		return TRUE;
	}
	
	return FALSE;

}


int StartingConditional()
{

	if(HasTheSpell()) return TRUE;
	else if(ItemsValid()) return TRUE;
	

	
	return FALSE;

}

I managed to solve it by rewriting the script like this. Don’t know why the other version didn’t work though:

#include "ginc_var_ops"
#include "ginc_param_const"

int ItemsValid()
{
	 
 
   object oPC = GetFirstPC(FALSE);
   object oFM = GetFirstFactionMember(oPC,FALSE);

	int bHasDispel = FALSE;
	
	while(GetIsObjectValid(oFM))
	{
		if (GetIsObjectValid(GetItemPossessedBy(oFM,"NW_IT_SPARSCR301")))
		{
			bHasDispel = TRUE;
		}	
		oFM = GetNextFactionMember(oPC, FALSE);
	}
	

	if(bHasDispel)
	{
		return TRUE;
	}
	
	return FALSE;
}




int HasTheSpell()
{

	object oPC = GetFirstPC(FALSE);
	int bHasSpell = FALSE;
	object oFM = GetFirstFactionMember(oPC,FALSE);

	while(GetIsObjectValid(oFM))
	{
	
		if(GetHasSpell(SPELL_DISPEL_MAGIC,oFM))
		{
			
			bHasSpell = TRUE;
			DecrementRemainingSpellUses(oFM, SPELL_DISPEL_MAGIC);
			
		}
		
		oFM = GetNextFactionMember(oPC, FALSE);
	}
	
	if(bHasSpell)
	{
		return TRUE;
	}
	
	return FALSE;

}


int StartingConditional()
{

	if(HasTheSpell()) return TRUE;
	else if(ItemsValid()) return TRUE;
	

	
	return FALSE;

}
1 Like

I believe it is because you were checking the inventory items of OBJECT_SELF and not the FM.

CHANGE object oItem = GetFirstItemInInventory(); TO

object oItem = GetFirstItemInInventory(oFM);

also do in oItem = GetNextItemInInventory(oFM);

2 Likes

Doh! What a stupid mistake of mine. Thanks for pointing it out.