state script_example_on

ifvare SWITCHSCRIPTID 1 // NRSCRIPT.MAP - Starts the Rotating Gear
{
 setvar TEMPVAR 2
 setsector[TEMPVAR].lotag 3

 setvar TEMPVAR 24
 setactor[TEMPVAR].x 28032
 setactor[TEMPVAR].y 33536
 setactor[TEMPVAR].z 8192
 setactor[TEMPVAR].sectnum 1

 setvar TEMPVAR 3
 setactor[TEMPVAR].x 28032
 setactor[TEMPVAR].y 33088
 setactor[TEMPVAR].z 8192
 setactor[TEMPVAR].sectnum 1

 setvar TEMPVAR 4
 setactor[TEMPVAR].x 28032
 setactor[TEMPVAR].y 33088
 setactor[TEMPVAR].z 8192
 setactor[TEMPVAR].sectnum 1
}
ends

state script_example_off

ifvare SWITCHSCRIPTID 1 // NRSCRIPT.MAP - Stops the Rotating Gear
{
 setvar TEMPVAR 2
 setsector[TEMPVAR].lotag 0

 setvar TEMPVAR 24
 setactor[TEMPVAR].x 23744
 setactor[TEMPVAR].y 33504
 setactor[TEMPVAR].z 14336
 setactor[TEMPVAR].sectnum 3

 setvar TEMPVAR 3
 setactor[TEMPVAR].x 23744
 setactor[TEMPVAR].y 33504
 setactor[TEMPVAR].z 14336
 setactor[TEMPVAR].sectnum 3

 setvar TEMPVAR 4
 setactor[TEMPVAR].x 23744
 setactor[TEMPVAR].y 33504
 setactor[TEMPVAR].z 14336
 setactor[TEMPVAR].sectnum 3
}
ends

define SCRIPTSWITCH 7445

action SCRIPTSWITCHOFF
action SCRIPTSWITCHON 1

eventloadactor SCRIPTSWITCH
 getactor[THISACTOR].lotag SWITCHSCRIPTID // The Lotag is the number of the script to play when the switch is flipped
 addlogvar SWITCHSCRIPTID
enda

useractor notenemy SCRIPTSWITCH 0
 ifvare SKILLSET? 0
 {
  action SCRIPTSWITCHOFF
  setvar SKILLSET? 1
 }
 state useswitchcheckwall
 setvar OBJECTWIDTH 32
 setvar OBJECTHEIGHT 32
 state getspritecenterz
 setvarvar KEYSCANNERZUP OBJECTCENTERZ
 subvarvar KEYSCANNERZUP OBJECTDIFF2
 setvarvar KEYSCANNERZDOWN OBJECTCENTERZ
 addvarvar KEYSCANNERZDOWN OBJECTDIFF2

 ifpdistl 1024
 {
  ifvare TEMP2 1
  {
   ifp pfacing
   {
    ifhitspace
    {
     ifcansee 
     {
      getactor[PLAYERID].z temp
      subvar temp 6144
      ifvarvarg temp KEYSCANNERZUP
      ifvarvarl temp KEYSCANNERZDOWN
      ifvare com_pause 0 // There are lot of conditions on this line. The last one is there to ensure proper timing. 
      { 
       ifaction SCRIPTSWITCHOFF
       {
        sound SWITCH_ON
        state script_example_on
        action SCRIPTSWITCHON
       }
       else
       ifaction SCRIPTSWITCHON
       {
        sound SWITCH_ON
        state script_example_off
        action SCRIPTSWITCHOFF
       }
       setvar com_pause 10
      }
     }
    }
   }
  }
 }
enda

