View difference between Paste ID: 7j85siTf and Wt2mj0tE
SHOW: | | - or go back to the newest paste.
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) );
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
            vector vNewPos;
118
            float fFace = GetFacing(oDest);
119-
                                vDoor+VectorNormalize(vDoor),
119+
120-
                                GetFacing(oDest)
120+
            if (fFace<180.0)
121
                fFace=fFace+179.9;
122
            else
123
                fFace=fFace-179.9;
124
125
            vNewPos.z = vDoor.z;
126
            vNewPos.x = vDoor.x + GetChangeInX(1.0, fFace);
127
            if (vNewPos.x < 0.0)
128
                vNewPos.x = - vNewPos.x;
129
            vNewPos.y = vDoor.y + GetChangeInY(1.0, fFace);
130
            if (vNewPos.y < 0.0)
131
                vNewPos.y = - vNewPos.y;
132
133
            location lPastDoor = Location(
134
                                GetArea(oDest),
135
                                vNewPos,
136
                                fFace
137
                            );
138
            AssignCommand(oCaster, ActionJumpToLocation(lPastDoor) );
139
        }
140
        else
141
            AssignCommand(oCaster, ActionJumpToObject(oDest) );
142
143
    }
144
    else
145
    {
146
        /*
147
        float fFace     = GetFacing(oDoor);
148
        location lDoorF = GenerateNewLocation(oDoor, 1.0,
149
                               fFace, fFace
150
                               );
151
        location lDoorR = GenerateNewLocation(oDoor, 1.0,
152
                               GetNormalizedDirection(fFace+180.0), fFace
153
                               );
154
        location lPC    = GetLocation(oCaster);
155
156
        if(GetDistanceBetweenLocations(lDoorF,lPC)>GetDistanceBetweenLocations(lDoorR,lPC))
157
        {
158
            ClearAllActions();
159
            ActionJumpToLocation( lDoorF );
160
        }
161
        else
162
        {
163
            ClearAllActions();
164
            ActionJumpToLocation( lDoorR );
165
        }
166
        */
167
        RunRatUnderDoor(oCaster, oDoor);
168
    }
169
}