Files
dsrc/sku.0/sys.server/compiled/game/script/ai/tusken_bantha.script
T
2013-09-10 23:17:15 -07:00

154 lines
3.8 KiB
Plaintext

include library.ai_lib;
include library.factions;
include library.utils;
const string SOCIAL_VOLUME = "npc_socialization";
const float SOCIAL_RANGE = 15f;
trigger OnAttach()
{
if ( !utils.hasScriptVar( self, "ai.tusken" ) )
{
cancelFollowing( self );
messageTo( self, "resumeLoitering", null, 3, false );
return SCRIPT_CONTINUE;
}
//debugSpeakMsg( self, "following " + getObjIdObjVar( self, "ai.tusken" ));
followTusken( self, utils.getObjIdScriptVar( self, "ai.tusken" ) );
factions.setFaction( self, "tusken" );
return SCRIPT_CONTINUE;
}
trigger OnDetach()
{
factions.setFaction( self, "bantha" );
return SCRIPT_CONTINUE;
}
trigger OnAddedToWorld()
{
if ( !utils.hasScriptVar( self, "ai.tusken" ) )
{
cancelFollowing( self );
messageTo( self, "resumeLoitering", null, 3, false );
return SCRIPT_CONTINUE;
}
followTusken( self, utils.getObjIdScriptVar( self, "ai.tusken" ) );
return SCRIPT_CONTINUE;
}
trigger OnBehaviorChange( int newBehavior, int oldBehavior, int[] changeFlags )
{
if ( isIncapacitated(self) )
return SCRIPT_CONTINUE;
if ( newBehavior < oldBehavior )
{
if ( !utils.hasScriptVar( self, "ai.tusken" ) )
{
cancelFollowing( self );
messageTo( self, "resumeLoitering", null, 3, false );
return SCRIPT_CONTINUE;
}
followTusken( self, utils.getObjIdScriptVar( self, "ai.tusken" ) );
return SCRIPT_OVERRIDE;//don't do the default AI thing
}
return SCRIPT_CONTINUE;
}
void followTusken( obj_id bantha, obj_id target )
{
//debugSpeakMsg( bantha, "thinking about following: " + target );
obj_id isFollowedBy = getObjIdObjVar( target, "ai.isFollowedBy" );
if ( isFollowedBy == null || isFollowedBy == bantha
// || !exists( isFollowedBy)
)
{
setMovementWalk( bantha );
//debugSpeakMsg( bantha, "REALLY " + target );
follow( bantha, target, 2f, 5f );
setObjVar( target, "ai.isFollowedBy", bantha );
utils.setScriptVar( bantha, "ai.tusken", target );
setObjVar( bantha, "ai.isFollowing", target );
}
else
{
followTusken( bantha, isFollowedBy );
}
}
messageHandler resumeLoitering()
{
if ( !utils.hasScriptVar( self, "ai.tusken" ) )
{
detachScript( self, "ai.tusken_bantha" );
return SCRIPT_CONTINUE;
}
followTusken( self, utils.getObjIdScriptVar( self, "ai.tusken") );
return SCRIPT_OVERRIDE;
}
void cancelFollowing( obj_id npc )
{
utils.removeScriptVar( npc, "ai.tusken" );
obj_id isFollowing = getObjIdObjVar( npc, "ai.isFollowing" );
if ( isFollowing != null )
messageTo( isFollowing, "stopBeingFollowed", null, 0, isObjectPersisted( isFollowing ) );
removeObjVar( npc, "ai.isFollowing" );
if ( hasObjVar( npc, "ai.isFollowedBy" ) )
{
obj_id isFollowedBy = getObjIdObjVar( npc, "ai.isFollowedBy");
messageTo( isFollowedBy, "stopFollowing", null, 0, isObjectPersisted( isFollowedBy) );
}
}
messageHandler stopBeingFollowed()
{
removeObjVar( self, "ai.isFollowedBy" );
return SCRIPT_CONTINUE;
}
messageHandler stopFollowing()
{
removeObjVar( self, "ai.isFollowing" );
cancelFollowing( self );
messageTo( self, "resumeLoitering", null, 3, false );
return SCRIPT_CONTINUE;
}
trigger OnFollowTargetLost(obj_id oldTarget)
{
cancelFollowing( self );
messageTo( self, "resumeLoitering", null, 3, false );
return SCRIPT_CONTINUE;
}
trigger OnFollowPathNotFound(obj_id target)
{
cancelFollowing( self );
messageTo( self, "resumeLoitering", null, 3, false );
return SCRIPT_CONTINUE;
}
trigger OnTriggerVolumeEntered( string volumeName, obj_id breacher )
{
if ( hasObjVar( breacher, "gm") )
return SCRIPT_CONTINUE;
if ( volumeName == ai_lib.ALERT_VOLUME_NAME )
{
if ( hasScript( breacher, "ai.tusken_raider") )
return SCRIPT_OVERRIDE;
}
return SCRIPT_CONTINUE;
}
trigger OnTriggerVolumeExited( string volumeName, obj_id breacher )
{
if ( volumeName == ai_lib.ALERT_VOLUME_NAME )
ignoreCreatureMovement(self, breacher);
return SCRIPT_OVERRIDE;
}