//Sandstorm mine trigger 3 Trigger 002-3 98,42 (127)
// Variables used: nibble 4 and 5 of QUEST_SouthTulimshar

002-3.gat,91,99,0|script|Button|400,0,0,{

    // This NPC previously used the variable TMW_Quest
    callfunc "ClearVarTMW_Quest";

    set @state, ((QUEST_SouthTulimshar & BYTE_2_MASK) >> BYTE_2_SHIFT);

    if (@state == 24) goto L_Trigger_Wrong_3;
    if (@state == 23) goto L_Trigger_3;
    if (@state == 22) goto L_Trigger_Wrong_3;

    mes "There is a large button on the ground.  A key hole appears on the button.";
    goto L_Close;

L_Trigger_Wrong_3:
    mes "There is a large button on the ground.  A key hole appears on the button.";
    menu
        "Put the key in, turn right.", L_Right_Wrong_3,
        "Put the key in, turn left.", L_Left_Wrong_3,
        "Do nothing.", L_Nothing_3;

L_Right_Wrong_3:
    set @state, 22;
    callsub S_Update_Var;
    mes "You turn the key right.";
    goto L_Close;

L_Left_Wrong_3:
    set @state, 22;
    callsub S_Update_Var;
    mes "You turn the key left.";
    goto L_Close;

L_Trigger_3:
    mes "There is a large button on the ground.  A key hole appears on the button.";
    menu
        "Put the key in, turn right.", L_Right_3,
        "Put the key in, turn left.", L_Left_3,
        "Do nothing.", L_Nothing_3;

L_Right_3:
    set @state, 22;
    callsub S_Update_Var;
    mes "You turn the key right.";
    goto L_Close;

L_Left_3:
    set @state, 24;
    callsub S_Update_Var;
    mes "You turn the key left. A clicking sound echoes throughout the mine.";
    goto L_Close;

L_Nothing_3:
    mes "You leave the button alone.";
    goto L_Close;

L_Close:
    set @state, 0;
    close;

S_Update_Var:
    set QUEST_SouthTulimshar, (QUEST_SouthTulimshar & ~(BYTE_2_MASK) | (@state << BYTE_2_SHIFT));
    return;
}