henesua

aa_door_open

May 20th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 KB | None | 0 0
  1. //::///////////////////////////////////////////////
  2. //:: aa_door_open
  3. //:://////////////////////////////////////////////
  4. /*
  5.     intended for use in a doors onopen event
  6. */
  7. //:://////////////////////////////////////////////
  8. //:: Created By: The Magus (2012 feb 7)
  9. //:: Modified:
  10. //:://////////////////////////////////////////////
  11.  
  12. #include "x2_inc_switches"
  13. #include "NW_I0_GENERIC"
  14.  
  15. #include "aa_inc_constants"
  16. #include "aa_inc_creatures"
  17. #include "aa_inc_time"
  18.  
  19. void main()
  20. {
  21.     int bClose, bLock   = FALSE;
  22.     object oCreature    = GetLastOpenedBy();
  23.     int bHandsRequired  = GetLocalInt(OBJECT_SELF, HANDS_TO_OPEN);
  24.     int bIncorporeal    = GetCreatureFlag(oCreature, CREATURE_VAR_IS_INCORPOREAL);
  25.  
  26.     // work around for the use of unidentified keys on a locked door
  27.     if(GetLocalInt(oCreature, "KEY_UNIDENTIFIED")<GetCurrentGameTime(FALSE, FALSE, FALSE, TRUE)+1300)
  28.     {
  29.         bClose = TRUE; bLock  = TRUE;
  30.     }
  31.     // some creatures do not need to open certain doors
  32.     else if( !GetLockKeyRequired(OBJECT_SELF) && !GetLocalInt(OBJECT_SELF,"MAGIC") && !GetLocalInt(OBJECT_SELF,"NO_PASS")
  33.         &&
  34.         (   bIncorporeal
  35.                 ||
  36.             GetHasFeat(FEAT_PASS_DOOR, oCreature)
  37.                 ||
  38.             GetIsSoftBodied(oCreature)
  39.         )
  40.       )
  41.     {
  42.         bClose = TRUE;
  43.         AssignCommand(oCreature,
  44.         ActionCastSpellAtObject(SPELL_ACT_PASSDOOR, OBJECT_SELF, METAMAGIC_ANY, TRUE, 0, PROJECTILE_PATH_TYPE_DEFAULT, TRUE)
  45.                 );
  46.     }
  47.     // some doors require the use of hands
  48.     else if( bHandsRequired
  49.                 &&
  50.              (bIncorporeal || !GetHasHands(oCreature))
  51.             )
  52.     {
  53.         bClose = TRUE;
  54.         if(GetIsPC(oCreature))
  55.             SendMessageToPC(oCreature, RED+"You need hands to open this door.");
  56.     }
  57.  
  58.     if(bClose)
  59.     {
  60.         object oDest = GetTransitionTarget(OBJECT_SELF);
  61.         int bDestDoor= GetObjectType(oDest)==OBJECT_TYPE_DOOR;
  62.         PlayAnimation(ANIMATION_DOOR_CLOSE);
  63.         if(bDestDoor)
  64.             AssignCommand(oDest, PlayAnimation(ANIMATION_DOOR_CLOSE));
  65.         if(bLock)
  66.         {
  67.             SetLocked(OBJECT_SELF,TRUE);
  68.             if(bDestDoor)
  69.                 DelayCommand(0.2, SetLocked(oDest,TRUE));
  70.             AssignCommand(oCreature, PlaySound("as_door_locked1"));
  71.             FloatingTextStringOnCreature(WHITE+"*Fumbles with the door*", oCreature);
  72.             SendMessageToPC(oCreature, "This object is locked.");
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment