Advertisement
henesua

aa_s0_passdoor

Feb 2nd, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.98 KB | None | 0 0
  1. //::///////////////////////////////////////////////
  2. //:: aa_s0_passdoor
  3. //:://////////////////////////////////////////////
  4. /*
  5.     Spell Script for Pass Door
  6.  
  7.     Transports caster to the door's destination or the otherside of the door
  8.  
  9.     Thanks to LightFoot8 for providing the function: RunRatUnderDoor
  10.     http://social.bioware.com/forum/1/topic/192/index/9060079#9063589
  11. */
  12. //:://////////////////////////////////////////////
  13. //:: Created By: The Magus (2012 jan 24)
  14. //:: Modified:
  15. //:://////////////////////////////////////////////
  16.  
  17. #include "aa_inc_constants"
  18.  
  19. #include "x2_inc_spellhook"
  20. //#include "x0_i0_position"
  21.  
  22.  
  23. void RunRatUnderDoor(object oRat, object oDoor)
  24. {
  25.    // Get the posistion for the rat.
  26.    vector vRat = GetPosition(oRat);
  27.  
  28.    // Get the position for the door
  29.    vector vDoor = GetPosition(oDoor);
  30.  
  31.    // Subtract the position of the rat from the position of the door.
  32.    // To get the vector representing the position of the rat from the door.
  33.    // basicly what we are doing is both the rat and the door have (X,Y) positions
  34.    // (Rx,Ry) and (Dx,Dy)
  35.    // if we subtract the position of the rat from both of them in effect moving
  36.    // the line segment to where the rat is at cords (0,0) the
  37.    // (Rx,Ry) - (Rx,Ry) =  (0,0)
  38.    // (Dx,Dy) - (Rx-Ry) =  (Dx-Rx,Dy-Ry)
  39.    // in effect moving the line segment to where the rat is at cords (0,0) the
  40.    // the (Dx-Rx,Dy-Ry) Is in effect the vector showing both distance and
  41.    //Direction that the door is from the rat.
  42.    vector vDoorFromRat = vDoor-vRat;
  43.  
  44.    //To get the position 1 unit beyond the door in a stright line from where
  45.    // the rat currently is, all we have to do is normilize the vector and add
  46.    // it to the position of the door.
  47.    vector vPastDoor1M = vDoor + VectorNormalize(vDoorFromRat);
  48.  
  49.    //Build a location with the new vector and have the rat face in the same
  50.    //Direction that the door was from him. .
  51.    location lPastDoor = Location(
  52.                                    GetArea(oRat),
  53.                                    vPastDoor1M,
  54.                                    VectorToAngle(vDoorFromRat)
  55.                                  );
  56.  
  57.    // Clear rats action que
  58.    AssignCommand(oRat,ClearAllActions(TRUE));
  59.  
  60.    //Run to the door
  61.    AssignCommand(oRat,ActionMoveToObject(oDoor,TRUE));
  62.  
  63.    //Lay flat
  64.    AssignCommand(oRat,ActionPlayAnimation( ANIMATION_LOOPING_GET_LOW,1.0,2.0));
  65.  
  66.    // Squezze under.
  67.    AssignCommand(oRat,ActionJumpToLocation(lPastDoor));
  68.  
  69. }
  70.  
  71.  
  72. void main()
  73. {
  74.     /*
  75.       Spellcast Hook Code
  76.       check x2_inc_spellhook.nss to find out more
  77.     */
  78.     if (!X2PreSpellCastCode())
  79.     {
  80.         // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
  81.         return;
  82.     }
  83.  
  84.     // End of Spell Cast Hook
  85.  
  86.     //  object oCaster = GetLastSpellCaster();
  87.     object oCaster  = OBJECT_SELF;
  88.     object oDoor    = GetSpellTargetObject();
  89.     if ( !GetIsObjectValid(oCaster) || GetObjectType(oDoor)!= OBJECT_TYPE_DOOR)
  90.     {
  91.         return;
  92.     }
  93.  
  94.     if(GetIsOpen(oDoor))
  95.     {
  96.         SendMessageToPC(oCaster, RED+"The door is open. Try walking through it instead.");
  97.         return;
  98.     }
  99.     else if(GetLockKeyRequired(oDoor) || GetLocalInt(oDoor,"MAGIC") || GetLocalInt(oDoor,"NO_PASS"))
  100.     {
  101.         SendMessageToPC(oCaster, DMBLUE+"You are unable to find an opening to pass through.");
  102.         return;
  103.     }
  104.  
  105.  
  106.     object oDest    = GetTransitionTarget(oDoor);
  107.  
  108.     if(GetIsObjectValid(oDest))
  109.     {
  110.         AssignCommand(oCaster, ClearAllActions(TRUE) );
  111.         AssignCommand(oCaster, ActionMoveToObject(oDoor,TRUE) );
  112.         AssignCommand(oCaster, ActionPlayAnimation( ANIMATION_LOOPING_GET_LOW,1.0,2.0) );
  113.  
  114.         if(GetObjectType(oDest)== OBJECT_TYPE_DOOR)
  115.         {
  116.             vector vDoor = GetPosition(oDest);
  117.             location lPastDoor = Location(
  118.                                 GetArea(oDest),
  119.                                 vDoor+VectorNormalize(vDoor),
  120.                                 GetFacing(oDest)
  121.                             );
  122.             AssignCommand(oCaster, ActionJumpToLocation(lPastDoor) );
  123.         }
  124.         else
  125.             AssignCommand(oCaster, ActionJumpToObject(oDest) );
  126.  
  127.     }
  128.     else
  129.     {
  130.         /*
  131.         float fFace     = GetFacing(oDoor);
  132.         location lDoorF = GenerateNewLocation(oDoor, 1.0,
  133.                                fFace, fFace
  134.                                );
  135.         location lDoorR = GenerateNewLocation(oDoor, 1.0,
  136.                                GetNormalizedDirection(fFace+180.0), fFace
  137.                                );
  138.         location lPC    = GetLocation(oCaster);
  139.  
  140.         if(GetDistanceBetweenLocations(lDoorF,lPC)>GetDistanceBetweenLocations(lDoorR,lPC))
  141.         {
  142.             ClearAllActions();
  143.             ActionJumpToLocation( lDoorF );
  144.         }
  145.         else
  146.         {
  147.             ClearAllActions();
  148.             ActionJumpToLocation( lDoorR );
  149.         }
  150.         */
  151.         RunRatUnderDoor(oCaster, oDoor);
  152.     }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement