Advertisement
Guest User

X-Ray Keypad Code

a guest
Mar 1st, 2015
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.63 KB | None | 0 0
  1. "KeyCodeSolved" "InternalState0""KeyCodeFailed" "InternalState1""ReadyForScramble" "InternalState2""ConnectKey1" "InternalState3""ConnectKey2" "InternalState4""ConnectKey3" "InternalState5""ConnectKey4" "InternalState6""ConnectKey5" "InternalState7""ConnectKey6" "InternalState8""ConnectKey7" "InternalState9""ConnectKey8" "InternalState10""ConnectTextField1" "InternalState11""ConnectTextField2" "InternalState12""ConnectTextField3" "InternalState13""ConnectTextField4" "InternalState14""ConnectCodeField1" "InternalState15""ConnectCodeField2" "InternalState16""ConnectCodeField3" "InternalState17""ConnectCodeField4" "InternalState18""TestForXRay" "InternalState19" "KeyPressed1" "InternalMessage0""KeyPressed2" "InternalMessage1""KeyPressed3" "InternalMessage2""KeyPressed4" "InternalMessage3""KeyPressed5" "InternalMessage4""KeyPressed6" "InternalMessage5""KeyPressed7" "InternalMessage6""KeyPressed8" "InternalMessage7""KeyCodeCancelled" "InternalMessage10""GenerateKeyCode" "InternalMessage11""RandomizeKeys" "InternalMessage12""PrintDebugInfo" "InternalMessage13""PlayerInXRay" "InternalMessage14""PlayerNotInXRay" "InternalMessage15"
  2.         -- this code is run when the script is loaded since its outside all functions
  3.         -- allows you to initialize things
  4.      
  5.         DEBUG_LUA_PIRATEXRAYPAD = FALSE                                    
  6.         MAX_KEYS_IN_SEQUENCE = 4
  7.         NUMBER_OF_KEYS = 8
  8.  
  9.         -- gKeyCodeSequence has an extra buffer 0 to be read as the final Enter (5th entry) needed in a code of 4 keys
  10.         gKeyCodeSequence = { 0, 0, 0, 0, 0 }
  11.         -- gKeysPressedList tracks which keys have been pressed on the pad.  1 = UNPRESSED, 0 = PRESSED (its set up this way so RandomWeightedChance can be used on the list)
  12.         gKeysPressedList = { 1, 1, 1, 1, 1, 1, 1, 1 }
  13.         -- gKeyValuesList tracks the mapping of displayed keys to the actual key it represents. Starts out unscrambled.
  14.         gKeyValuesList = { 1, 2, 3, 4, 5, 6, 7, 8 }
  15.  
  16.         -- which entry of the code sequence we're at
  17.         gCurrentCodeIndex = 1
  18.         -- true until an incorrect key is pressed
  19.         gIsEnteredCodeCorrect = 1
  20.  
  21.         -- variable used to track what key the player pressed, so we can go outside the LUA object, test for X-Ray with PlayerProxy, then come back in from the Proxy
  22.         -- and check the actual button pressed
  23.         gCurrentKeyPressed = 0
  24.  
  25.         -- list of connected text fields for displaying pressed keys
  26.         gConnectedTextFieldObjIDs = { 0, 0, 0, 0 }
  27.  
  28.         -- list of connected Key MultiModelActors, for swithcing out the look of keys during randomization
  29.         gConnectedKeyActorObjIDs = { 0, 0, 0, 0, 0, 0, 0, 0 }
  30.  
  31.         -- list of connected text fields for displaying code needed
  32.         gConnectedCodeFieldObjIDs = { 0, 0, 0, 0 }
  33.  
  34.         -- Message functions
  35.         -- Message functions will be called with the matching name as the message with
  36.         -- "On" prefixed.  As below, this object takes Start, Stop, Reset and ResetAndStart
  37.         -- messages.
  38.         --
  39.         -- A message function parameter is a table containing three elements:
  40.         --   msg.state is a string indicating the source state that sent the message
  41.         --   msg.sender is a string identifer for the object that sent the message
  42.         --   msg.originator is a string identify for the object that originator this
  43.         --      chain of messages
  44.  
  45.  
  46.  -- ********************************************* DEBUG FUNCTIONS *********************************************************
  47.         function printKeysPressed()
  48.           if (DEBUG_LUA_PIRATEXRAYPAD) then
  49.             Print("KeysPressed : 1 2 3 4 5 6 7 8 \n")
  50.             Print("KeysPressed :")
  51.             for i = 1, NUMBER_OF_KEYS, 1 do
  52.               Print(" " .. gKeysPressedList[i] .."")      
  53.             end
  54.             Print("\n")
  55.           end
  56.         end
  57.  
  58.         function printKeyValues()
  59.           if (DEBUG_LUA_PIRATEXRAYPAD) then
  60.             Print("KeyValues : 1 2 3 4 5 6 7 8 \n")
  61.             Print("KeyValues :")
  62.             for i = 1, NUMBER_OF_KEYS, 1 do
  63.               Print(" " .. gKeyValuesList[i] .."")      
  64.             end
  65.             Print("\n")
  66.           end
  67.         end
  68.        
  69.         function printDebugInfo()
  70.           printKeysPressed()
  71.           printKeyValues()
  72.         end
  73.  
  74.  -- ********************************************* MATH FUNCTIONS *********************************************************
  75.  
  76.         function round(num, idp)
  77.           return tonumber(string.format("%." .. (idp or 0) .. "f", num))
  78.         end
  79.  
  80.  
  81.  -- ********************************************* FUNCTIONS FOR HANDLING MULTIACTOROBJECT SUPPORT *********************************************************
  82.  
  83.         function convertTextFieldToConnectionName(textFieldToConvert)
  84.           -- This function gives us the InternalState that we'll look for on connected MultiModelActors to figure out which object corresponds to which
  85.           -- text field, in order from left to right.
  86.  
  87.           if(textFieldToConvert == 1) then
  88.             return ("InternalState11")
  89.           elseif(textFieldToConvert == 2) then
  90.             return ("InternalState12")
  91.           elseif(textFieldToConvert == 3) then
  92.             return ("InternalState13")
  93.           elseif(textFieldToConvert == 4) then
  94.             return ("InternalState14")
  95.           end
  96.         end
  97.  
  98.         function convertKeyToMessage(keyToConvert)
  99.           -- This function converts a Key (1-8) to the corresponding InternalMessage that must be sent to a connected MultiModelActor to tell it to display the
  100.           -- CMDL corresponding to that number.  9 Is used for the Pressed State on the actual keys
  101.           -- This is used both for the Display Area as well as the 8 keys you can press, when they get randomized.
  102.        
  103.           if(keyToConvert == 1) then
  104.             return("InternalMessage3")
  105.           elseif(keyToConvert == 2) then
  106.             return("InternalMessage4")
  107.           elseif(keyToConvert == 3) then
  108.             return("InternalMessage5")
  109.           elseif(keyToConvert == 4) then
  110.             return("InternalMessage6")
  111.           elseif(keyToConvert == 5) then
  112.             return("InternalMessage7")
  113.           elseif(keyToConvert == 6) then
  114.             return("InternalMessage8")
  115.           elseif(keyToConvert == 7) then
  116.             return("InternalMessage9")
  117.           elseif(keyToConvert == 8) then
  118.             return("InternalMessage10")
  119.           elseif(keyToConvert == 9) then
  120.             return("InternalMessage11")
  121.           else
  122.             -- must be "enter/nothing"
  123.             return("InternalMessage2")
  124.           end
  125.         end
  126.  
  127.         function getConnectedMultiModelActors(msg)
  128.           -- This function populates our three ObjID lists (gConnectedTextFieldObjIDs, gConnectedCodeFieldObjIDs, and gConnectedKeyActorObjIDs)  with the connected
  129.           -- MultiObjectActors that correspond to their members. Whenever we need to update a display field, a code field, or a key actor with a specific button image,
  130.           -- we now have simple lists to index for the ObjID to send the appropriate message to
  131.          
  132.           if(DEBUG_LUA_PIRATEXRAYPAD) then            
  133.             Print("Checking connections for Objects...\n")
  134.           end
  135.  
  136.           local connections = GetObjectConnectionList()
  137.           for i,connection in ipairs( connections ) do
  138.             if(DEBUG_LUA_PIRATEXRAYPAD) then
  139.               Print(" Connection[" .. connection.state .. "] --> [" .. connection.message .. "]\n" )
  140.             end
  141.             for i2,connectedObjID in ipairs( connection.objectids ) do
  142.               if(DEBUG_LUA_PIRATEXRAYPAD) then
  143.                 Print("   ConnectedID :" .. connectedObjID .. "\n")
  144.               end
  145.               if(connection.state == "InternalState3") then        -- "ConnectKey1"
  146.                 gConnectedKeyActorObjIDs[1] = connectedObjID
  147.               elseif(connection.state == "InternalState4") then    -- "ConnectKey2"
  148.                 gConnectedKeyActorObjIDs[2] = connectedObjID
  149.               elseif(connection.state == "InternalState5") then    -- "ConnectKey3"
  150.                 gConnectedKeyActorObjIDs[3] = connectedObjID
  151.               elseif(connection.state == "InternalState6") then    -- "ConnectKey4"
  152.                 gConnectedKeyActorObjIDs[4] = connectedObjID
  153.               elseif(connection.state == "InternalState7") then    -- "ConnectKey5"
  154.                 gConnectedKeyActorObjIDs[5] = connectedObjID
  155.               elseif(connection.state == "InternalState8") then    -- "ConnectKey6"
  156.                 gConnectedKeyActorObjIDs[6] = connectedObjID
  157.               elseif(connection.state == "InternalState9") then    -- "ConnectKey7"
  158.                 gConnectedKeyActorObjIDs[7] = connectedObjID
  159.               elseif(connection.state == "InternalState10") then    -- "ConnectKey8"
  160.                 gConnectedKeyActorObjIDs[8] = connectedObjID
  161.  
  162.               elseif(connection.state == "InternalState11") then    -- "ConnectTextField1"
  163.                 gConnectedTextFieldObjIDs[1] = connectedObjID
  164.               elseif(connection.state == "InternalState12") then    -- "ConnectTextField2"
  165.                 gConnectedTextFieldObjIDs[2] = connectedObjID
  166.               elseif(connection.state == "InternalState13") then    -- "ConnectTextField3"
  167.                 gConnectedTextFieldObjIDs[3] = connectedObjID
  168.               elseif(connection.state == "InternalState14") then    -- "ConnectTextField4"
  169.                 gConnectedTextFieldObjIDs[4] = connectedObjID
  170.               elseif(connection.state == "InternalState15") then    -- "ConnectCodeField1"
  171.                 gConnectedCodeFieldObjIDs[1] = connectedObjID  
  172.               elseif(connection.state == "InternalState16") then    -- "ConnectCodeField2"
  173.                 gConnectedCodeFieldObjIDs[2] = connectedObjID  
  174.               elseif(connection.state == "InternalState17") then    -- "ConnectCodeField3"
  175.                 gConnectedCodeFieldObjIDs[3] = connectedObjID  
  176.               elseif(connection.state == "InternalState18") then    -- "ConnectCodeField4"
  177.                 gConnectedCodeFieldObjIDs[4] = connectedObjID            
  178.               end
  179.             end
  180.           end    
  181.         end
  182.  
  183.         function displayKeyPressed(keyPressed)
  184.           -- This function receives a keyPressed (1-9, since this doesn't get sent by Enter), and converts it to a message string (messageToSend)
  185.           -- The message string (messageToSend) is one of 10 messages that a MultiModeActor can receive.  We've connected a MultiModeActor for each
  186.           -- Text Field corresponding to an index in the sequence.  
  187.           -- The message string is sent to the Object ID of the corresponding Text Field for the current key index we're on.
  188.           -- i.e. "We pressed the number 2 for our 3rd number.  Convert 2 into "InternalMessage4", the message that will switch our Text Field MultiModelActor to the
  189.           --     "2" image.  We then look through our connected objects list and find the ObjID for the 3rd display TextField. Send that ObjID the "InternalMessage4"
  190.           --      message so it will switch its image to the number 2.
  191.  
  192.           local messageToSend = convertKeyToMessage(keyPressed)
  193.           local receiverObjID = gConnectedTextFieldObjIDs[gCurrentCodeIndex]
  194.  
  195.           if(receiverObjID == 0) then
  196.             if(DEBUG_LUA_PIRATEXRAYPAD) then
  197.               Print ("WARNING! No connected actor for TextField" .. gCurrentCodeIndex .."\n")
  198.             end
  199.             return
  200.           end
  201.  
  202.           if(DEBUG_LUA_PIRATEXRAYPAD) then
  203.             Print ("Sending message ".. messageToSend .." to receiverObjID " .. receiverObjID .." \n")
  204.           end
  205.           SendEventMessage("Activate", messageToSend, receiverObjID)
  206.         end
  207.  
  208.         function setKeyActorModels(includePressedKeys)
  209.           if(DEBUG_LUA_PIRATEXRAYPAD) then
  210.              Print ("setKeyActorModels! includePressedKeys : " .. includePressedKeys .." \n")
  211.           end
  212.           -- This function runs through the gKeyValuesList to get the current value of a key (what it's been randomized to) and then sends the appropriate message to
  213.           -- the associated KeyActor, to force the DisplayModel for that value.
  214.          
  215.           for i = 1, NUMBER_OF_KEYS, 1 do
  216.             -- if we've decided not to include pressed keys, then check to see if the current key we're looking at is pressed, and return out if true.
  217.             if((includePressedKeys == 0) and (gKeysPressedList[i] == 0)) then
  218.               if(DEBUG_LUA_PIRATEXRAYPAD) then
  219.                 Print ("gKeysPressedList[" .. i .. "] == 0 and includePressedKeys was 0. Skipping setActorModel for this key. \n")
  220.               end
  221.             else
  222.               local receiverObjID = gConnectedKeyActorObjIDs[i]      
  223.               if(receiverObjID == 0) then
  224.                 if (DEBUG_LUA_PIRATEXRAYPAD) then
  225.                    Print ("WARNING! No connected actor for KeyActor" .. i .."\n")
  226.                 end
  227.                 return
  228.               end
  229.  
  230.               local keyToDisplay = gKeyValuesList[i]
  231.               local messageToSend = convertKeyToMessage(keyToDisplay)
  232.               if (DEBUG_LUA_PIRATEXRAYPAD) then
  233.                 Print ("key ".. i .." | ToDisplay ".. keyToDisplay .." | Sending message ".. messageToSend .." to receiverObjID " .. receiverObjID .." \n")
  234.               end
  235.             SendEventMessage("Activate", messageToSend, receiverObjID)
  236.             end
  237.           end
  238.         end
  239.  
  240.         function setCodeDisplayModels()
  241.           -- this function sets up the DisplayModels for each CodeDisplay multimodel actor - effectively resetting the display to the current code chosen
  242.           for i = 1, MAX_KEYS_IN_SEQUENCE, 1 do
  243.             local receiverObjID = gConnectedCodeFieldObjIDs[i]
  244.             if(receiverObjID == 0) then
  245.                if (DEBUG_LUA_PIRATEXRAYPAD) then
  246.                   Print ("WARNING! No connected actor for CodeDisplay" .. i .."\n")
  247.                end
  248.                return
  249.             end
  250.             local keyToDisplay = gKeyCodeSequence[i]
  251.             local messageToSend = convertKeyToMessage(keyToDisplay)
  252.             SendEventMessage("Activate", messageToSend, receiverObjID)
  253.           end
  254.         end
  255.  
  256.   -- ********************************************* RANDOMIZING KEYS *********************************************************
  257.  
  258.  
  259.         function randomizeKeyValues()
  260.           if(DEBUG_LUA_PIRATEXRAYPAD) then
  261.              Print ("Randomizing Keys! \n")
  262.           end
  263.           printDebugInfo()
  264.           -- This function randomizes the keys by remapping the value for each key.  I.e. you may press key 1, but it's acting like it's key 6
  265.  
  266.           local chosenKey
  267.          
  268.           for i = 1, NUMBER_OF_KEYS-1, 1 do
  269.              -- make sure we're not trying to remap a key that's already been pressed and locked
  270.              -- Print ("Remapping Key " .. i .." : ")
  271.              if(gKeysPressedList[i] == 1) then          
  272.                
  273.                 -- return a random index from the list of available keys that haven't been pressed (pressed keys are set to 0, so they can't be rolled)
  274.                 -- Print ("Key Unpressed, choosing random remap \n")
  275.                 chosenKey = RandomRange(1, NUMBER_OF_KEYS)
  276.                 chosenKey = round(chosenKey, 0)
  277.                
  278.                 local needKeyReplacement = 1              
  279.                 while needKeyReplacement do      
  280.                   -- Print("trying chosenKey ["..chosenKey.."]\n")
  281.                   if(gKeysPressedList[chosenKey] == 1) then
  282.                     -- Print("gKeysPressedList["..chosenKey.."] is available, swapping with keyValue ["..i.."]\n")
  283.                     break
  284.                   else
  285.                     chosenKey = chosenKey + 1
  286.                     if(chosenKey > NUMBER_OF_KEYS) then
  287.                       chosenKey = 1
  288.                     end
  289.                   end
  290.                 end
  291.  
  292.                 -- swap the current key's value with the chosen key's value
  293.                 if(DEBUG_LUA_PIRATEXRAYPAD) then
  294.                   Print ("Remapping : Key["..i.."] Value["..gKeyValuesList[i].."] to Value["..gKeyValuesList[chosenKey].."]\n")
  295.                   Print ("Swapping  : Key["..chosenKey.."] Value["..gKeyValuesList[chosenKey].."] to Value["..gKeyValuesList[i].."]\n")
  296.                 end
  297.                 local valueToSwap = gKeyValuesList[i]
  298.                 gKeyValuesList[i] = gKeyValuesList[chosenKey]
  299.                 gKeyValuesList[chosenKey] = valueToSwap
  300.                
  301.              else
  302.                if(DEBUG_LUA_PIRATEXRAYPAD) then
  303.                  Print ("gKeysPressedList["..i.."] is pressed, skipping! \n")
  304.                end
  305.              end
  306.           end
  307.  
  308.           printDebugInfo()
  309.           -- once we've randomized, set the key actors' models to match their randomized values.  Don't include pressed keys
  310.           setKeyActorModels(0)
  311.         end
  312.  
  313.  -- ********************************************* KEY CODE CREATION / SETUP *********************************************************
  314.            
  315.         function generateRandomKeyCode()
  316.           -- This function (shock!) generates a random Key Code that the player must enter into the key code interaction.  
  317.          
  318.           local i
  319.          
  320.           local availableKeys = { 1, 1, 1, 1, 1, 1, 1, 1 }
  321.  
  322.           if ( DEBUG_LUA_PIRATEXRAYPAD ) then
  323.              Print (" Generating Key : ")
  324.           end
  325.  
  326.           for i = 1, MAX_KEYS_IN_SEQUENCE, 1 do
  327.             local chosenKey = RandomWeightedChoice(availableKeys)
  328.             gKeyCodeSequence[i] = chosenKey
  329.             availableKeys[chosenKey] = 0
  330.  
  331.             if ( DEBUG_LUA_PIRATEXRAYPAD ) then
  332.               Print (" " .. chosenKey .. " ")
  333.             end
  334.           end
  335.  
  336.           if ( DEBUG_LUA_PIRATEXRAYPAD ) then
  337.               Print (" \n")
  338.           end
  339.  
  340.           -- set the code display up with the correct visuals for our new code
  341.           setCodeDisplayModels()
  342.         end
  343.  
  344.         function clearKeyCode()
  345.           if ( DEBUG_LUA_PIRATEXRAYPAD ) then
  346.               Print (" Clearing Key Code! \n")
  347.           end
  348.  
  349.           gIsEnteredCodeCorrect = 1
  350.           gCurrentCodeIndex = 1
  351.  
  352.           for i = 1, NUMBER_OF_KEYS, 1 do
  353.             gKeysPressedList[i] = 1
  354.           end
  355.         end
  356.  
  357.  
  358.  -- ********************************************* CHECKING INPUT VS. CODE *********************************************************
  359.  
  360.         function checkKeyCodeCompletion()
  361.           if ( gIsEnteredCodeCorrect > 0 ) then
  362.             SendEvent( "KeyCodeSolved" )
  363.           else
  364.             SendEvent( "KeyCodeFailed" )
  365.           end
  366.         end      
  367. --[[ **********OLD KEY CODE CHECK***********
  368.         function checkKeyPressedAgainstCode(keyPressed)
  369.           -- map the key pressed to its current value in the gKeyValuesList. This is the scrambled list representing what each key maps to at that moment
  370.           local remappedKeyPressed = gKeyValuesList[keyPressed]
  371.  
  372.           -- get the current key needed in the sequence
  373.           local currentKeyNeeded = gKeyCodeSequence[gCurrentCodeIndex]
  374.  
  375.           displayKeyPressed(remappedKeyPressed)
  376.          
  377.           if ( DEBUG_LUA_PIRATEXRAYPAD ) then
  378.             Print (" CurrentKeyNeeded :  " .. currentKeyNeeded .. " / User Pressed : " .. remappedKeyPressed .. " \n")
  379.           end
  380.  
  381.          
  382.           if( currentKeyNeeded ~= remappedKeyPressed ) then
  383.             gIsEnteredCodeCorrect = 0
  384.             SendEvent( "InvalidKeyPressed" )
  385.           end
  386.  
  387.           -- set the key pressed to the "pressed image"
  388.           local receiverObjID = gConnectedKeyActorObjIDs[keyPressed]
  389.           local messageToSend = convertKeyToMessage(9)
  390.           SendEventMessage("Activate", messageToSend, receiverObjID)
  391.  
  392.           -- set the passed key as being pressed, then randomize the values of all keys
  393.           gKeysPressedList[keyPressed] = 0
  394.  
  395.           -- increment to the next index in the key code sequence
  396.           gCurrentCodeIndex = gCurrentCodeIndex+1
  397.           -- check if we just entered the last number needed
  398.           if(gCurrentCodeIndex > MAX_KEYS_IN_SEQUENCE) then
  399.             checkKeyCodeCompletion()
  400.           else
  401.             SendEvent("ReadyForScramble")
  402.           end
  403.         end      
  404. ]]--
  405. -- ********** NEW KEY CODE CHECK *********
  406.         function checkKeyPressedAgainstCode(isInXRay)
  407.  
  408.           -- get the current key needed in the sequence
  409.           local currentKeyNeeded = gKeyCodeSequence[gCurrentCodeIndex]
  410.          
  411.           local keyPressed = gCurrentKeyPressed
  412.  
  413.            -- set the passed key as being pressed
  414.           gKeysPressedList[keyPressed] = 0
  415.  
  416.            -- map the key pressed to its current value in the gKeyValuesList. This is the scrambled list representing what each key maps to at that moment
  417.           local keyPressedValue = gKeyValuesList[keyPressed]
  418.          
  419.           if ( DEBUG_LUA_PIRATEXRAYPAD ) then
  420.             Print (" CurrentKeyNeeded :  " .. currentKeyNeeded .. " / User Pressed : " .. keyPressedValue .. " \n")
  421.           end
  422.  
  423.           -- If player is not in X-Ray visor, check if they pressed the current key value needed. If so, swap the key's value with another unpressed key's value
  424.           if(isInXRay == 0) then
  425.             if (keyPressedValue == currentKeyNeeded) then
  426.                if ( DEBUG_LUA_PIRATEXRAYPAD ) then
  427.                  Print("Not In X-Ray and pressed correct key. Swapping with another key value! \n")
  428.                end
  429.                
  430.                local chosenKey = RandomRange(1, NUMBER_OF_KEYS)
  431.                chosenKey = round(chosenKey, 0)
  432.  
  433.                local needKeyReplacement = 1              
  434.                while needKeyReplacement do      
  435.                  -- Print("trying chosenKey ["..chosenKey.."]\n")
  436.                  if(gKeysPressedList[chosenKey] == 1) then
  437.                    -- Swap the newly chosen value to our keyPressedValue, then swap the two values in the ValuesList
  438.                    -- Print("gKeysPressedList["..chosenKey.."] is available, swapping its value with currentKeyPressed Value ["..valueToSwap.."] \n")
  439.                    keyPressedValue = gKeyValuesList[chosenKey]
  440.                    gKeyValuesList[chosenKey] = gKeyValuesList[keyPressed]
  441.                    gKeyValuesList[keyPressed] = keyPressedValue
  442.                    break
  443.                  else
  444.                    chosenKey = chosenKey + 1
  445.                    if(chosenKey > NUMBER_OF_KEYS) then
  446.                      chosenKey = 1
  447.                    end
  448.                  end
  449.                end
  450.              else
  451.                if( DEBUG_LUA_PIRATEXRAYPAD ) then
  452.                  Print("Not In X-Ray but did not press correct value! Let it drop through!\n")
  453.                end
  454.              end
  455.            end
  456.  
  457.           -- show the value pressed on the appropariate Display TextField
  458.           displayKeyPressed(keyPressedValue)              
  459.  
  460.           -- if the player didn't press the key with the value needed, send the InvalidKeyPressed Event and mark that they've put in a wrong value
  461.           if( currentKeyNeeded ~= keyPressedValue ) then
  462.             gIsEnteredCodeCorrect = 0
  463.             SendEvent( "InvalidKeyPressed" )
  464.           end
  465.  
  466.           -- set the key pressed to the "pressed image"
  467.           local receiverObjID = gConnectedKeyActorObjIDs[keyPressed]
  468.           local messageToSend = convertKeyToMessage(9)
  469.           SendEventMessage("Activate", messageToSend, receiverObjID)
  470.  
  471.          
  472.           -- increment to the next index in the key code sequence
  473.           gCurrentCodeIndex = gCurrentCodeIndex+1
  474.           -- check if we just entered the last number needed
  475.           if(gCurrentCodeIndex > MAX_KEYS_IN_SEQUENCE) then
  476.             checkKeyCodeCompletion()
  477.           else
  478.             SendEvent("ReadyForScramble")
  479.           end
  480.         end
  481.  
  482. -- ********************************************* X-RAY HANDLING **********************************************************
  483.         function OnPlayerInXRay(msg)
  484.           checkKeyPressedAgainstCode(1)
  485.         end
  486.  
  487.         function OnPlayerNotInXRay(msg)
  488.           checkKeyPressedAgainstCode(0)
  489.         end
  490.  
  491. -- ********************************************* MESSAGE AND LOAD EVENTS *********************************************************
  492.  
  493.         function OnKeyPressed1(msg)
  494.           gCurrentKeyPressed = 1
  495.           SendEvent("TestForXRay")
  496.         end
  497.  
  498.         function OnKeyPressed2(msg)
  499.           gCurrentKeyPressed = 2
  500.           SendEvent("TestForXRay")
  501.         end
  502.  
  503.         function OnKeyPressed3(msg)
  504.           gCurrentKeyPressed = 3
  505.           SendEvent("TestForXRay")
  506.         end                          
  507.  
  508.         function OnKeyPressed4(msg)
  509.           gCurrentKeyPressed = 4
  510.           SendEvent("TestForXRay")
  511.         end
  512.  
  513.         function OnKeyPressed5(msg)
  514.           gCurrentKeyPressed = 5
  515.           SendEvent("TestForXRay")
  516.         end
  517.  
  518.         function OnKeyPressed6(msg)
  519.           gCurrentKeyPressed = 6
  520.           SendEvent("TestForXRay")
  521.         end                          
  522.  
  523.         function OnKeyPressed7(msg)
  524.           gCurrentKeyPressed = 7
  525.           SendEvent("TestForXRay")
  526.         end
  527.  
  528.         function OnKeyPressed8(msg)
  529.           gCurrentKeyPressed = 8
  530.           SendEvent("TestForXRay")
  531.         end
  532.  
  533.         function OnKeyCodeCancelled(msg)
  534.           clearKeyCode()
  535.         end
  536.  
  537.         function OnGenerateKeyCode(msg)
  538.           clearKeyCode()          
  539.           generateRandomKeyCode()
  540.           randomizeKeyValues()
  541.         end
  542.  
  543.         function OnRandomizeKeys(msg)
  544.           randomizeKeyValues()
  545.         end
  546.  
  547.         function OnPrintDebugInfo(msg)
  548.           printDebugInfo()
  549.         end
  550.  
  551.         function OnAreaLoaded(msg)
  552.           getConnectedMultiModelActors(msg)
  553.         end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement