// ZZ> This function makes an item fall to the floor when spawned
IfSpawned
  GetContent
  SetState
  IfStateIs0
    GetState
  Else
    // Start sprung
    tmpargument = 2
    SetState
    tmpargument = ACTIONUA
    DoActionOverride
  KeepAction
  MakeCrushValid
  MakeAmmoKnown
  // Don't activate right away
  tmpargument = 100
  SetTime


IfCrushed
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  tmpargument = 0
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  GoPoof
  tmpargument = 1
  SendMessageNear


IfDropped
  // Unhidden, used state
  tmpargument = 2
  SetState
  tmpargument = ACTIONUA
  DoActionOverride
  KeepAction
  SetTargetToSelf
  StopTargetMovement


// Lay a trap
IfUsed
  tmpargument = 40
  SetReloadTime
  tmpx = 0
  tmpy = 1
  tmpargument = [TECH]
  IfTargetHasSkillID
    tmpx = 1
  tmpargument = [DISA]
  IfTargetHasSkillID
    tmpx = 1
  IfXIsEqualToY  // Has either [TECH] or [DISA] skill
    tmpargument = ACTIONMG
    TargetDoAction

    // Drop one
    tmpx = targetx
    tmpy = targety
    tmpturn = targetturn
    tmpdistance = 30
    Compass
    tmpdistance = targetz + 15
    tmpturn = rand
    SpawnCharacterXYZ
      // Make the new one have 1 ammo
      tmpargument = 1
      SetChildAmmo


      // Down the ammo
      CostAmmo
      IfAmmoOut
        GoPoof

      // Tell the player
      tmpargument = 5
      SendMessageNear
    Else
      // Couldn't spawn...  Tell player to step back
      tmpargument = 10
      SendMessageNear
  Else
    tmpargument = 6
    SendMessageNear


// Tell them what they've won...
IfGrabbed
  SetTargetToWhoeverIsHolding
  IfStateIs0
    // Grabbing an active trap
    tmpx = 0
    tmpy = 1
    tmpargument = [TECH]
    IfTargetHasSkillID
      tmpx = 1
    tmpargument = [DISA]
    IfTargetHasSkillID
      tmpx = 1
    IfXIsEqualToY  // Has either [TECH] or [DISA] skill
      tmpargument = 7
      SendMessageNear
      tmpargument = 1
      SetState
    Else
      IfTargetIsAPlayer
        tmpargument = 8
        SendMessageNear
      DetachFromHolder
      tmpargument = 2
      SetState
      tmpargument = ACTIONUA
      DoActionOverride
      tmpargument = rand & 1023 + 1024 // 4-8 damage
      DamageTarget
      EnchantTarget
      StopTargetMovement
      SetTargetToSelf
      StopTargetMovement
      tmpargument = 0
      tmpdistance = 22050
      PlaySound
  Else
    UndoEnchant
      tmpargument = 9
      SendMessageNear
    Else
      IfTargetIsAPlayer
        tmpargument = 0
        SendMessageNear
    // Hidden state
    tmpargument = 1
    SetState


IfHitGround				// Make a sound
  tmpargument = 1			  //
  tmpdistance = rand & 2047 + 10000	  //
  PlaySound				  //


IfNotDropped
  tmpargument = 2
  SendMessageNear


IfTakenOut
  SetTargetToWhoeverIsHolding
  IfTargetIsAPlayer
    tmpargument = 4
    SendMessageNear


IfNotPutAway
  tmpargument = 3
  SendMessageNear


// See if the trap is sprung
IfTimeOut
  tmpargument = 6
  SetTime
  IfStateIs0
    SetTargetToSelf
    SetOwnerToTarget
    SetTargetToNearestLifeform
      SetTargetToLowestTarget
      IfTargetIsFlying
        GetState  // NOP
      Else
        // Does it have legs?
        tmpargument = [XLEG]
        IfTargetHasAnyID
          // No legs...
          GetState  // NOP
        Else
          // Got legs
          tmpx = targetdistance
          tmpy = 35
          IfXIsLessThanY
            tmpx = selfz + 10
            tmpy = targetz
            IfXIsMoreThanY
              tmpargument = 2
              SetState
              tmpargument = ACTIONUA
              DoActionOverride
              tmpargument = rand & 1023 + 512 // 2-6 damage
              DamageTarget
              EnchantTarget
              StopTargetMovement
              tmpargument = 0
              tmpdistance = 22050
              PlaySound


// All Done
End
