henesua

v2_trg_en_brambl

Apr 20th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.93 KB | None | 0 0
  1. //::///////////////////////////////////////////////
  2. //:: v2_trg_en_brambl
  3. //:://////////////////////////////////////////////
  4. /*
  5.     intended for use in a trigger's onenter event
  6.     which slows the creature as they lumber through the undergrowth.
  7. */
  8. //:://////////////////////////////////////////////
  9. //:: Created:   The Magus (2012 mar 4)
  10. //:://////////////////////////////////////////////
  11. //:: Modified:  Henesua (2013 dec 7) updating for vives
  12.  
  13. #include "v2_inc_constants"
  14. #include "v2_inc_creatures"
  15. #include "v2_inc_spell"
  16.  
  17. void main()
  18. {
  19.     object oCreature   = GetEnteringObject();
  20.  
  21.     // avoidance
  22.     if(     !GetIsObjectValid(oCreature)
  23.         ||  GetIsFlying(oCreature) // if already flying... return
  24.         ||  GetIsDM(oCreature)
  25.       )
  26.         return;
  27.  
  28.     string sSnd     = "as_na_grassmove1";
  29.     int bGrass      = GetLocalInt(OBJECT_SELF, "GRASS");
  30.     int nStealth    = GetStealthMode(oCreature);
  31.     int bImmune;
  32.     int bIncorp     = GetLocalInt(oCreature,"X2_L_IS_INCORPOREAL");
  33.     // immunity
  34.     if(     GetHasSpellEffect(SPELL_FREEDOM_OF_MOVEMENT, oCreature)
  35.         ||  GetHasFeat(FEAT_WOODLAND_STRIDE, oCreature)
  36.         ||  GetHasSpellEffect(SPELL_STEADY_STRIDE, oCreature)
  37.         ||  bIncorp
  38.       )
  39.     {
  40.         bImmune = TRUE;
  41.     }
  42.  
  43.     int nSize   = GetCreatureSize(oCreature);
  44.     int nSlow   = 50;
  45.     int nRace   = GetRacialType(oCreature);
  46.     int nConceal, nHide, nMissChance;
  47.  
  48.     switch (nSize)
  49.     {
  50.         case CREATURE_SIZE_TINY:
  51.             bImmune     = TRUE;
  52.             nConceal    = 50;
  53.             nMissChance = MISS_CHANCE_TYPE_NORMAL;
  54.             nHide       = 127;
  55.         break;
  56.         case CREATURE_SIZE_SMALL:
  57.             if(     nRace==RACIAL_TYPE_ANIMAL
  58.                 ||  nRace==RACIAL_TYPE_BEAST
  59.                 ||  nRace==RACIAL_TYPE_MAGICAL_BEAST
  60.               )
  61.                 bImmune=TRUE;
  62.             nSlow      -= 25;
  63.             nConceal    = 30;
  64.             nMissChance = MISS_CHANCE_TYPE_VS_RANGED;
  65.             nHide       = 4;
  66.         break;
  67.         case CREATURE_SIZE_MEDIUM:
  68.             nConceal    = 15;
  69.             nMissChance = MISS_CHANCE_TYPE_VS_RANGED;
  70.             nHide       = 2;
  71.         break;
  72.         case CREATURE_SIZE_LARGE:
  73.             nSlow += 10;
  74.         break;
  75.         case CREATURE_SIZE_HUGE:
  76.             nSlow -= 25;
  77.         break;
  78.         default:
  79.  
  80.         break;
  81.     }
  82.  
  83.     // TALL GRASS - Move more quickly than through brambles
  84.     if(bGrass)
  85.         nSlow -= 20;
  86.  
  87.     // strength perk
  88.     nSlow   += GetAbilityModifier(ABILITY_STRENGTH, oCreature)*-2;
  89.  
  90.     // escape artist perk
  91.     if((d20()+GetSkillRank(SKILL_ESCAPE_ARTIST, oCreature)-GetArmorCheckPenalty(oCreature))>=20)
  92.         nSlow = FloatToInt(nSlow/2.0);
  93.  
  94.     if (nSlow < 1)
  95.         nSlow = 0;
  96.     else if (nSlow > 99)
  97.         nSlow = 99;
  98.  
  99.     int nPenalty;
  100.     if (nSlow >79)
  101.     {
  102.         nPenalty= 5;
  103.     }
  104.     else if (nSlow > 59)
  105.     {
  106.         nPenalty= 4;
  107.     }
  108.     else if (nSlow > 39)
  109.     {
  110.         nPenalty= 3;
  111.     }
  112.     else if (nSlow > 19)
  113.     {
  114.         nPenalty= 2;
  115.     }
  116.     else if (nSlow > 0)
  117.     {
  118.         nPenalty= 1;
  119.     }
  120.  
  121.     if(!bGrass)
  122.     {
  123.       switch(d4())
  124.       {
  125.         case 4: sSnd    = "as_na_leafmove1"; break;
  126.         case 3: sSnd    = "as_na_leafmove2"; break;
  127.         case 2: sSnd    = "as_na_leafmove3"; break;
  128.         case 1: sSnd    = "as_na_bushmove1"; break;
  129.         default: sSnd   = "as_na_bushmove2"; break;
  130.       }
  131.     }
  132.     else
  133.     {
  134.       switch(d2())
  135.       {
  136.         case 2: sSnd    = "as_na_grassmove2"; break;
  137.         case 1: sSnd    = "as_na_grassmove1"; break;
  138.         default: sSnd   = "as_na_grassmove1"; break;
  139.       }
  140.     }
  141.  
  142.     effect eSlow    = EffectMovementSpeedDecrease(nSlow);
  143.     effect eHampered= EffectLinkEffects(EffectSavingThrowDecrease(SAVING_THROW_REFLEX, nPenalty), EffectACDecrease(nPenalty));
  144.     effect eLink;
  145.  
  146.     effect eConceal = EffectLinkEffects(EffectConcealment(nConceal, nMissChance),EffectSkillIncrease(SKILL_HIDE, nHide));
  147.  
  148.     if (nPenalty > 0)
  149.         eLink=EffectLinkEffects(eHampered,eSlow);
  150.     else
  151.         eLink = eSlow;
  152.  
  153.     if(nStealth!=STEALTH_MODE_ACTIVATED && !bIncorp)
  154.     {
  155.         float fDelay;
  156.         object oSound   = GetLocalObject(OBJECT_SELF, "SOUND_OBJECT");
  157.         if(!GetIsObjectValid(oSound))
  158.         {
  159.             fDelay      = 0.1;
  160.             oSound      = CreateObject(OBJECT_TYPE_PLACEABLE, "sound_player", GetLocation(OBJECT_SELF));
  161.             SetLocalObject(OBJECT_SELF, "SOUND_OBJECT", oSound);
  162.         }
  163.         DelayCommand(fDelay, AssignCommand(oSound, PlaySound(sSnd) ) );
  164.         //AssignCommand(oCreature, PlaySound(sSnd) );
  165.         //PlaySound(sSnd);
  166.     }
  167.     if(!bImmune)
  168.         ApplyEffectToObject(DURATION_TYPE_PERMANENT, eLink, oCreature);
  169.     if(nConceal)
  170.         ApplyEffectToObject(DURATION_TYPE_PERMANENT, eConceal, oCreature);
  171.     SetLocalInt(oCreature, "BRAMBLE", TRUE);
  172. }
Advertisement
Add Comment
Please, Sign In to add comment