Author Topic: Script for setting faction/faction relationship during game play??  (Read 389 times)

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0


               Hello. Is there a way to set the relationship between diferent faction programmatically during game play? I know, obviously, how to do this in the toolset, but doing it with a script would fix a lot of issues for me. This topic may overlap with my other one, if the solution for the door-bludgeoning is to set the NPC's faction to hostile with the PC. I appreciate the help. Thanx!
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #1 on: June 15, 2013, 12:28:51 am »


               For standard factions: SetStandardFactionReputation()
For custom factions: AdjustFactionReputation()

More information: NWN Lexicon on Reputation and Faction Functions
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #2 on: June 15, 2013, 12:49:26 am »


               The typical way to do this is to have a few creatures in an area that are out of play and to target these creatures with the faction adjustments.

The trick:
each creature has no AI scripts. Delete them all.
each creature has one of the custom factions.
each creature is tagged with the name of the custom faction they belong to
none of these creatures should be targeted with plot, and none of them should be able to see one another (although without any AI scripts this probably doesn't matter)

then when you want to adjust a faction's reputation relative to another or to the PC:
search by tag for the faction name
adjust reputation
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #3 on: June 15, 2013, 12:56:15 am »


               Ah. Yes. This is perfect.
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #4 on: June 15, 2013, 01:43:28 am »


               There's a simple example of the faction focus concept that henesua talk about on the AdjustFactionReputation() page I linked. For a more robust implementation, though, you might consider using Personal Reputation and Reaction. It also has scripts that have guards protect doors and chests (much better than the simple one I posted on the other thread).
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #5 on: June 16, 2013, 02:29:17 am »


               I can't get it to work. It's compiling okay, but the Dojo isn't going hostile when I attack the door. I know there's no PC faction.  Here's what I'm trying to do:
#include "nw_i0_plot"
void main()
{
   // Get the faction focus objects
   object oPC   = GetObjectByTag("Faction_Focus_PC");
   object oDojo = GetObjectByTag("Faction_Focus_Dojo");

   // Get how the PC and Dojo feel about each other now.
   int nReputationWithPC   = GetReputation(oDojo, oPC);
   int nReputationWithDojo = GetReputation(oPC, oDojo);

   // Get how the PC should feel about the Dojo and vice versa. This
   // info is set by any script that persistently adjusts how the factions feel
   // about each other.
   int nStoredReputationWithPC   = GetCampaignInt("MyCampaign", "Reputation_PC_Dojo");
   int nStoredReputationWithDojo = GetCampaignInt("MyCampaign", "Reputation_Dojo_PC");

   // Adjust the reputations to the desired values.
   AdjustFactionReputation(oDojo, oPC,   nStoredReputationWithPC   - nReputationWithPC - 100);
   AdjustFactionReputation(oPC,   oDojo, nStoredReputationWithDojo - nReputationWithDojo - 100);
}
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #6 on: June 16, 2013, 03:24:09 am »


               What the example is doing is adjusting how those factions feel about each other based on a persistently stored value. It's the sort of thing that might run OnModuleLoad. For an OnPhysicalAttacked script, you'd wanna do the following:

void main()
{
    // Get the PC and Dojo faction focus object
    object oPC   = GetLastAttacker();
    object oDojo = GetObjectByTag("Faction_Focus_Dojo");

    // Adjust how the Dojo feels about the PC
    AdjustReputation(oPC, oDojo, -100);
}

Note that we don't get a faction focus for the PC. We just get him instead.
               
               

               


                     Modifié par Squatting Monk, 16 juin 2013 - 02:30 .
                     
                  


            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #7 on: June 16, 2013, 03:24:55 am »


               EDIT: double post ':blink:'
               
               

               


                     Modifié par Squatting Monk, 16 juin 2013 - 02:26 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #8 on: June 16, 2013, 03:53:30 am »


               

henesua wrote...

The typical way to do this is to have a few creatures in an area that are out of play and to target these creatures with the faction adjustments.

The trick:
each creature has no AI scripts. Delete them all.
each creature has one of the custom factions.
each creature is tagged with the name of the custom faction they belong to
none of these creatures should be targeted with plot, and none of them should be able to see one another (although without any AI scripts this probably doesn't matter)

then when you want to adjust a faction's reputation relative to another or to the PC:
search by tag for the faction name
adjust reputation


Couldn't you also do this with placeables?
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #9 on: June 16, 2013, 04:40:10 am »


               No, unfortunately. AdjustReputation() does not work with placeables.
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #10 on: June 18, 2013, 07:47:26 am »


               I still can't get it to work, Monk. Is there a header file?
               
               

               
            

Legacy_BelowTheBelt

  • Hero Member
  • *****
  • Posts: 699
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #11 on: June 18, 2013, 11:51:27 pm »


               Quick question... How does the plot setting on the NPC faction creatures affect the custom factions?
               
               

               
            

Legacy_Squatting Monk

  • Hero Member
  • *****
  • Posts: 776
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #12 on: June 19, 2013, 01:11:51 am »


               

Groove Widdit wrote...

I still can't get it to work, Monk. Is there a header file?

No, you don't need to include anything. Here's a simple demo. Notice that when you attack the door, both the faction focus and the member of the faction go hostile. (Though neither of them will attack you, since they do not have scripts assigned making them do so).

BelowTheBelt wrote...

Quick question... How does the plot setting on the NPC faction creatures affect the custom factions?

IIRC, both the plot and immortal flags stop this from working. This is why it's important to keep your factions focuses isolated and unscripted. Don't want them killing each other.
               
               

               
            

Legacy_Groove Widdit

  • Sr. Member
  • ****
  • Posts: 293
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #13 on: June 19, 2013, 01:14:49 am »


               Okay, I got it to work. Thanks guys. It took some experimentation to figure how to get an isolated custom creature set up right, but it does now work. This is crucial to my dungeon.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Script for setting faction/faction relationship during game play??
« Reply #14 on: June 19, 2013, 04:15:43 am »


                For another way of handling when your door is attacked, you may want to loot at the  Simply Stealing   thread.