Page 1 of 1
LUA - Checking the order of kills
Posted: Mon May 25, 2009 8:59 pm
by Fiodis
How would you go about checking the order in which the character damages or kills something? For instance, say you want to make a keypad with a lock, and there's ten buttons (0 - 9), and you have a five-number activation key which the character types out by shooting the appropriate buttons. How could you check in which order he shoots them?
Re: LUA - Checking the order of kills
Posted: Sat Jun 06, 2009 10:54 pm
by [RDH]Zerted
There are lots of ways to do it. Heres one way:
* Store your key in a table: key[1] = ''o"; key[2]=''p"; key[3]="e"; key[4]=''n";
* Have a variable to keep track of how much of the key has been entered: entered = 1
* When a character/button is destroyed, see if it matches the value in the table: if key[entered] == destoryedChar then...
** If they don't match, then reset the 'entered sequence': entered = 1
** If they do match, then move on to the next key: entered += 1
*** After the +=1, you will need to see if the entire key has been entered: if entered > table.getn(key) then...
**** If so, then the correct key has been entered and you open the door and reset everything