Author Topic: Conversation while in combat  (Read 446 times)

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Conversation while in combat
« on: February 10, 2011, 08:07:43 pm »


               Ok here's the situation...A NPC stands (defender faction) where I placed it. When a PC comes within 30 meters a trigger spawns hostiles creatures near the NPC and they start fighting each other. When the NPC percieve the PC he runs towards him and start his conversation but the PC can't answer because the dialog is quickly interrupted by the nearby hostiles...
Is there a way to "freeze" the scene once the dialog begins so that the PC can select his answer and then resume the action?
I hope you understand what I mean (think at drizzt being assaulted by dozens of gnolls in BG and initiating the dialog with your character '<img'>
Thanks!
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Conversation while in combat
« Reply #1 on: February 11, 2011, 03:07:59 am »


               Quickly the only way I know to do this is to change the hostile creatures temp to common allow pc to choose then back to hostile.  we did this on a previous post let me try to find the link or I can send you the script example if you drop a PM with your email.
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Conversation while in combat
« Reply #2 on: February 11, 2011, 07:13:32 am »


               I could not find the link but here is a script you can put in npc on_percept script, and on damaged script.  i will keep looking for link.  These scripts should give you a good idea, I do have a better example in a small mod if you want me to email it to you.

//---------------------------------
on_perception script

//npc_percp
//:://////////////////////////////////////////////////
//:: NW_C2_DEFAULT2
/*
 Default OnPerception event handler for NPCs.

 Handles behavior when perceiving a creature for the
 first time.
*/
//:://////////////////////////////////////////////////

#include "nw_i0_generic"

void main()
{
// * if not runnning normal or better Ai then exit for performance reasons
   // * if not runnning normal or better Ai then exit for performance reasons
   //if (GetAILevel() == AI_LEVEL_VERY_LOW) return;

   object oPercep = GetLastPerceived();
   int bSeen = GetLastPerceptionSeen();
   int bHeard = GetLastPerceptionHeard();


object oSelf = OBJECT_SELF;
location lLoc = GetLocation(oSelf);

//chk1
if( GetIsInCombat(OBJECT_SELF)==TRUE  )
{
// stop NPC from attacking npc's
AssignCommand(oSelf, ClearAllActions(TRUE));

// Search through all creatures in a 40 meter radius centered on oSelf
object oNPC = GetFirstObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);

while(GetIsObjectValid(oNPC))
   {
   // Clear combat states for every creature found in search
   // that would be hostile to oSelf npc(defender) or oPC
   //ClearPersonalReputation(oPC,oNPC);
   ClearPersonalReputation(oSelf,oNPC);
   AssignCommand(oNPC, ClearAllActions(TRUE));

   // Change NPC to Commoner Faction so no longer hostile
   if( (!GetIsPC(oNPC)) && oNPC!=oSelf )
   {
   ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);
   }


   oNPC = GetNextObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
   }//end of if( GetIsInCombat(OBJECT_SELF)==TRUE  )
}//end of if( GetIsInCombat(OBJECT_SELF)==TRUE  )
//
//chk2
if( GetIsInCombat(OBJECT_SELF)==FALSE  )
{
// stop NPC from attacking npc's
AssignCommand(oSelf, ClearAllActions(TRUE));

// Search through all creatures in a 40 meter radius centered on oSelf
object oNPC = GetFirstObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);

while(GetIsObjectValid(oNPC))
   {
   // Clear combat states for every creature found in search
   // that would be hostile to oSelf npc(defender) or oPC
   //ClearPersonalReputation(oPC,oNPC);
   ClearPersonalReputation(oSelf,oNPC);
   AssignCommand(oNPC, ClearAllActions(TRUE));

   // Change NPC to Commoner Faction so no longer hostile
   if( (!GetIsPC(oNPC)) && oNPC!=oSelf )
   {
   ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);
   }


   oNPC = GetNextObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
   }//end of if( GetIsInCombat(OBJECT_SELF)==TRUE  )
}//end of if( GetIsInCombat(OBJECT_SELF)==TRUE  )

//
// chk 3
if( GetIsInCombat(OBJECT_SELF)==FALSE && (bSeen) )
{
object oPC = GetFirstObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
// Have the NPC oSelf begin a conversation with PC
// This "" will execute npc conversation set by npc properties or execute a file
// ActionStartConversation(oPC, "name of conversation file", FALSE, TRUE )
while(GetIsObjectValid(oPC))
   {                 //GetLocalInt(oSelf,"in_conv"==0
   if(  GetIsPC(oPC)==TRUE)
       {
       // stop player char from attacking NPC's
       AssignCommand(oPC, ClearAllActions(TRUE));
       AssignCommand(oSelf, ActionMoveToObject(oPC,TRUE));
       SetLocalInt(oSelf,"in_conv",1);//==0
       AssignCommand(oSelf, ActionStartConversation(oPC, "", FALSE, TRUE ));
       }
   oPC = GetNextObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
   }//end of while(GetIsObjectValid(oPC))
// Else NPC is normal OnPercived script
//
//chk 4
}else if( GetIsInCombat(OBJECT_SELF)==FALSE && (bHeard) )
{
object oPC = GetFirstObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
// Have the NPC oSelf begin a conversation with PC
// This "" will execute npc conversation set by npc properties or execute a file
// ActionStartConversation(oPC, "name of conversation file", FALSE, TRUE )
while(GetIsObjectValid(oPC))
   {                 //GetLocalInt(oSelf,"in_conv"==0
   if(  GetIsPC(oPC)==TRUE)
       {
       // stop player char from attacking NPC's
       AssignCommand(oPC, ClearAllActions(TRUE));
       AssignCommand(oSelf, ActionMoveToObject(oPC,TRUE));
       SetLocalInt(oSelf,"in_conv",1);//==0
       AssignCommand(oSelf, ActionStartConversation(oPC, "", FALSE, TRUE ));
       }
   oPC = GetNextObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
   }//end of while(GetIsObjectValid(oPC))
// Else NPC is normal OnPercived script
}else
   {
   ExecuteScript("nw_c2_default2", oSelf);
   }

//end of script
}

//------------------------
on damaged script

// npc_ondamge
//Here's an example for you. For this to work, set the NPC as Immortal = True in its properties.
//This will allow the NPC to take damage down to 1 hit point but not be killed.
//
//In the NPCs OnDamaged script slot, have something like the following:

void main()
{

/*
object oSelf = OBJECT_SELF;
location lLoc = GetLocation(oSelf);
int nHP = GetCurrentHitPoints(oSelf);

// If the NPC currently has 1 Hit Point left
if(nHP == 1) {

    // Search through all creatures in a 20 meter radius centered on oSelf
    object oNPC = GetFirstObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
    while(GetIsObjectValid(oNPC)) {

        // Clear combat states for every creature found in search
        AssignCommand(oNPC, ClearAllActions(TRUE));
        // Change NPC to Commoner Faction so no longer hostile
        if (!GetIsObjectValid(oNPC)) {
            ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);
        }
        oNPC = GetNextObjectInShape(SHAPE_SPHERE, 20.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
    }

    // Have the NPC begin a conversation with PC
    object oPC = GetFirstPC(); // In a SP module, this is the player’s originally created character
    AssignCommand(oSelf, ActionStartConversation(oPC, "", FALSE, FALSE));
    }
    // Else NPC is not yet at 1 Hitpoint, so fire normal OnDamaged script
    else {

    ExecuteScript("x2_def_ondamage", oSelf);

    }
}
*/
object oSelf = OBJECT_SELF;
object oAttacker = GetLastDamager(oSelf);
location lLoc = GetLocation(oSelf);
int nHP = GetCurrentHitPoints(oSelf);

// If the NPC currently has 1 Hit Point left
if(nHP <= 20 && GetLocalInt(oAttacker,"Perm_Hostile")==0 )
{
// stop player char from attacking NPC
    if(GetLocalInt(oAttacker,"Perm_Hostile")==0)
    {
    AssignCommand(oAttacker, ClearAllActions(TRUE));
    }
// stop oSelf from attacking oAttacker
    if(GetLocalInt(oAttacker,"Perm_Hostile")==0)
    {
    ClearPersonalReputation(oAttacker,oSelf);
    }

// uncoment if you want oSelf to be a hostile creature that talks
//ChangeToStandardFaction(oSelf, STANDARD_FACTION_COMMONER);
AssignCommand(oSelf, ClearAllActions(TRUE));

// Search through all creatures in a 40 meter radius centered on oSelf
object oNPC = GetFirstObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);

while(GetIsObjectValid(oNPC))
    {
    // Clear combat states for every creature found in search
    //ClearPersonalReputation(oAttacker,oSelf);
    //ClearPersonalReputation(oAttacker,oNPC);
    if(GetLocalInt(oNPC,"Perm_Hostile")==0)                                           //
        {
        ClearPersonalReputation(oSelf,oNPC);
        AssignCommand(oNPC, ClearAllActions(TRUE));
        }

    // Change NPC to Commoner Faction so no longer hostile
    if( (!GetIsPC(oNPC)) )
        {
        ChangeToStandardFaction(oNPC, STANDARD_FACTION_COMMONER);
        }
                              //GetLocalInt(oSelf,"in_conv"==0
    if(  GetIsPC(oNPC)==TRUE && oAttacker==oNPC )
        {
        // Have the NPC begin a conversation with PC
        //This "" will execute npc conversation set by npc properties or execute a file
        //ActionStartConversation(oPC, "name of conversation file", FALSE, TRUE )
        //AssignCommand(oSelf, ActionStartConversation(oAttacker, "", FALSE, TRUE ));
        // stop player char from attacking NPC's

        AssignCommand(oNPC, ClearAllActions(TRUE));
        AssignCommand(oSelf, ActionMoveToObject(oNPC,TRUE));
        SetLocalInt(oSelf,"in_conv",1);//==0
        AssignCommand(oSelf, ActionStartConversation(oNPC, "", FALSE, TRUE ));
        }

    oNPC = GetNextObjectInShape(SHAPE_SPHERE, 40.0f, lLoc, FALSE, OBJECT_TYPE_CREATURE);
    }//end of while(GetIsObjectValid(oNPC))
}//end of if(nHP <= 20)
// Else NPC is not yet at 1 Hitpoint, so fire normal OnDamaged script
else
    {
    ExecuteScript("nw_c2_default6", oSelf);
    }
//end of script
}

I couldn't remember which script had which information, I hope it helps.
               
               

               


                     Modifié par Greyfort, 11 février 2011 - 07:16 .
                     
                  


            

Legacy_Krevett

  • Full Member
  • ***
  • Posts: 203
  • Karma: +0/-0
Conversation while in combat
« Reply #3 on: February 11, 2011, 10:34:37 am »


               Thanks for pointing me in the right direction you're right I found no other way than changing the NPC factions temporary (I store them locally on the NPC fighting them in his onpercieve_usd for later retrieving them and set their faction back to hostile at the end of the dialog)
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Conversation while in combat
« Reply #4 on: February 11, 2011, 04:26:15 pm »


               Why not just change the npc to a plot character, so they stop attacking him, and then just change him back once the conversation is over?