GetLastKiller() query and Party variables?

Hello! :slight_smile:

I’ve another query crop up in my script writing.

I’m trying to implement a very basic quest of Kill X number of enemies to spawn Y enemy.

Now if this was a single player, I think it would be straight forward, using GetLastKiller included in the creatures OnDeath script, to add +1 to the “XenemyKilled” variable.

Once it reached a certain number, Y would spawn.

However, I’m trying to build my quests with a party of PC’s in mind.

I’ve got an #include script function from Lilac Soul that allows party wide variable sets and calls, however it seems impossible to +1? as I get an script error.

Does GetLastKiller() function as I imagine and only works for the PC that strikes the killing blow?

Do Associates (GetMaster) count as Summoned Creatures and Henchmen only, or other party members?

Below is an example of script I’ve currently come up with.

The main issue is if different party members strike the killing blow, the script will call their Variable and +1 to that, and then set the entire party, so it may actually take more than X kills.

Really i’m after a way of adding a plus / minus variable to the entire party after a kill.

I suppose I could do a complex IF script, of if variable = 1, then make it =2, iIF it =3 then make it =4 until it reached the desired amount? Is this the best solution?

Thanks a lot,
Roarthing

object oTarget;
object oSpawn;

    // Get the creature who triggered this event.
    object oPC = GetLastKiller();


    while ( GetMaster(oPC) != OBJECT_INVALID )
        oPC = GetMaster(oPC);

    // Set party variable.
    int nValue = GetLocalInt(oPC, "quest1_1") + 1;
    SetLocalIntOnAll(oPC, "q1_1", nValue);

// Abort if the variable is less than 5.
    if ( GetPartyInt(oPC, "quest1_1") < 5 )
        return;

    // Abort if the variable is 1 (i.e. Already spawned BossMonster.)
    if ( GetLocalInt(oPC, "quest1_done") == 1 )
        return;

        // Spawn "BossMonster". 

You could store the variable on the area or on the module rather than on the object that killed the hostile. That way, all kills would be contributing to the same counter, no matter who struck the killing blow.

GetArea()
GetModule()

Far as getting errors in that script goes - are you actually #including the library? The line is missing in the code you’ve posted. Without it, the compiler would have no idea what the functions you’re trying to use are, and go “RAWRGH! UNDEFINED IDENTIFIER!” or “ERROR PARSING VARIABLE LIST!”.

Take a look at https://nwnlexicon.com/index.php?title=GetFirstFactionMember, too. You can cycle through all members of the PC party in a while loop if you need to, associates included.

Thanks The Barbarian,

You’re an omnipotent oracle of wisdom!

I like both suggestions.

With an Area variable, I can use the Area Exit to determine if any PCs are left, and otherwise reset the counter correct?

I like GetNextFactionMember loop, however are PCs in a party on a separate faction than PCs in another party, or are they all stIill PC.
I.e. if multiple parties were allowed would party one killing required enemies also make the variable change for PCs not in the area?

Highly unlikely to be an issue on my semipw private server but Im trying to make everything as full proof as possible to save going back and rewriting.

Yes, you can erase area variables in the area’s OnExit event. You could increment a PC counter by 1 every time a PC enters the area, and decrement it again every time a PC leaves the area, for instance.

I don’t actually know whether PC parties are separate factions. :thinking: I’d expect them to be, though, yeah. Doing it otherwise wouldn’t make a lot of sense. Probably a good idea to store on the party, then, if you want parties to have to increment their counters individually. They’d be competing for mob kills that way, though… and people could annoy other people by farming in areas without needing them for the quest/boss. :thinking:

You could also set up a counter per party on the area, with some mild variable sorcery; creating something to identify the party by, and incrementing a joint counter using that thing or string as a base.

Take a look at these, they sound like they were made for this exact kind of thing:
https://nwnlexicon.com/index.php?title=Category:Party_Functions
https://nwnlexicon.com/index.php?title=SetLocalIntOnAll

noooo… too much pressure!! x_x ::panic attack time:: :scream: ::hides::

I think omnipotent was definitely the wrong word. It means all powerful. The word you wanted was omniscient. That means all knowing. :sunglasses:

TR

2 Likes

I should never, under any circumstances, be allowed anywhere near either concept. (Warning: Mildly NSFW)

3 Likes

I’m speechless at the above link. Haha!

Back OT, I think the aPartyVariables from the j2assassin include are perfect :slight_smile:

Thanks!

1 Like