Here is how it looks:
# Jedi Knight COG Script
#
# ACTOR_FRIENDF.COG
#
# A cog for a friendly actor.
# Kinda like Max, just better.
# Class cog/follow player version.
#
# [DP]
#
symbols
thing friend local
thing player nolink local
thing target local
int count=0 local
message created
message killed
message pulseend
message killed
message damaged
message skill
message timer
int oldAIMode local
int isFrozenNow=0 local
flex extraFreezeTime=0.0 local
template powerup=+DSTrifle local
template limb=+stormlimb local
int newThing local
int victim local
int bin local
int senderref=-1 local
ai flee_ai=noweapon.ai local
int damage local
vector currentpos local
# ========================================================================================
code
Created:
player = GetLocalPlayerThing();
SetThingPulse(GetSenderRef(), 1);
AIClearMode(GetSenderRef(), 0x1206);
Return;
# ........................................................................................
damaged:
damage = GetParam(0);
if(GetParam(1) == 16) // saber damage might cause dismemberment
{
damage = (damage * 2.0);
victim = GetSenderRef();
if(GetThingHealth(victim) <= damage) // but only if damage is sufficient to kill
{
if(rand() < 0.05) // random chance
{
AmputateJoint(victim, 5);
newThing = CreateThingAtPos(limb, GetThingSector(victim), GetThingPos(victim), '0 0 0');
SetThingVel(newThing, '0.0 0.7 1.4');
}
}
}
ReturnEx(damage);
return;
# ........................................................................................
killed:
victim = GetSenderRef();
if(GetActorWeapon(victim, 1) != -1)
{
AmputateJoint(victim, 3);
newThing = CreateThing(powerup, victim);
SetLifeleft(newThing, 200.0);
}
return;
# ........................................................................................
Killed:
If(GetThingClassCog(GetSenderRef()) != GetSelfCog()) Return;
SetThingPulse(GetSenderRef(), 0);
AIClearMode(friend, 0x1206);
AISetMode(friend, 0x1);
Return;
# ........................................................................................
skill:
bin = GetParam(0);
if(bin == 24) // Force Pull
{
// he's a fighter, not a fleer... -srs
senderref = GetSenderRef();
// If he hasn't been pulled yet...
if (GetActorWeapon (senderref, 1) != -1)
{
SetActorWeapon(senderref, 1, -1);
newThing = CreateThing(powerup, GetSenderRef());
SetLifeleft(newThing, 30.0);
AISetClass (senderref, flee_ai);
AISetMode(senderref, 0x4);
ReturnEx(newThing);
}
else
{
// Give the actor a shove towards the player.
currentpos = VectorSub(GetThingPos(GetLocalPlayerThing(), senderref));
currentpos = VectorScale(VectorNorm(currentPos), 250);
ApplyForce(senderref, currentpos);
ReturnEx(-1);
}
//AIFlee(senderref, GetLocalPlayerThing());
Return;
}
else
if(bin == 31) // Force Grip
{
ReturnEx(10); // return base damage that is taken by this actor.
Return;
}
else
if(bin == 34) // Deadly Sight
{
ReturnEx(10); // return base damage that is taken by this actor.
Return;
}
// else
// if(bin == 1035) // Carbonite
// {
// if (!isFrozenNow)
// {
// senderref = GetSenderRef();
// victim = GetParam(2);
//
// isFrozenNow = 1;
// extraFreezeTime = 0.0;
//
// oldAIMode = AIGetMode(victim);
// AISetMode(victim, 0x2000); // Disable the actor's AI.
// AISetMoveThing(victim, victim); // Set the thing as it's own destination so it stops moving.
//
// SetTimerEx(GetParam(1), 1035, victim, 0); // Make an appointment for "Unthawing"
// }
// else
// {
// extraFreezeTime = extraFreezeTime + GetParam(1);
// }
//
// ReturnEx(0);
// return;
// }
ReturnEx(-1);
return;
# ........................................................................................
timer:
senderref = GetSenderRef();
if(GetSenderId() == 1035) // Thaw out
{
victim = GetParam(0);
if (!extraFreezeTime)
{
AIClearMode(victim, 0xFFFFFFFF);
AISetMode(victim, oldAIMode); // Reinstate the actor's AI.
isFrozenNow = 0;
}
else
{
// We've been hit more than once, so we need to extend the freeze time.
SetTimerEx(extraFreezeTime, 1035, victim, 0); // Make an appointment for "Unthawing"
extraFreezeTime = 0.0;
}
}
Return;
# ........................................................................................
Pulse:
count = 0;
friend = GetSenderRef();
If(AIGetMode(friend) == 0x202) Return; // So it keeps on the same target
target = FirstThingInView(friend, 170, 12, 0x4);
If((GetThingClassCog(target) == GetSelfCog())||(target == player)) target = -1;
While((target == -1)&&(count < GetThingCount()))
{
target = NextThingInView();
If(count == GetThingCount()) target = -1;
If((GetThingClassCog(target) == GetSelfCog())||(target == player)) target = -1;
count = count + 1; // Incase there isn't anything in view
}
If(target != -1) // If there's a target
{
CaptureThing(target);
AISetFireTarget(friend, target);
AISetMoveThing(friend, target);
AISetLookPos(friend, GetThingPos(target));
AISetMode(friend, 0x202);
AIClearMode(friend, 0x1000);
}
Else // If not, go to player
If((VectorDist(GetThingPos(player), GetThingPos(friend))) > .5)
{
call followplayer;
Return;
}
Else AIClearMode(friend, 0x1206);
Return;
# ........................................................................................
FollowPlayer:
AISetMoveThing(friend, player);
AISetLookPos(friend, GetThingPos(player));
AISetMode(friend, 0x1);
AIClearMode(friend, 0x1206);
Return;
end