//-------------------------------------------------------------------------------
// Set up general stuff
IfSpawned
  tmpargument = ACTIONJB
  DoAction
  KeepAction
  MakeCrushValid
  MakeAmmoKnown

//-------------------------------------------------------------------------------
// Make it poof
IfCrushed
  tmpx = selfx
  tmpy = selfy
  tmpdistance = selfz
  tmpargument = 0
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  SpawnExactParticle
  GoPoof
  tmpargument = 1
  SendMessageNear

//-------------------------------------------------------------------------------
// Make it lie on the floor
IfDropped
  KeepAction

//-------------------------------------------------------------------------------
// Play a clink or clang
IfHitGround
  tmpargument = 0
  PlaySound

//-------------------------------------------------------------------------------
// Alert others to draw
IfTakenOut
  SetTargetToWhoeverIsHolding
  IfTargetIsAPlayer
    tmpargument = 2
    SendMessageNear

//-------------------------------------------------------------------------------
// Tell them what they've won...
IfGrabbed
  SetTargetToWhoeverIsHolding
  IfTargetIsAPlayer
    tmpargument = 0
    SendMessageNear

//-------------------------------------------------------------------------------
// Give the user a bonus, but it's addictive...
IfUsed
  SetTargetToWhoeverIsHolding
  tmpx = 0
  tmpargument = [WMAG] // If an Arcane magic user
  IfTargetHasSkillID
    tmpx = 1
  
  tmpargument = [HMAG] // If a Divine magic user
  IfTargetHasSkillID
    tmpx = 1
  
  //Spellcasters gain mana
  tmpy = 1
  IfXIsEqualToY
    IfTargetHasNotFullMana
      //Standard drinking stuff
      tmpargument = ACTIONMC
      TargetDoAction
      tmpdistance = SPAWNORIGIN
      tmpargument = 1
      SpawnAttachedHolderParticle
      
      tmpargument = 40
      SetReloadTime        

      //Messages
      IfUsageIsKnown
        tmpargument = 3
        SendMessageNear
      Else
        MakeSimilarNamesKnown
        MakeUsageKnown
        tmpargument = 4
        IfTargetIsAPlayer
          tmpargument = 5
        SendMessageNear
        tmpargument = 40
        tmpdistance = EXPDARE
        GiveExperienceToTarget
      
      //Normal potion
      tmpargument = 0
      IfArmorIs
        // Decrease max mana a little
        tmpargument = 0 - 32		      
        GiveManaToTarget

        // Increase current mana
        tmpargument = rand % 2047 + 2048	//Amount of mana gained
        PumpTarget
        
        //Do flashy effects      
        tmpargument = 1
        PlaySound      
      
      //Super potion
      tmpargument = 1
      IfArmorIs

        // Heal all damage
        tmpargument = 256*50	//Amount of mana gained
        PumpTarget

        //Do flashy effects      
        tmpargument = 2
        PlaySound
        
      
      //Use a potion
      CostAmmo
      IfAmmoOut
        GoPoof

    Else
      tmpx = selfx	//Where to spawn the object
      tmpy = selfy
      tmpturn = selfturn
      tmpdistance = 0	//Velocity speed of the spawned object
      SpawnCharacter	//Spawn a copy of the flask
        tmpargument = 40
        SetReloadTime
        CostAmmo
        IfAmmoOut
          GoPoof
        tmpargument = 1
        SetChildAmmo
        IfNameIsKnown
          SetChildState     //Remember that it is identified already
  Else
    tmpargument = 6 // If you're not a magic user, it tastes nasty, for some reason.
    SendMessageNear // That's magic for you, I suppose...
    tmpargument = 7
    SendMessageNear
    
    //Bravery/foolishness is rewarded
    tmpargument = 40
    tmpdistance = EXPDARE
    GiveExperienceToTarget  

    //Standard drinking stuff
    tmpargument = ACTIONMC
    TargetDoAction
    tmpdistance = SPAWNORIGIN
    tmpargument = 1
    SpawnAttachedHolderParticle
    CostAmmo    
    tmpargument = 1
    SpawnAttachedHolderParticle
    CostAmmo
    IfAmmoOut
      GoPoof
    tmpargument = 1
    PlaySound
    tmpargument = 40
    SetReloadTime


//-------------------------------------------------------------------------------
//Allow to become a super potion
tmpargument = 0
IfArmorIs
  IfOrdered
    tmpx = selforder
    tmpy = [ENCH]
    IfXIsEqualToY
      tmpargument = 1
      ChangeArmor
      tmpargument = BLUE
      SparkleIcon
      
//This make super potions sparkle
Else
  tmpx = rand & 2
  tmpy = 0
  IfXIsEqualToY
    tmpargument = 2
    tmpx = rand % 50 - 25
    tmpy = rand % 50 - 25
    tmpdistance = rand & 31
    SpawnParticle
  
//-------------------------------------------------------------------------------
// Finish up
End
//-------------------------------------------------------------------------------

