void main()
{

object oPC = GetPCSpeaker();
object oTarget;

int nInt = GetLocalInt(oPC, "CurtainSide");
int nRND = d6();
int nDMG = d6();
int nMOD = GetAbilityModifier(ABILITY_STRENGTH, oPC);
if (nMOD < 1) nMOD = 1;
int nDEX = GetAbilityScore(oPC, ABILITY_DEXTERITY);
int nAdj;

if (nDEX < 9) nAdj = ((9 - nDEX)*5);
if (nDEX > 12) nAdj = ((12 - nDEX)*5);
int nFall = (50 + nAdj);
int nBase = d100();

effect eDamage = EffectDamage(nDMG, DAMAGE_TYPE_BLUDGEONING, DAMAGE_POWER_NORMAL);
effect eKnock = EffectKnockdown();
effect eDazed = EffectDazed();

object oEnemy;
int i;
int nEnemyType = d4();
int nEnemy;
string sCreature;
if (nEnemyType == 1)
 {
 nEnemy = 6;
 sCreature = "gnoll_curtain";
 }
else if (nEnemyType == 2)
 {
 nEnemy = 6;
 sCreature = "bugbear_curtain";
 }
else if (nEnemyType == 3)
 {
 nEnemy = 4;
 sCreature = "ogre_curtain";
 }
else if (nEnemyType == 4)
 {
 nEnemy = 3;
 sCreature = "gargoyle_curtain";
 }

if (nMOD < nRND)
 {
 ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC);
 ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eKnock, oPC, 5.0f);
 FloatingTextStringOnCreature("Ouch! Your strength has failed you!  In fact, that attempt almost knocked you out...", oPC);
 }

else
 {
 if (nInt == 1)
  {
  //Teleport to Side 2
  oTarget=GetFirstFactionMember(oPC, FALSE);
  while (GetIsObjectValid(oTarget))
   {
   AssignCommand(oTarget, ClearAllActions());
   AssignCommand(oTarget, ActionJumpToLocation(GetLocation(GetObjectByTag("WP_Curtain2"))));
   DelayCommand(0.25, AssignCommand(oTarget, SetFacingPoint(GetPosition(GetObjectByTag("WP_Curtain2Face")))));
   oTarget=GetNextFactionMember(oPC, FALSE);
   }
  if (nFall < nBase)
   {
   //PC falls down & is dazed
   DelayCommand(0.3, AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_DEAD_FRONT, 1.0f, 3.0f)));
   DelayCommand(3.5, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDazed, oPC, 5.0f));
   }
  // Create the monster(s) at the PC's location and spawn as many
  // monsters at that location as is dictated by nEnemy
  for (i = 1; i < (nEnemy+1); i++)
   {
   oEnemy = CreateObject(OBJECT_TYPE_CREATURE, sCreature, GetLocation(GetObjectByTag("WP_Curtain2Face")), FALSE);
   }
  FloatingTextStringOnCreature("You have been ambushed!", oPC);
  //end conditional
  }

 if (nInt == 2)
  {
  //Teleport to Side 1
  oTarget=GetFirstFactionMember(oPC, FALSE);
  while (GetIsObjectValid(oTarget))
   {
   AssignCommand(oTarget, ClearAllActions());
   AssignCommand(oTarget, ActionJumpToLocation(GetLocation(GetObjectByTag("WP_Curtain1"))));
   DelayCommand(0.25, AssignCommand(oTarget, SetFacingPoint(GetPosition(GetObjectByTag("WP_Curtain1Face")))));
   oTarget=GetNextFactionMember(oPC, FALSE);
   }
  if (nFall < nBase)
   {
   //PC falls down & is dazed
   DelayCommand(0.3, AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_DEAD_FRONT, 1.0f, 5.0f)));
   DelayCommand(0.3, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDazed, oPC, 5.0f));
   }
  // Create the monster(s) at the PC's location and spawn as many
  // monsters at that location as is dictated by nEnemy
  for (i = 1; i < (nEnemy+1); i++)
   {
   oEnemy = CreateObject(OBJECT_TYPE_CREATURE, sCreature, GetLocation(GetObjectByTag("WP_Curtain1Face")), FALSE);
   }
  FloatingTextStringOnCreature("You have been ambushed!", oPC);
  //end conditional
  }

 }

}

