I was looking for a script that runs everytime the PC successfully hits an indestructable gong.
I want the enemy who is blocking the path to an objective hear the gong and go to the gong/waypoint to investigate the sound.
I have found one script that I have not been able to implement. As much as I hate to admit it, it confuses me.
void main()
{
object oPC = GetLastHostileActor();
if (!GetIsPC(oPC)) return;
object oTarget;
oTarget = GetObjectByTag("as_mg_gong_02");
SoundObjectPlay(oTarget);
SoundObjectSetVolume(oTarget, 100);
AmbientSoundPlay(GetArea(oPC));
}
int NW_FLAG_BEHAVIOR_SPECIAL = 0x00000001;
void SetBehaviorState(int nCondition, int bValid = TRUE)
{
int nPlot = GetLocalInt(OBJECT_SELF, "NW_BEHAVIOR_MASTER");
if(bValid == TRUE)
{
nPlot = nPlot | nCondition;
SetLocalInt(OBJECT_SELF, "NW_BEHAVIOR_MASTER", nPlot);
}
else if (bValid == FALSE)
{
nPlot = nPlot & ~nCondition;
SetLocalInt(OBJECT_SELF, "NW_BEHAVIOR_MASTER", nPlot);
}
}
int isGong( object gong ) {
return GetTag(gong) == "TsGong";
}
int isBaton( object baton ) {
int type = GetBaseItemType(baton);
return
type == BASE_ITEM_TORCH ||
type == BASE_ITEM_CLUB ||
type == BASE_ITEM_LIGHTFLAIL ||
type == BASE_ITEM_HEAVYFLAIL ||
type == BASE_ITEM_MORNINGSTAR;
}
void moveToObject( object what, int run ) {
if( isBusy() || isSleeping() )
return;
ClearAllActions();
ActionMoveToObject( what, run, 5.0 );
}
int getIsSentient( object who ) {
int r = GetRacialType( who );
if( r == RACIAL_TYPE_DWARF || r == RACIAL_TYPE_ELF ||
r == RACIAL_TYPE_FEY || r == RACIAL_TYPE_GNOME ||
r == RACIAL_TYPE_HALFELF || r == RACIAL_TYPE_HALFLING ||
r == RACIAL_TYPE_HUMAN ||
r == RACIAL_TYPE_DRAGON || r == RACIAL_TYPE_GIANT ||
r == RACIAL_TYPE_HALFORC || r == RACIAL_TYPE_HUMANOID_GOBLINOID ||
r == RACIAL_TYPE_HUMANOID_ORC || r == RACIAL_TYPE_HUMANOID_REPTILIAN )
return 1;
return 0;
}
void sayChoice( int chanceToSay, string dumb, string s1, string s2, string s3, string s4, object who = OBJECT_SELF ) {
if( isSleeping( who ) ) {
return;
}
if( !getIsSentient( who ) )
return;
if( d100() >= chanceToSay )
return;
string s = dumb;
if( GetAbilityScore( who, ABILITY_INTELLIGENCE ) >= 6 ) {
switch( d4() ) {
case 1: s = s1; break;
case 2: s = s2; break;
case 3: s = s3; break;
case 4: s = s4; break;
}
}
if( who != OBJECT_SELF )
AssignCommand( who, SpeakString(s) );
else
SpeakString( s );
}
void returnToPostWhenNotInCombat() {
debugSay( "returning to post when not in combat." );
if( !GetIsObjectValid( OBJECT_SELF ) )
return;
if( GetIsInCombat() ) {
DelayCommand( 6.0, returnToPostWhenNotInCombat() );
return;
}
// Now return to your post.
object preGongPost = GetLocalObject( OBJECT_SELF, "tsPreGongPost" );
if( GetIsObjectValid( preGongPost ) ) {
debugSay( "attempting to return to my post." );
moveToObject( preGongPost, FALSE );
DestroyObject( preGongPost, 7.0 );
}
else {
debugSay( "no post to return to." );
}
DeleteLocalObject( OBJECT_SELF, "tsPreGongPost" );
DeleteLocalInt( OBJECT_SELF, "tsGongResponse" );
}
int testFight( object who = OBJECT_SELF ) {
object enemy = GetNearestCreature( CREATURE_TYPE_REPUTATION, REPUTATION_TYPE_ENEMY, who, 1, CREATURE_TYPE_PERCEPTION, PERCEPTION_SEEN );
tell( GetName(who)+" test fight. Found="+GetName(enemy) );
if( GetIsObjectValid(enemy) ) {
ActionMoveToObject( enemy, TRUE );
ActionAttack( enemy );
DelayCommand( 24.0, returnToPostWhenNotInCombat() );
return 1;
}
return 0;
}
void reactToVisitingGong( object gong ) {
if( !GetIsObjectValid( OBJECT_SELF ) )
return;
// When I reach the gong, what do I do or say? If I get there and don't
// end up in combat, maybe I won't be fooled the next time.
int gongReactionTicks = GetLocalInt( OBJECT_SELF, "tsGongReactionTicks" );
if( gongReactionTicks >= 3 ) {
// If I didn't get to the gong within 18 seconds, then
// forget about reacting.
debugSay( "I give up. I'm going back to my post." );
DeleteLocalInt( OBJECT_SELF, "tsGongReactionTicks" );
if( !testFight() )
returnToPostWhenNotInCombat();
return;
}
SetLocalInt( OBJECT_SELF, "tsGongReactionTicks", gongReactionTicks+1 );
tell( "Current action = "+IntToString(GetCurrentAction()) );
if( GetCurrentAction() == ACTION_MOVETOPOINT || GetDistanceBetween( OBJECT_SELF, gong ) > 5.0 ) {
// We aren't close enough yet, so keep trying.
debugSay( "Still moving to the gong." );
if( !testFight() )
DelayCommand( 6.0, reactToVisitingGong( gong ) );
return;
}
DeleteLocalInt( OBJECT_SELF, "tsGongReactionTicks" );
debugSay( "reacting to my visit to the gong." );
SetBehaviorState( NW_FLAG_BEHAVIOR_SPECIAL, FALSE );
// OK, we got to the gong. What did we find?
if( testFight() ) {
sayChoice( 70,
"You make noise!",
"So, it was you who made the noise!",
"You gave yourself away!",
"Striking that gong was unwise!",
"That noise will cost you your life!"
);
return;
}
sayChoice( 70,
"Uhhh, nobody here?",
"I thought I heard...",
"That is strange...",
"I guess it was the wind.",
"Something suspicious is going on."
);
DelayCommand( TS_SECONDS_TO_RETURN_TO_POST, returnToPostWhenNotInCombat() );
}
void gongResponse() {
if( !GetIsObjectValid( OBJECT_SELF ) )
return;
if( isBusy() ) {
debugSay( "too busy to respond to that gong." );
return;
}
SetBehaviorState( NW_FLAG_BEHAVIOR_SPECIAL, TRUE );
removeEffectType( OBJECT_SELF, EFFECT_TYPE_SLEEP );
debugSay( "responding to a gong." );
ClearAllActions();
sayChoice( 70,
"Duh, what?",
"What was that?",
"An alarm!",
"I heard a gong!",
"I'm checking that noise out."
);
// Store where we are standing so we can return here if we find nothing near
// the gong.
object preGongPost = GetLocalObject( OBJECT_SELF, "tsPreGongPost" );
if( !GetIsObjectValid( preGongPost ) ) {
preGongPost = CreateObject( OBJECT_TYPE_PLACEABLE, "plc_invisobj", GetLocation(OBJECT_SELF) );
if( !GetIsObjectValid(preGongPost) )
tell( "ERROR: unable to create invisible object to return to." );
SetLocalObject( OBJECT_SELF, "tsPreGongPost", preGongPost );
}
object gong = GetLocalObject( OBJECT_SELF, "tsGongIHeard" );
moveToObject( gong, TRUE );
DelayCommand( 6.0, reactToVisitingGong( gong ) );
DeleteLocalObject( OBJECT_SELF, "tsGongIHeard" );
}





Retour en haut






