[Tutorial] [Script] Anagram Minigame |
Pmcarpan « Citoyen » 1381307880000
| 0 | ||
Hello fellow coders and non-coders! In this tutorial we are going to make a simple anagram minigame. This is a simple code and doesn't have anything complex. Before starting, we need to make a check on things. We need no shaman, no auto new game-creation by TFM, no afk-death and no auto-score(as we will manually give points). So the following will have to be implemented. Also before starting the round, the player scores have to be set to 0. a dit : First off, we need to accept messages(more correctly, guesses) from the users. To do this, we need to create an eventChatCommand which will tally the guesses with the correct answer. If the guess is correct, we will make him win, increase his score by 1 and also display that he/she has won. As print displays the message only to the user and chatMessage is blocked in tribe houses, we will use ui.addTextArea for display. Further we have to change rounds. For this we will change the timer value to 10 seconds. We are not done yet after previous brainstorming session! A major fallacy remains. More than one user can win. So we are using an additional boolean answergiven which was initially false and is set to true after the correct answer. a dit : Now we need no deaths right? (If you do, you can remove this part though it is suggested to have no deaths). So we need to respawn a player when he/she dies and we need to respawn new players. This part is very simple. One eventNewPlayer and one eventPlayerDied only with the same command i.e. tfm.exec.respawnPlayer. a dit : Now we need to add a map rotation to the room. So lets create a table containing the maps first! This table is maps={...}. We need to change rounds when time is 0 or less than 0. For this we use eventLoop which has two arguments- the current time and time remaining. We can use the second for the purpose. If the remaining time is less than or equal to 0, we will change the round with tfm.exec.newGame with a random map from our table. Also we need to set our initial answergiven to false and remove the text area. a dit : Note that we are manually starting the round with a map and initially setting answergiven to false. So we are done with the intricate design of the game. So what is left? The questions(anagrams) and the answers! The anagrams will be stored in the table question={...} and the answers will be stored in the table answer={...}. Note that the questions and answers have to be in order. Why? Think about it for a moment! How will be import the question and the answer? By using math.random and so we wouldn't want the answer of bono to be cheese. We want the question and the answer to be updated when the round starts. So we put them in eventNewGame() along with the game time to be set. a dit : And with that, we are done! If we put together the codes, we will have something like this. https://paste.moepl.eu/view/c18d11fe This was a simple code. But I hope that it has helped you to grasp the concepts better. Hopefully this will help you in your future developments! v2.01 -word scrambler ~idea by Leafileaf -hide your answer by using ![space]guess ~courtesy Leafileaf -non-repitition of old words ~courtesy Leafileaf -addition of new words Leafileaf a dit : So I had the time to make some improvements. Instead of clubbing them to the above, I'll just be discussing them here. Also thank you Leafileaf for your suggestions! So the word scrambler may seem quite complex, but it is really simple! First we need the table of the answers and a new table to contain the letters. We'll be using only two words in the answer table. First up, we will take the letters and sort them in the letters table using a simple for-loop.(Here, I have used str:sub(x,y) which gives us the part of the string str from character position x to y. Simple? Now comes the complex part. We will run a for-loop for the length of the answer and use math.random to create a new word using a variable id. At the same time, we'll remove the letter from the letters table. I have also added an if statement as a check for not giving away the answer. Compact Version a dit : Hiding the answer is quite simple. a dit : The non-repetition of words is also quite easy. We put a variable called prev which stores the previous word. for tallying. If the current word is the same as the previous word, we run a while loop to constantly get a new word till the word is not the same as prev. I'm not adding this piece individually, you can check it from the whole code. Anagram Script v2.02: https://paste.moepl.eu/view/5541bc82 Also, thank you for reading through this! All suggestions are welcome! For stopping the script, open the Lua editor(/lua), type system.exit() and press submit. Note: The wordlist is subjected to change without notice and may not be updated everytime. Other tutorials by pro coders: Map rotation tutorial by Shamousey: Topic-457950 FFA tutorial by Shamousey: Topic-457951 |
Xxninjazxx « Citoyen » 1381314660000
| 0 | ||
That code won't work because instead of < or > you have < because you edited it after making it |
Pmcarpan « Citoyen » 1381322880000
| 0 | ||
It should work now, and nice observation ^^' |
Shatterz « Citoyen » 1382283480000
| 0 | ||
I Like this Keep it up :D |
Mikuhl « Citoyen » 1382285820000
| 0 | ||
Your lack of tabs hurt my eyes. :( |
Michealjacki « Citoyen » 1382851800000
| 0 | ||
nice map i like this |
Leafileaf « Citoyen » 1382938080000
| 0 | ||
Instead of having a question table, why not just take a random word from the answer table and mess up the letters? If you have a question table then people can just memorise the questions and answer it within a few seconds. Then the game becomes a memorising game instead of anagram. EDIT: Look at my post below. I added the word scrambler and some new things, including hidden guesses. |
Pmcarpan « Citoyen » 1382961360000
| 0 | ||
Leafileaf a dit : Thanks for the suggestion! I will be adding it as soon as possible ^^ |
Leafileaf « Citoyen » 1383209160000
| 0 | ||
Suggested code: Anagram Code a dit : Add as many things as you want to the answers table. The more words, the more the challenge! *-* As a general rule, words added should be 5 or more characters long. Otherwise it's too easy. Also, words should not have too many identical characters or a too distinct length. Suggested length is 6~10 characters. About 50 such words will make a good anagram minigame. Though the more the merrier! Note: Solve with ![space][guess] if you don't want your guess to be seen. ex. ! apples P.S. Im rubbish at solving anagrams. |
0 | ||
Leafileaf a dit : why not just a dit : ehe |
Leafileaf « Citoyen » 1383216720000
| 0 | ||
Issey a dit : No. What about wrong answers? ex. ! sapple |
0 | ||
Leafileaf a dit : ok ok you win if only there was a way to generate all possible words within a limited range while making the load time extremely slow hmm |
Pmcarpan « Citoyen » 1383309000000
| 0 | ||
Issey a dit : I found out a simpler way lol. Thanks for the ideas @Leafi and @Issey |