login

Author Topic: Finding out who destroyed who  (Read 2988 times)

Cirdan

  • Guest
Finding out who destroyed who
« on: January 26, 2007, 10:13:23 am »
Would it be possible to find out, not only when a party has been destroyed (whether by the player or an NPC party), but by whom the party was destroyed, and where it was destroyed, stocking the info for later use in a script (spawning a new party and making it track down the culprits...for instance)? and if so, could somebody give me pointers on how to go about doing this, given that i am a Python newbie?

Offline Hellequin

  • Journeyman
  • ***
  • Posts: 254
    • View Profile
Re: Finding out who destroyed who
« Reply #1 on: January 26, 2007, 10:57:02 am »
Yes, it should be quite possible.  All of the logic involved is accessible to you, it's just a matter of finding where in the sequence to insert your assignment statements to keep track of things.  The first thing you need to be aware of is that it'll be quite a different procedure for tracking this for combats where the player isn't involved, from ones where the player is involved.

When the player isn't involved, the logic is in module_simple_triggers.py, the second big trigger structure labeled "simulate battle".  Partway down it's got the logic for whether to consider the battle won or not, and by whom.  Put a call there to your script that stores whodunnit, who died, and where (see notes on this below).

When the player is involved, the encounter logic will be in the relevant menu - simple_encounter in many cases but not all, depending on what else you've done with your mod.  Once again you want to find the point in the logic where it makes the determination of who won, and insert your call there.

Figuring out where the kill happened is actually the hardest part - as far as I know there's no way to get a position on the world map directly.  But here's an example of a workaround: create a party template called "grave_marker" or whatever, make it pf_disabled so it doesn't ever show up on the map and pf_static so it stays put.  During your "a party just got killed" logic, call (set_spawn_radius, 0) and then (spawn_around_party) to make an instance of pt_grave_marker at the location of the deceased.  The spawn_around_party operation stores the partyID of the just-spawned party in reg0 (see header_operations.py), so make sure you store that datum somewhere more permanent.  Then, at any later time, you can spawn a visible party at spawn_radius zero from the grave marker party, and they'll appear at the spot the kill was made.  (Optionally you clean up your parties roster by removing the grave marker at this point, depending on how often you figure this'll happen.)

In terms of storing your data, you need to think about where to store this information.  Perhaps the mod only needs to keep track of the single most recently killed party, in which case you can use a single global variable like "$most_recently_killed_party" for each snippet of information you want to keep track of.  Or perhaps you want to associate it with the party which did the killing in which case you'd use slots on that party, (party_set_slot, ":Killer_party", slot_party_latest_victim, ":Killed_party"), or the like.  Or, perhaps best, you put every bit of information into slots on the grave_marker party, except for (somewhere) a reference so that you know which grave_marker is which.  (That latter might not even be necessary; perhaps each grave_marker gets assigned an hour-of-death and then a trigger using (try_for_parties) iterates across all parties every hour, throwing out the ones that aren't spawned by pt_grave_marker, throwing out the ones whose hour-of-death is too recent or whatever, and taking action on anything that passes those conditions.)

That's an outline of how I'd handle the code you describe.  There are probably other ways to do it, but this one would work.

- Hellequin

Offline fujiwara

  • Master
  • *****
  • Posts: 858
    • View Profile
Re: Finding out who destroyed who
« Reply #2 on: January 27, 2007, 01:58:22 am »
Excellent explanation, Hellequin. :)

The horses tend to get their legs caught in the catapult rather than being properly launched.

Cirdan

  • Guest
Re: Finding out who destroyed who
« Reply #3 on: January 27, 2007, 10:54:38 am »
It hardly sounds simple to me, but maybe that's my lack of experience with Python, general programming and the module system. I'll give it a try at any rate; I can set the game to spawn a party that will track down another easilly, so if i can get which party to hunt and where it oughtn't be a problem.

Cirdan

  • Guest
Re: Finding out who destroyed who
« Reply #4 on: January 28, 2007, 07:12:18 am »
Errr...i have more  questions, of an extremely newbie nature i'm afraid.
First of all, the M&B module system uses a number of triggers which correspond to hardcoded game events. I've found some of them in the header_xxxx.py files, but by no means all of them. Is there anywhere one can find a full library of these triggers with an explanation of how to use them?

And secondly, in this specific instance, at the start of the simple_triggers battle "simulator", it appears that root_attacker_party and root_defender_party are loaded, then they are grouped with any allied parties. Would I not have to save who the "core" parties are at this point? or am i totally misunderstanding how this code works?