Ondeath Script

Hello, I need one of the amazing scripter here to write a script. I have working knowledge, but writing from scratch is not in my wheel house. I also do not know what is and is not possible.

The idea is for when a creature is killed, the script checks how many PCs are in the party of the creature’s killer and then gives an item to all the PC characters in that party who are also in the area at the time of the creature’s death.

-On death get last attacker
-if last attacker was a summon, get the PC owner of that summon
-check for number of PC characters in the party of the PC killer
-check for number of PC characters in the area of the killed creature(probably a waypoint tag placed in the area of the encounter trigger)
-give an item to the number of PC that pass the two criteria, all other PCs that fail do nothing.

Then at the end, I will execute a script that I use for XP.

If anyone is up to the task, I would be grateful.

1 Like

No idea about the script I’m rubbish at them but would it be easier to check the number of people in the party before the fight and create that amount of objects on the creature or in a chest which the creature has the key to ?

1 Like

Easier, maybe, but would that be robust enough for what I am wanting to do?

Another thing to consider is that if you don’t know who is in the party you might hit an issue with giving them things unless there’s some sort of one each function.

Here’s what I would try and do without a script, forget the counting, creature dies, you find a key that opens the creature’s stash, open the chest, conversation starts about loot, during the conversation it’s decided that everybody that killed the creature gets one “souvenir”.

The conversation editor has a gc_is in party condition, use that to give ( ga_give item ) that party member their prize if they’re not there move on to the next one. You can even put the conversation on death of the creature if it’s body parts you’re hacking off.

1 Like
/*
	Place on the creature's OnDeath event.
	Gives every non-associate party member in the area an item upon death of OBJECT_SELF.	
*/

void main()
{
	object oKiller = GetLastKiller();
	object oFM = GetFirstFactionMember(oKiller, FALSE);
	
	while (GetIsObjectValid(oFM))
	{
		if (!GetAssociateType(oFM) && (GetArea(oKiller) == GetArea(oFM)))
		{
			CreateItemOnObject("item_resref", oFM);	// <-- put your item's resref here
		}
		
		oFM = GetNextFactionMember(oKiller, FALSE);
	}
}
3 Likes

clarification? Should that include companions, or only true player-owned characters …?

2 Likes

The item goes to the Players only. There are no companions in my mod.

Thank you, I’ll implement and test it out.

1 Like

I have implemented something simpler for other systems and situations.

I have a chest with a onopen script that checks PC inventory for the specific item tag I want to give, and if it doesn’t find the item, it gives the item to the PC. The script will run whenever a PC Character opens the chest. So the whole party can open the chest and get the item. No need for a dialog.

But I wanted something different here. I want the item to automatically appear in the Characters inventory after the creature is killed.

1 Like

@kevL_s @travus - Travus’ script includes companions if I’m not mistaken?

As I’ve never played multiplayer on NWN2, I’m a bit curious how it works with different PCs in a party. They can be part of the party too, I assume?

riffing off @travus

/*
	Place on the creature's OnDeath event.

	Gives every Owned character in the killer's party (in the area) an
	item upon death of OBJECT_SELF.	
*/

void main()
{
	object oKiller = GetLastKiller();
	if (GetIsObjectValid(GetFactionLeader(oKiller))) // check if killer is party-faction
	{
		object oArea = GetArea(oKiller);

		// 'bPCOnly=TRUE' arg in GetFirst/NextFactionMember() cycles over Owned chars only (iirc)
		// - there are other ways to do this if 'bPCOnly' means player-controlled ...
		object oFM = GetFirstFactionMember(oKiller);
		while (GetIsObjectValid(oFM))
		{
			if (GetArea(oFM) == oArea)
			{
				CreateItemOnObject("item_resref", oFM);	// <-- put your item's resref here
			}
			oFM = GetNextFactionMember(oKiller);
		}
	}
}

 
suggested test: If a wizard is controlling its familiar, does the familiar get the item, or the wizard ?

Tested it with multiple player characters at same time, and one of those players was controlling their familiar. The item only went to the player characters regardless of whether controlling their familiar or not.

Does a familiar actually have an inventory?

2 Likes

I believe that an inventory is integral to the definition of all creature-objects.

so, yes …

Yes, they have to have an inventory for their bites, claws and skins but I don’t know how you’re supposed to get anything off the little sods if you give it to them !

                WANTED

           FOR THEFT OF LOOT 

:bat::wolf::bear::spider::rat::cat2::pig::rabbit:

       IF YOU SEE THESE CREATURES
          GIVE THEM NOTHING !

Note to self… Go and do something productive you’re losing the plot !

3 Likes

CLOSE YER EYES, TSONGO, CLOSE YER EYES !

those are actually equipped items, not in the inventory-container per se

write a console script … or fashion up a gui with inventory-manipulation operations …

1 Like

:dark_sunglasses:

1 Like

@kevL_s

Unless I missed an edit, where @travus uses the following function …

!GetAssociateType(oFM)

… then only proper PCs will receive the item (unless “dominated”). That is, no “normal associates” (henchmen, familiars, animal comps or summons) will be included in the loop of the killer’s faction members. However, this would give the item to “companions” if present (due to the FALSE parameter, but only if they were present in the mod anyway).

Although, I believe the script might fail to give any item if the last killer was from another faction other than a party member. :thinking: E.g. It somehow died from AoE effect, perhaps? I believe I recall some weird event that failed to trigger a similar script I had when doing something like this once.

If the builder wants the item to go to the party members present (no matter the final killer of said creature), then I think I’d play it safe and just grab the First PC and cycle though them to give the item to. (Maybe add a condition to ensure a player was not a DM if possibly present.)

So, something like this …

On creature’s OnDeath Event Hook

//////////////////////////////////////////////////////////////////////////////////
// JUST GIVES AN ITEM TO EVERY PLAYER (EXCEPT ANY DM PRESENT) WHEN CREATURE KILLED
// ASSUMES THAT THE PLAYER IS NOT CONTROLLING A COMPANION, ALTHOUGH ANY PLAYER PC
// IN THE AREA WOULD RECEIVE THE ITEM ANYWAY IF THEY WERE.
//////////////////////////////////////////////////////////////////////////////////

void main()
{
	object oPC = GetFirstPC(TRUE);
	
	object oArea = GetArea(OBJECT_SELF);
	
	while (oPC != OBJECT_INVALID)
	{
		if (GetArea(oPC) == oArea && !GetIsDM(oPC))
		{
			CreateItemOnObject("item_resref", oPC);	// <-- put your item's resref here
		}
		
		oPC = GetNextPC(TRUE);
	}	
}
2 Likes

… as long as they are a member of the killer’s party.

I’d be tempted to use GetFirst/NextPC() also, but am unsure what happens if Owned chars are not currently grouped … (hence get first/next factionmember)

 
and i put this line in →

	if (GetIsObjectValid(GetFactionLeader(oKiller))) // check if killer is party-faction

As you suggest it could evaluate to FALSE rather unexpectedly. It could be difficult to ensure that the critter is killed by a partymember, or as the result of a partymember’s actions … so it might be best to take that check out, depends on @MagicalWisps intentions … and, what does GetLastKiller() really return ?

1 Like

@kevL_s

It depends upon how the OP has the module setup to handle parties. It’s not clear on the game setup. It sounds like a potential MP setup, allowing a few players to join to make a single party, but … :thinking:

If there is only a single party, then the GetFirstPC should be fine. More than one party, then we need to go back to the faction member function and checks. :slightly_smiling_face:

Struggling to sleep, but going to try again now… Catch you later. :+1::zzz:

ah okay,

later Lance

1 Like