//-----------------------------------------------------------------------------------
//Egoboo only supports 4 different skins, so I use a trick here to make a fifth
IfSpawned
  tmpargument = 1
  IfContentIs
    tmpargument = 2		//This is blue (water palace)
    SetRedShift
    SetGreenShift

  //Make sure it's down
  tmpargument = ACTIONMJ
  DoAction
    KeepAction			      // Make it stay on last frame
    tmpargument = 10
    SetBumpHeight

  //Content decides which type button it is and which spork
  GetContent
  SetState	
  
//ORDER OF PALACES
//0 Sand
//1 Water
//2 Shadow
//3 Ash
//4 Ice

//-----------------------------------------------------------------------------------
//This function makes the button open the passage
tmpx = 20				// Threshold weight
tmpy = weight				// Weight of characters on top
IfXIsLessThanY				// Open it
  SetTargetToWhoeverBumped

    //Automatically unlock if the player already has beaten this module
    tmpargument = [MAIN]
    IfTargetHasQuest
      tmpturn = 4
      IfDistanceIsMoreThanTurn
        tmpargument = [SPOR]
        IssueOrder
        tmpargument = 5
        SendMessageNear				//Tell them it's in place
        tmpargument = ACTIONMG
        DoAction
        KeepAction			      // Make it stay on last frame
        tmpargument = 0
        SetBumpHeight
        tmpargument = 55			//Spawn a fake spork
        tmpx = selfx
        tmpy = selfy
        tmpdistance = selfz
        SpawnExactCharacterXYZ
        tmpargument = selfstate		//Set the skin for the spawned spork
        SetChildState
        tmpdistance = selfz + 50		//Do some shiny effects
        tmpx = selfx
        tmpy = selfy
        SpawnExactParticle
        SpawnExactParticle
        SpawnExactParticle
        PlaySound
        tmpargument = 5
        SetState
      Else
        IfStateIs0
          tmpargument = [SPOW]	//Water spork
        IfStateIs1
          tmpargument = [SPOS]	//Sand
        IfStateIs2
          tmpargument = [SPOA]	//Ash
        IfStateIs3
          tmpargument = [SPOD]	//Shadow
        IfStateIs4
          tmpargument = [SPOI]	//Ice
        CostTargetItemID			  // Check for Spork type
        
//Commented script checks for quest instead of actual physical spork
//  IfTargetIsAPlayer
      //Only check for sporks if one isnt already added
//    tmpargument = 5
//    IfStateIsNot   
        //Check if target has the spork
//      tmpargument = [MAIN]
//      IfTargetHasQuest        
//        tmpx = tmpdistance
//        tmpy = selfcontent
//        IfXIsLessThanY
//          DoNothing
//        Else
          
          tmpargument = [SPOR]
          IssueOrder
          tmpargument = 10
          tmpdistance = EXPSECRET
          GiveExperienceToTarget
          tmpargument = 5
          SendMessageNear				//Tell them it's in place

          // Make it stay on last frame
          tmpargument = ACTIONMG
          DoAction
          KeepAction
          tmpargument = 0
          SetBumpHeight

          //Spawn a fake spork
          tmpargument = 55
          tmpx = selfx
          tmpy = selfy
          tmpdistance = selfz
          SpawnExactCharacterXYZ
          tmpargument = selfstate		//Set the skin for the spawned spork
          SetChildState

          //Do some shiny effects
          tmpdistance = selfz + 50
          tmpx = selfx
          tmpy = selfy
          SpawnExactParticle
          SpawnExactParticle
          SpawnExactParticle
          PlaySound

          //Dont do this again
          tmpargument = 5
          SetState
    
      //Tell what is missing
      tmpargument = 5
      IfStateIsNot
        IfTimeOut
          tmpargument = selfstate
          SendMessageNear
          tmpargument = 100
          SetTime
      
End					// Finished with this character
