// Each switch must be flipped in order. // I used the tag to get the order (1,2,3) and a localINT to indicate // where in the sequence we are. // Initial Version of this script was not multiplayer friendly // Modified 7/6/2002 // Changed localINT from PC to MODULE level to account for multiple // PCs interacting with the switches // Set variables at the head for easier configuration for number of // switches and names of light sources and invisible objects. //Change the following variables to reflect your module's needs // ------------------------------------------------------------------ //Max Number of switches int iMaxSwitches=5; //Invisible object tag base string sInvisibleObjectBase = "inv00"; //Light blueprint base string sLightBlueprintBase = "sol_"; //Light tag base string sLightTagBase = "LIGHT_"; //LocalINT title string sCurrentState = "WF_SWITCHES"; //Door to unlock when complete object oDoor = GetObjectByTag("AirDoor2"); // ------------------------------------------------------------------ void makelight(int lightnum) { CreateObject(OBJECT_TYPE_PLACEABLE,sLightBlueprintBase + IntToString(lightnum), GetLocation(GetObjectByTag(sInvisibleObjectBase+IntToString(lightnum),0))); DelayCommand(0.2, RecomputeStaticLighting(GetArea(GetObjectByTag(sLightTagBase + IntToString(lightnum))))); } void main() { object oPC=GetLastUsedBy(); //Read the stored state int iCurrentState = GetLocalInt(GetModule(),sCurrentState); //Find out which switch is being used int iUsedSwitch = StringToInt(GetSubString(GetTag(OBJECT_SELF),GetStringLength(GetTag(OBJECT_SELF))-1,1)); if (iCurrentState <= iMaxSwitches) { //Only do this if the sequence is not complete //If the current state is one less than the switch being pulled then if ((iCurrentState+1) == iUsedSwitch) { // Show switch activation AssignCommand(OBJECT_SELF, PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE)); // Turn related light on makelight(iUsedSwitch); // Store the sequence position SetLocalInt(GetModule(),sCurrentState,(iCurrentState+1)); AssignCommand(OBJECT_SELF, PlaySound("gui_dm_drop")); // Test for final Condition if (iUsedSwitch == iMaxSwitches) { // save the state showing the puzzle is finished SetLocalInt(GetModule(),sCurrentState,iMaxSwitches+1); // Put anything you want to happen when the puzzle is solved in this // section below. As is, it will unlock and open a door: // ------------------------------------------------------------------ // make the last light if any makelight(iMaxSwitches+1); // play a nice sound AssignCommand(OBJECT_SELF, PlaySound("gui_magbag_full")); //open our door SetLocked(oDoor, FALSE); AssignCommand(OBJECT_SELF, ActionOpenDoor(oDoor)); // Tell the PC about opening the door SendMessageToPC(oPC, "A door has opened somewhere!" ); // ------------------------------------------------------------------ } } else { // Sequence broken, so we must reset everything AssignCommand(OBJECT_SELF, PlaySound("gui_cannotequip")); // Show switch activation AssignCommand(OBJECT_SELF, PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE)); // Destroy all light objects int i; object oLight; string sLampTag; string sSwitchTag; string sSwitchTagBase=GetSubString(GetTag(OBJECT_SELF),0,GetStringLength(GetTag(OBJECT_SELF))-1); string sInvObjTag; //SendMessageToPC(GetFirstPC(), sSwitchTagBase ); for (i = 1; i <= iMaxSwitches; ++ i) { sLampTag = sLightTagBase + IntToString(i); sSwitchTag = sSwitchTagBase + IntToString(i); sInvObjTag = sInvisibleObjectBase + IntToString(i); // Flip switch back DelayCommand(0.2, AssignCommand(GetObjectByTag(sSwitchTag), PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE))); // Reset the lights oLight=GetObjectByTag(sLampTag); DelayCommand(0.2, DestroyObject(oLight)); DelayCommand(2.5, RecomputeStaticLighting(GetArea(GetObjectByTag(sInvObjTag)))); } SetLocalInt(GetModule(),sCurrentState,0); } } }