11-03-2003 17:10
- Communicates with game rules instantiation module via LinkMessages in order to launch attacks on enemy
- If you turn AP on it attacks avatars, otherwise it attacks scrpited agents
- if you turn DoFarStrikeOn it will attempt to place itself 4.5m from target and do FarStrikes. If it gets closer than 2m by accident it proximitystrikes anyway
- otherwise it will stick to target and do proximitystrikes

Uses llMoveToTarget because its easy peasy.

In the very close future I plan to have a robot arena where we battle different AIs against each other (common locked game rule instantiation module in each robot).

I cant tell if this is the current version of the scirpt or not, but it shows the basic idea.


CODE

integer AP = TRUE;
integer DoFarStrike = FALSE;
integer DoRepulse = FALSE;

vector LastTargetPos = ZERO_VECTOR;

Init()
{
llSay(0, "AI online");
}

default
{
state_entry()
{
if( AP )
{
llSensorRepeat("","",AGENT,20.0,PI,1.0);
}

else
{
llSensorRepeat("","",SCRIPTED,20.0,PI,1.0);
}
Init();
}
on_rez( integer param )
{
Init();
}
touch_start( integer num_detected )
{
// llSay( 0, "sending message" );
llMessageLinked( LINK_SET, 0, "test", "" );
}
sensor( integer num_detected )
{
//llSay( 0, (string)num_detected );
string TargetName;
key Targetid;

Targetid = llDetectedKey(0);
TargetName = llDetectedName(0);

vector VectorToTarget;
VectorToTarget = llDetectedPos(0) - llGetPos();

float DistanceToTarget;
DistanceToTarget = llVecMag( VectorToTarget );

// llSay( 0, "Far striking..[" + TargetName + "]");

if( !AP )
{
if( DistanceToTarget <= 2.0 )
{
llMessageLinked( LINK_SET, 0, "PROXIMITYSTRIKE", "" );
}
else
{
llMessageLinked( LINK_SET, 0, "FARSTRIKE", "" );
}

vector ExtrapolatedNextPosition;
if( LastTargetPos != ZERO_VECTOR )
{
ExtrapolatedNextPosition = llDetectedPos(0) - LastTargetPos +llDetectedPos(0);
}
else
{
ExtrapolatedNextPosition = llDetectedPos(0);
}
LastTargetPos = llDetectedPos(0);

if( !DoFarStrike )
{
llMoveToTarget( ExtrapolatedNextPosition, 0.2);
}
else
{
// llSay( 0, "Far striking..[" + TargetName + "]");

if( DistanceToTarget > 5.0 || DistanceToTarget < 4.0 )
{

llMoveToTarget( llGetPos() - ( 4.5 - DistanceToTarget ) * VectorToTarget / llVecMag( VectorToTarget ), 0.1 );
}
else
{
vector VectorPerpToTarget;
VectorPerpToTarget = llVecNorm(VectorToTarget % <llFrand(1.0)- 0.5,llFrand(1.0)- 0.5, llFrand(1.0)- 0.5>) * 2.0;
// llMoveToTarget( llGetPos() + <llFrand(1.0)- 0.5,llFrand(1.0)- 0.5, llFrand(1.0)- 0.5>, 0.1 );
llMoveToTarget( llGetPos() + VectorPerpToTarget, 0.1 );
}
}
}else //AP
{
if( DistanceToTarget <= 2.0 )
{
llMessageLinked( LINK_SET, 0, "PROXIMITYSTRIKE", "" );
llMoveToTarget( llGetPos() - ( 4.5 - DistanceToTarget ) * VectorToTarget / llVecMag( VectorToTarget ), 1.0 );
llSleep( 1.0);
llStopMoveToTarget();
}
else
{
llMoveToTarget( llDetectedPos(0), 0.5 );

}
} // AP
} // sensor event
}