For the purposes of this tutorial, we'll create 4 additional events (Bush #1, Bush #2, Bush #3 and Bush #4) that can be searched for each part of the combination. These are dotted around the map so that when "searched", one part of the combination will show up.
We'll also need to create 4 variables (Num 1, Num 2, Num 3 and Num 4) to "store" the individual combination numbers, but this is primarily to avoid using switches when the number is obtained.
The combination for this tutorial will be 4321, with each part stored in the variable "Num Digits". If you attempt to open the chest without first knowing the entire combination of four numbers, you won't be able to open it.
Starting with the Bush #1 event, in the Event Commands, we're going to create a Conditional Branch to determine if the bush has already been searched. If so, display a message with the first number in the combination sequence; if not, set the first number (in this case set to 4) and add one to the number of digits. The complete code will look like this:
<>Branch if Var [0003:Num 1] is 0 Greater <>Message: The first number is: \V[3]. <> : Else Handler <>Variable Oper: [0003:Num 1] Set, 4 <>Variable Oper: [0007:Num Digits] + , 1 <>Message: The first number is: \V[3]. <> : End
Repeat that with Bush #2, changing "Num 1" to "Num 2", "\V[3]" to "\V[4]" and under the Else Handler change the "4" to a "3", thus:
<>Branch if Var [0004:Num 2] is 0 Greater <>Message: The first number is: \V[4]. <> : Else Handler <>Variable Oper: [0004:Num 2] Set, 3 <>Variable Oper: [0007:Num Digits] + , 1 <>Message: The first number is: \V[4]. <> : End
Repeat the process for Bush #3 and Bush #4, increasing the values accordingly.
After that, we need to create the chest. For this, we'll check to see if all the numbers needed for the combination lock are known. If not, a message will be displayed telling you that you don't know the full code. If so, check for the correct combination (in this case, 4321) and open the chest upon the correct combination being entered.
We'll be drawing on the previous tutorials - Part 1 (Basic Chests), Part 4a (Combination Locks) and Part 3 (Random Contents) to create the chest.
The complete routine will look like this:
<>Branch if Var [0007:Num Digits] is 4 <>Input Number: 4 Digit, [0002:Combo] <>Branch if Var [0002:Combo] is 4321 <>Play Sound: open1 <>Move Event: This Event, Face Right <>Wait: 0.2 Sec <>Move Event: This Event, Face Up <>Wait: 0.2 Sec <>Move Event: This Event, Face Left <>Wait: 0.2 Sec <>Call Event: Random Contents <>Switch Operation: [0004:Chest 4b Opened] ON <> : Else Handler <>Message: The combination is incorrect. <> : End <> : Else Handler <>Message: You don't have all the numbers yet. <> : End