Author Topic: Please help with my (teleporting) charging boar  (Read 312 times)

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Please help with my (teleporting) charging boar
« on: April 02, 2014, 07:13:22 am »


               

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.

 



               
               

               
            

Legacy_ruadhri10

  • Jr. Member
  • **
  • Posts: 52
  • Karma: +0/-0
Please help with my (teleporting) charging boar
« Reply #1 on: April 02, 2014, 08:43:14 am »


               

Movement and combat clear the action queue, I'm afraid (http://nwn.wikia.com/wiki/Action_queue).


 


I haven't thought of any easy solutions to your dilemma, other than wrapping your ActionAttack in a DelayCommand(0.2,(ActionAttack(oTarget));



               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Please help with my (teleporting) charging boar
« Reply #2 on: April 02, 2014, 05:23:33 pm »


               

I see.  That helps a lot.


 


Using DelayCommand(0.2,ActionAttack(oTarget)); allows the teleporting behavior to work correctly, but it doesn't attack at the end.  Still, you got me past where I was stuck.  Now I can play with it more.



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Please help with my (teleporting) charging boar
« Reply #3 on: April 02, 2014, 09:50:29 pm »


               After the moves, you could try ActionDoCommand(my_function()), where my_function() issues the ActionAttack. IIRC that queues the ActionAttack at exactly the right time.