Stealing item script

I found a stealing script used in the OC;


// 11_a_stealing
/*
	Give the player chaos points if they steal from the object this script is attached to.
*/
// JYL 03/16/06

#include "ginc_misc"
	
void main()
{
	object oTarget = GetLastDisturbed();
	object oArea = GetArea(OBJECT_SELF);
	string sName = GetName(oTarget);
	
	object oItem = GetModuleItemAcquired();


	if (GetLocalInt(oArea, sName) != 1)
	{
		AdjustAlignment(oTarget, ALIGNMENT_CHAOTIC, 1);
		AdjustAlignment(oTarget, ALIGNMENT_EVIL, 1);
		SetLocalInt(oArea, sName, 1);
	}
	//what I added;
		while ( GetModuleItemAcquired() != ""); //cycle all items looted
		{
		
			SetStolenFlag(oItem, 1); //flag looted item as stolen
		
		}
		
}

Apart from alignment change, I want to add a loop to flag every item looted from the container with Stolen flag.

Did I get it right?
Or should I use getfirstitem, getnextitem to cycle the container’s inventory and flag every item?

that looks like a container’s OnDisturbed script

( it’d probly be better to set all contents stolen in the OnOpen but it could work here also )

there’s some code probs there…

GetModuleItemAcquired() returns an object, but it’s being compared against a string. objects can be compared only against objects, and/or strings against strings.

and yep that’s an infinite loop (if it could compile…). The basics of a loop go like this: First you want to set a variable. Then compare that variable against something (of the same type). Then do something to the variable while inside the loop, so that the condition gets tested again (and hence should end at some value of said variable).

object oItemInContainer = GetFirstItemInInventory(OBJECT_SELF);

// this is testing 'oItemInContainer' against 'OBJECT_INVALID' -
// they are the same type, but not necessarily the same value.
while (GetIsObjectValid(oItemInContainer))
{
    SetStolenFlag(oItemInContainer, TRUE);

    // this will change the value of 'oItemInContainer' to OBJECT_INVALID
    // when there are no more items in the container to iterate over.
    oItemInContainer = GetNextItemInInventory(OBJECT_SELF);
}

and, since the item that was picked out of the container is (probably) not in the container anymore, set it to stolen also:

SetStolenFlag(GetInventoryDisturbItem(), TRUE);

This script isn’t used in the OC (it isn’t attached to any object). If you want to set a Stolen flag on the looted items use the OnAcquire module script.

Something like this…

<game root folder>\Campaigns\Neverwinter Nights 2 Campaign\k_mod_acquire.nss:

// k_mod_acquire
/*
	Module acquire item script
	gets the tag of the item and calls:
	"i_<tag>_aq"
*/
// ChazM 3/1/05
// BMA-OEI 9/26/05
// ChazM 10/20/05 - hook back in to the x2_mod_def* script

//#include "ginc_debug"

void main()
{
	ExecuteScript("x2_mod_def_aqu", OBJECT_SELF);

	object oPC      = GetModuleItemAcquiredBy();
	object oTarget  = GetModuleItemAcquiredFrom();
	object oItem    = GetModuleItemAcquired();

	if (GetObjectType(oTarget) == OBJECT_TYPE_CREATURE
	&& !GetIsEnemy(oTarget) && !GetIsDead(oTarget) && !GetFactionEqual(oTarget, GetFirstPC()))
	{
		object oArea = GetArea(oTarget);
		string sName = ObjectToString(oTarget);

		if (!GetLocalInt(oArea, sName))
		{
			SetLocalInt(oArea, sName, TRUE);

			AdjustAlignment(oPC, ALIGNMENT_CHAOTIC, 1);
			AdjustAlignment(oPC, ALIGNMENT_EVIL, 1);

			SetStolenFlag(oItem, TRUE);

			object oItemInContainer = GetFirstItemInInventory(oTarget);
			while (GetIsObjectValid(oItemInContainer))
			{
				SetStolenFlag(oItemInContainer, TRUE);
				oItemInContainer = GetNextItemInInventory(oTarget);
			}
		}
	}
}

Sorry, it checks only creatures.

Is the K mod script for every item acquired? I do not want to flag every single acquired item.
Cleaned up.


// 11_a_stealing
/*
	Give the player chaos points if they steal from the object this script is attached to.
*/
// JYL 03/16/06

#include "ginc_misc"
	
void main()
{
	object oTarget = GetLastDisturbed();
	object oArea = GetArea(OBJECT_SELF);
	string sName = GetName(oTarget);
	
	object oItem = GetFirstItemInInventory(OBJECT_SELF); //picks up first item in called object - the container


	if (GetLocalInt(oArea, sName) != 1)
	{
		AdjustAlignment(oTarget, ALIGNMENT_CHAOTIC, 1);
		AdjustAlignment(oTarget, ALIGNMENT_EVIL, 1);
		SetLocalInt(oArea, sName, 1);
		
		while ( GetIsObjectValid(oItem)); //cycle all items looted, goes into the align change function
		{
			SendMessageToPC(GetFirstPC(),"You thief you"); // XD
			SetStolenFlag(oItem, TRUE); //flag looted item as stolen
			oItem = GetNextItemInInventory(OBJECT_SELF); // move to next object
		
		}
	}
	SendMessageToPC(GetFirstPC(),"Pillager!"); // XD
	SetStolenFlag(GetInventoryDisturbItem(), TRUE); //since the item that was picked out of the container is (probably) not in the container anymore, set it to stolen also:
		
}

I remember seeing align changes while rifling one of the houses in West Harbor, or its just my imagination. Anyway i’ll try it again.


// 11_a_stealing
/*
	Give the player chaos points if they steal from the object this script is attached to.
*/
// JYL 03/16/06

#include "ginc_misc"
	
void main()
{
	object oTarget = GetLastDisturbed();
	object oArea = GetArea(OBJECT_SELF);
	string sName = GetName(oTarget);
	
	object oItem = GetFirstItemInInventory(OBJECT_SELF); //picks up first item in called object - the container


	if (GetLocalInt(oArea, sName) != 1)
	{
		AdjustAlignment(oTarget, ALIGNMENT_CHAOTIC, 2);
		AdjustAlignment(oTarget, ALIGNMENT_EVIL, 2);
		SetLocalInt(oArea, sName, 1);
		
		while ( GetIsObjectValid(oItem)) //cycle all items looted, goes into the align change function
		{
			SendMessageToPC(GetFirstPC(),"You thief you"); // XD
			SetStolenFlag(oItem, TRUE); //flag looted item as stolen
			oItem = GetNextItemInInventory(OBJECT_SELF); // move to next object
		
		}
	}
	SendMessageToPC(GetFirstPC(),"Pillager!"); // XD
	SetStolenFlag(GetInventoryDisturbItem(), TRUE); //since the item that was picked out of the container is (probably) not in the container anymore, set it to stolen also:
		
}

the while loop will not fire if you use loot all button… perhaps putting it in onopen is better…