Ondeath Script

this is what first occured to me →

void main()
{
	object oKiller = GetLastKiller();
	object oArea = GetArea(OBJECT_SELF);

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

@kevL_s

I’m still a little nervous about relying on the GetLastKiller function to return a valid party member PC.

While it works most of the time, I believe I experienced it to not return a valid party member on the odd occasion. I’d have to recheck, but it may have been related to such things as if a damage over time spell or a friendly NPC got the final blow, for example.

It all depends on the circumstances of where and how the combat results in the creature’s death with respect to how many party factions are potentially involved. :thinking:

Exactly. :+1:

Basically, The party size is unlimited and the level range can be any 1-30 grouped together. As for the purpose, I need to give an intangible item to the player.

The players are stuck in a mind prison where they have to kill 3 creatures to obtain lost memories. I do not want the memories to drop to the ground into a loot bag or corpse or chest. I need the item to appear into the inventory of the PC character. There are many ways I could do this with spawning in placeables, journal entries, and dialogs, but I want simplicity, and a script on death seems to be the simplest method IMO.

So You need a way to give the player the item when a creature is killed.
Getlastkiller makes sense to me, but I am fully ignorant of the vast function library that exist in NWNscript.

Find out who killed the creature(Must be a PC), give the item to all members of that PC’s faction(Which I assume means Party members who are PC only)

I have encountered times over the years when the combat log has said “someone damages …” In this case the getlastkiller may try to find that someone. Who may or may not exist.

1 Like

@MagicalWisps

I think I ought to clear up some terminology here, as NWN2 handles parties, PCs, companions/cohorts, associates and even players differently.

1) NUMBER OF PARTIES

a) In a MP game, you can allow more than one party, where a number of players may form their own parties and own factions. (A PW approach.)

b) In a MP game, a module may restrict to a SINGLE PARTY (this is what I do), so no matter how many players join the game, they are all part of the same single party. (A MP Coop approach.)

c) In a SP game, there is only ever one party.

d) The PARTY SIZE is limited by the server settings. Therefore, you cannot, as you say, have a party size that is “unlimited”. Imagine a party size of 100, that would mean 100 portraits on the side.

2) PLAYER vs PCs v COMPANIONS

a) In a MP game, you can have as many players as your server can support, up to a maximum of ? … I don’t run a Persistent World server, so I don’t know what the maximum can be. However, I do run a MP campaign that limits the game to a SINGLE PARTY, which I allow up to four players. However, I allow up to six PCs in the SINGLE PARTY.

b) A player can often switch between their main PC (which they joined the game with), and/or any companions or cohorts they have had join their PARTY faction. If this is a SP game, then you will have a SINGLE player, with a SINGLE PLAYER FACTION, of which the player can have join as many cohorts (self made PCs), or companions (found in your world), as you allow.

c) Furthermore, you also have associates for every PC, such as familiars, animal companions, summons and henchmen.

3) YOUR SETUP: SP or MP Questions

To clarify your requirements, we need to know the following:-

a) Is this a SP or a MP module/campaign?

b) Are you allowing the player to add more PCs (cohorts) or find companions (from your world), to join this PARTY?

MY GUESS: I am guessing that you mean to design for a SP game only, and you will need to know what limit you are setting fro the party size for that single player. However, correct me if I have that wrong.

c) You say, “players are stuck”, but do you mean PCs? For when you say “players” (plural), then it sounds like a MP game.

d) Then you want the item to go into “the inventory of the PC character”. Again, we need to clarify if you mean it is a MP game (with more than one player), or is a SP game, with only one player? Then, we need to clarify if you mean the item can go into the inventory of the PC the player is currently possessing, or if you want the item to go into the Main PC (the one the player joined the game with), even if they currently posses another PC in their party?

e) So when you say “(Must be a PC)”, again, do you mean it has to be the Main PC, or any PC that the player has in their party, which they may, or may not, be possessing? Because, what if the player is playing their Main PC (who is a fighter), but the PC wizard (in their party) does the final kill? Did you mean that the Main PC still gets the item, even of their party wizard does the kill, as opposed to the fighter, who the player is actually (default) possessing at the time? Or, what if the player is possessing the wizard, and the Main PC (the fighter) kills the creature while the player is actually possessing the wizard PC?

MY CONCLUSION

ASSUMPTION 1: Here I will make as the best interpretation of what you are after: I assume you mean to say that this is a SP game, with a party of perhaps a maximum of six PCs (made from Main PC, cohorts and/or companions), which can indeed grow larger, if any of these PCs (of the same party) also have associates, such as summons, companions, familiars, or henchmen. Basically, a SINGLE PARTY game catering for a SINGLE PLAYER.

ASSUMPTION 2: Regardless of which PC the player currently possesses and plays, you wish the item to go to the Main PC upon the death of the creature.

ASSUMPTION 3: You need this item to drop (and be in the Main PC inventory) on the death of this creature.

I repeat that there is a risk that using GetLastKiller may not always give you what you need, and is why I am avoiding using it, unless you know it is not an essential item, which can go missed if this function fails.

SOLUTION A: As this item is effectively just a token, which you need to record progress, I would suggest implementing a journal update instead, and use that as the indication of what stage the player is at. I would also use variables to track the overall number of items collected.

SOLUTION B: Ensure the item is created on the Main PC (the one which the player joined the game with first), at the time of the creature death regardless of how it died. I make the assumption that the creature cannot die any other way, or if you intended an alternate way for the beast to die or not? If it is a simple matter of needing the item on the Main PC at time of the creature’s death, the the safest and surest way to do it (avoiding any potential OBJECT_INVALID via using GetLastKiller) is to use the script I posted above.

NB: If there is no chance of a MP game (and/or involving a DM), then you need not do the DM check, and you could even avoid the loop altogether. So when you say, “So You need a way to give the player the item when a creature is killed.”, then this is all you need…

SP VERSION: On the creature’s OnDeath hook.

(See my original script above for a MP version.)

//////////////////////////////////////////////////////////////////////////////////
// JUST GIVES AN ITEM TO PLAYER MAIN PC WHEN CREATURE KILLED (SP GAME ONLY)
// ASSUMES WE NEED THE ITEM ON THE MAIN PC REGARDLESS OF WHO KILLED THE CREATURE
// ALSO ASSUMES THAT THE CREATURE CANNOT DIE ANY OTHER WAY
//////////////////////////////////////////////////////////////////////////////////

void main()
{
	CreateItemOnObject("item_resref", GetFirstPC(TRUE));	// <-- put your item's resref here		
}

EDIT: I just read this …

So, this now begs the question about whether this is a SP or MP again? So, we need more description about how your module is setup to play. :thinking: Hopefully, after reading this post, you will be able to clarify your needs. This post info conflicts with your latest that says “The party size is unlimited”.

So, how does this fit in with your first quote I have for you? If not companions, are you meaning cohorts?

1 Like

my understanding so far is that it’s a multiplayer game (not sure if single or multi-playerfaction). There are no companions (called “companions” in NwScript.nss) or cohorts (called “player created” in NwScript.nss) but there can be associates.

(note: don’t confuse “player created character” with “owned character” – owned is the character the player logs in with and player-created are characters that can be brought into a campaign via the player creation GUI)

@Lance_Botelle i believe you call player-created chars “cohorts” ?

 

then why not just do
SetLocalInt(oPc, "hasMemory1", TRUE)
SetLocalInt(oPc, "hasMemory2", TRUE)
SetLocalInt(oPc, "hasMemory3", TRUE)

Or do you really want an item to appear in the character(s) inventory?

setting local_ints is by far the simplest

 
 
But the question remains, what, exactly gets back these memories …? (see Lance’s post above)

2 Likes

Also, I’m wondering if it really matters who the killer is or how the holders of the lost memories die? That is, retrieval of lost memories would be more robust if, like Lance says, GetLastKiller() isn’t needed – simply, if the creature dies, the memory is retrieved unconditionally

2 Likes

@kevL_s

Yes, I do. :+1: I find it an easier distinction to recognise when helping to distinguish between the various types of “PCs” the player can control, especially for players who don’t always use the same coding terms, which can be a little confusing where “possession” is also used. So, I have:-

MainPC - The PC the player joined the game with. (Owned PC.)
Cohorts - Other PCs the player has created for their party. (If allowed.)
Companions - PCs that the player can find in the module design to join the party. (If included.)

:thinking: I am wondering if this may be some kind of PW (Persistent World) setup myself now. If it is PW and the OP says, “check for number of PC characters in the party of the PC killer” and only for those that were in the same area at the time, then what happens if more than one PC faction (say two parties from two different players) are both involved in the creature kill? Is it now suggesting that only the party who landed the killing blow receive the token?

@MagicalWisps

Can you give us more information about your setup?

  1. Is it SP or MP?

  2. If MP: PW (Multiple party factions), or Coop (Single party faction)?

1 Like

I am building it for PW, but I also want to be able to release as a SP/Coop. It is built so that if I remove the mysql script functionality, it still works in a SP/Coop situation. As of right now, I can do just that.

Here is what I have set up.
MainPC - The PC the player joined the game with. (Owned PC.)
Cohorts - Not available
Companions - Not available
Party size - not limited by campaign settings(Unlimited)
Number of parties - not limited by campaign settings(Unlimited)

As for party size, The party size is limited by the server whether hardware or campaign settings. For me the party size is only limited by the server hardware and or bandwidth. The number of parties from my knowledge is also limited by the hardware and bandwidth and or server settings.

In PWs you’ll find players will group together in a party as there is a social aspect to the PW servers as well as distribution of XP among the party who kills a creature. It is beneficial to group together in a single party. However there can be multiple parties so there is also a decorum in PWs stating interaction as well as courtesies for parties participating in a quest.

In a SP, then there is only one party, so no problems here.

In Coop, there is a quasi Multiplayer, but you can have one party or multiple parties, but by nature gamers will wish to be in the same party in a Coop game or they group in a party when they are doing the same quests together but are separate when they are wishing to go to different areas away from each other. I am assuming that by Coop you mean a person hosting the mod and determining the server settings.

As for memories, the items do have descriptions on the item, but they are props as well. As far as players being stuck, I mean in terms game dev, gates that players have to open with keys they get by doing an action.

A player can go to an area where in order for them to escape that area, they need to collect “keys” (Memories) to open gates to leave the “prison” via a dialog conversation on an NPC. If they die, they escape the prison because they died, and they respawn back to a location where they can choose another adventure to go on.

Originally I had the Memory “items” droppable in the creature inventory, but since they are Memories, I thought it would make more sense for them to appear in the inventory rather that having a Player Character pick them up from the corpse.

For me the simplest way to do that is via scripting, as for the simplest way within the method of scripting, I am ignorant of that as I am uneducated in the many ways and techniques for scripting.

My mod is based on Waterdeep: Dragon Heist, however it doesn’t follow a linear story nor necessarily the Dragon heist campaign. It is a sand box mod that has a dragon heist flavor story among other quests and adventures.

1 Like

@MagicalWisps

I have to take your word on that, as I have no idea how to work with any PW mysql stuff. :slight_smile:

Party Size - Have you contradicted yourself in your comment, or have I misunderstood? In the list you say unlimited, but later say limited by server setting.

Emphasis in your quote is mine. I think you might be confusing players working together in one group (made from multiple parties) as opposed to actually all being in one party, as far as NWN2 script is concerned.

In this case, I think you may need to have a means of having such individual parties agree to setup as a group, by “signing in” to a temporary “group faction”, as it were. Once all parties involved are signed in to the “group faction”, then it is this “group faction” you need to check against.

However, if there is no risk of including all players (any * ) who would receive the token while in the area of the creature kill, then using that first script I suggested that uses the GetFirstPC(TRUE) loop while checking being in the same area, should be the safest to go with. i.e. Bypass the GetLKastKiller check, as it sounds like you want any and all PCs (of various players) to be able to receive the token if they took part in the “group” kill. The bottom line, you can ignore a single faction member search for the last killer in this situation, because I don’t believe all those involved would be included due to faction settings of a PW.

( * ) The only “player” that may be in an area that would not need the token are DMs as far as I can see, which my script included a check for.

Last point, PWs will require a degree of knowledge and consideration beyond most module designs, and I would say if you are struggling to manage this script, you may hit a number of bigger issues moving forward, depending upon how involved you are making this PW. Have you considered writing for a SP and/or basic Coop MP first? Even the latter, a MP coop is a considerable amount of work more to make it work than even a SP, and I say that with experience. :slight_smile:

1 Like

I have to take your word on that, as I have no idea how to work with any PW mysql stuff. :slight_smile:

Party Size - Have you contradicted yourself in your comment, or have I misunderstood? In the list you say unlimited, but later say limited by server setting.

I have a server running PW at this very moment so I can test multiple players and multiple party configurations. As for party size. That number is limited by two factors. Server Hardware/ bandwidth, or server settings.

I think you might be confusing players working together in one group (made from multiple parties) as opposed to actually all being in one party, as far as NWN2 script is concerned.

I am not confusing this idea. Two separate players in the same area is two parties until they decide to join together using the join party mechanism. I only want the killer’s party to get the item. And since I have party size unlimited then there can be any number of party groups running around with any number of party members. For me it is only limited by server hardware/bandwidth.

Last point, PWs will require a degree of knowledge and consideration beyond most module designs, and I would say if you are struggling to manage this script, you may hit a number of bigger issues moving forward, depending upon how involved you are making this PW.

I am well aware of the degree of knowledge necessary. Which is why I reached out to a helpful community that wishes to help keep this game alive. If we shudder to the challenges set before us, humanity would have gone extinct long ago. With that said this is not my first PW that I have been involved with, and I do have a solid set of scripting systems that have been tested, used, and altered by me. I was able to articulate what I wanted and received by the good graces of the NWN2 community, a working script that functions in the way I wanted it to. So far, I consider creating this PW to be a challenge, because of the kind generous peoples of the NWN2 Community, that challenge isn’t an impossible one.

1 Like

What “join party” mechanism is that then?

If they are two parties (to start with), what do they become when “joined”? Whose party faction are they now? Who is joining who? These may all be PW sort of things that you manage differently to what I do, and so only you would know what the faction state is.

As far as I am aware, “Party Size” relates to the number of PCs in a single party, rather than the number of parties on a server. So, just to be clear, if you had 30 players all join the same party, you will have 30 PCs in the party bar, plus all associates of each player?

PWs are above my knowledge - sorry. While I can script for normal SP or MP (Coop), there are too many other aspects to PW (like you are raising) that I have no experience with. I’ll chip in if and when I can, but maybe others can add if they have this experience.

All the best. :slight_smile:

1 Like

Start up a multiplayer hosting session and uncheck Only one Party.
Go to player menu, then player list, then you’ll see option to invite to party.

1 Like

id just be wary of the object returned by GetLastKiller()

It’s likely to be correct most of the time, but have a look at its entry on the Lexicon (which is often accurate for Nwn2)

cases you might want to test (in addition to those considered on the Lexicon page)
- creature is killed by a persistent or temporary AoE
- creature is killed by the spelleffect from a rod/wand/staff or scroll
- ?

 
so a message on failure might be a good thing

if (GetIsObjectValid(oKiller))
{
    // note that 'oKiller' might still be valid here
    // but an incorrect representation of the expected killer ->
    if (GetObjectType(oKiller) == OBJECT_TYPE_CREATURE)
    {
        // do routine
    }
    else
    {
        // print warning or error to logfile and/or the chat window
    }
}
else
{
    // print warning or error to logfile and/or the chat window
}
1 Like