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 .