I gave boar shape player tool1 on its hide and tried to script it so that the boar will jump toward the target in three increments. However, the boar kicks up dust, says Oink!, and runs toward the target and attacks it - no jumping/teleporting.
This is the first time I've attempted any use of vectors before, so I'm not sure if the problem is with them or with the actions at the end of the script.
void main()
{
object oPC = OBJECT_SELF;
object oTarget = GetSpellTargetObject();
//---------------------- condition 1
if( oTarget == oPC ) {
SendMessageToPC(oPC,"Select a target to charge other than yourself.");
return;
}
//---------------------- condition 2
float fDist = GetDistanceBetween(oPC,oTarget);
if( fDist > 20.0 ) {
FloatingTextStringOnCreature("Get closer to charge.",oPC,FALSE);
return;
}
if( fDist < 6.0 ) {
FloatingTextStringOnCreature("You are too close to charge.",oPC,FALSE);
return;
}
fDist = fDist - 1.0; //subtract 1 so that we don't end up trying to teleport on top of the target
//---------------------- condition 3
vector vTarget = GetPosition(oTarget);
vector vPC = GetPosition(oPC);
if( !LineOfSightVector(vPC,vTarget) ) {
FloatingTextStringOnCreature("You must have line of sight to charge.",oPC);
return;
}
ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectVisualEffect(460),oPC);
string sOink;
switch( d3() )
{
case 1: sOink = "Oink!"; break;
case 2: sOink = "Snort!"; break;
default: sOink = "Squeel!"; break;
}
FloatingTextStringOnCreature(sOink,oPC);
SetFacingPoint(vTarget);
float fFacing = GetFacing(OBJECT_SELF);
location lTarget = GetLocation(oTarget);
location lTarget1;
location lTarget2;
location lTarget3;
//fDist is the distance to the target - 1.0.
//Determine the X and Y components of that direction and set its magnitude to 1/3 of fDist
float fX = cos(fFacing)*fDist/3;
float fY = sin(fFacing)*fDist/3;
//The X and Y components to the X and Y components of the PC position vector and create a new location*3
vPC.x = vPC.x + fX;
vPC.y = vPC.y + fY;
lTarget1 = Location( GetAreaFromLocation(lTarget), vPC, fFacing );
vPC.x = vPC.x + fX;
vPC.y = vPC.y + fY;
lTarget2 = Location( GetAreaFromLocation(lTarget), vPC, fFacing );
vPC.x = vPC.x + fX;
vPC.y = vPC.y + fY;
lTarget3 = Location( GetAreaFromLocation(lTarget), vPC, fFacing );
//Now jump to each location in rapid succession and attack!
ActionJumpToLocation(lTarget1);
ActionJumpToLocation(lTarget2);
ActionJumpToLocation(lTarget3);
ActionAttack(oTarget);
ActionDoCommand(SetCommandable(TRUE));
SetCommandable(FALSE);
}
At one point, I reversed the order of the actions and it gave amusing behavior.
ActionAttack(oTarget);
//Now jump to each location in rapid succession and attack!
ActionJumpToLocation(lTarget3);
ActionJumpToLocation(lTarget2);
ActionJumpToLocation(lTarget1);
The boar would run to the target, attack it, then jump backwards. That led me to believe my vector math and the locations I created from them were right, but the issue is with the actions. I appreciate any help.