×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Tutorial] [Script] Anagram Minigame
[Tutorial] [Script] Anagram Minigame
Pmcarpan
« Citoyen »
1381307880000
    • Pmcarpan#0000
    • Profil
    • Derniers messages
    • Tribu
#1
  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 :

tfm.exec.disableAutoShaman(true)
tfm.exec.disableAutoNewGame(true)
tfm.exec.disableAfkDeath(true)
tfm.exec.disableAutoScore(true)

for player in pairs(tfm.get.room.playerList) do --getting the name of a player
tfm.exec.setPlayerScore (player, 0) --setting score to 0
end


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 :

function eventChatCommand(player,guess)
if guess==answerbyplayer and answergiven==false --checking for correct answer and answer given or not
then tfm.exec.giveCheese(player)
tfm.exec.playerVictory(player) --giving the player cheese and making him/her win
tfm.exec.setPlayerScore(player, 1, true) --increasing score by 1
ui.addTextArea(0, player .. " has won!!") --displaying the player's victory
answergiven=true --answer has been given
tfm.exec.setGameTime(10,true) --setting game time to 10 seconds
end

end

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 :

function eventNewPlayer(newplayer)
tfm.exec.respawnPlayer(newplayer)
end

function eventPlayerDied(deadplayer)
tfm.exec.respawnPlayer(deadplayer)
end

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 :

maps={0,"@3297238","@2720753"} --feel free to add your maps!
...
tfm.exec.newGame(maps[math.random(#maps)]) --running a map beforehand
answergiven=false --initializing answergiven to false
...
function eventLoop(time,remaining)
if remaining<=0
then tfm.exec.newGame(maps[math.random(#maps)]) --executing a random map from the table maps
answergiven=false --set to false just before round-start
ui.removeTextArea(0)
end
end

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 :

question={"bono","rife","meho","heeces","goonirttryme","malla"}
answer={"noob","fire","home","cheese","trigonometry","llama"}
--feel free to add more questions and answers
...
function eventNewGame()

tfm.exec.setGameTime(120,true) --setting game time
QAid=math.random(1,6) --limits of the question and answer number
questionasked=question[QAid] --importing the question
answerbyplayer=answer[QAid] --importing the answer
ui.addTextArea(0,"Anagram Time! Try to solve this: "..questionasked ) --displaying the question
end

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 :


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.


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 :


letters={}
answer={"noob","pro"}
question=""

answerbyplayer=answer[math.random(#answer)]

for i=1,#answerbyplayer,1 do
letters=answerbyplayer:sub(i,i)
end

for i=1,#answerbyplayer,1 do
id=math.random(#letters)
if i==1 and id==1 then
id=math.random(2,#answerbyplayer)
end
question=question..letters[id]
table.remove(letters,id)
end

print(question)


Hiding the answer is quite simple.
a dit :


system.disableChatCommandDisplay("",true)


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
    • Xxninjazxx#0000
    • Profil
    • Derniers messages
#2
  0
That code won't work because instead of < or > you have &lt; because you edited it after making it
Pmcarpan
« Citoyen »
1381322880000
    • Pmcarpan#0000
    • Profil
    • Derniers messages
    • Tribu
#3
  0
It should work now, and nice observation ^^'
Shatterz
« Citoyen »
1382283480000
    • Shatterz#0000
    • Profil
    • Derniers messages
#4
  0
I Like this Keep it up :D
Mikuhl
« Citoyen »
1382285820000
    • Mikuhl#3311
    • Profil
    • Derniers messages
    • Tribu
#5
  0
Your lack of tabs hurt my eyes. :(
Michealjacki
« Citoyen »
1382851800000
    • Michealjacki#0000
    • Profil
    • Derniers messages
    • Tribu
#6
  0
nice map i like this
Leafileaf
« Citoyen »
1382938080000
    • Leafileaf#0000
    • Profil
    • Derniers messages
    • Tribu
#7
  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
    • Pmcarpan#0000
    • Profil
    • Derniers messages
    • Tribu
#8
  0
Leafileaf a dit :
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.

Thanks for the suggestion! I will be adding it as soon as possible ^^
Leafileaf
« Citoyen »
1383209160000
    • Leafileaf#0000
    • Profil
    • Derniers messages
    • Tribu
#9
  0
Suggested code:

Anagram Code a dit :

maps={"0"}

answer={"trigonometry","llama","hello","transformice","apples","shaman","awesome","question","circle","happy","house","mouse","rabbit","anagrams","branch","sharing","volcano","sunlight","scrabble","nature","phone","knock","window","rainbow","child","rulers","dough","fridge","build","cruiser","square","cloud","anchor","folder","flower"}

tfm.exec.disableAutoShaman(true)
tfm.exec.disableAutoNewGame(true)
tfm.exec.disableAfkDeath(true)
tfm.exec.disableAutoScore(true)
system.disableChatCommandDisplay("",true) --guesses can't be seen.
prev=""

for player in pairs(tfm.get.room.playerList) do
tfm.exec.setPlayerScore (player, 0)
end

tfm.exec.newGame(maps[math.random(#maps)])

answergiven=false

function eventNewGame()

tfm.exec.setGameTime(120,true)
QAid=math.random(#answer)
questionasked=scramble(answer[QAid])
if questionasked==prev then eventNewGame() return nil end -- if same word, get a new one.
prev=questionasked
answerbyplayer=answer[QAid]
ui.addTextArea(0,"Anagram Time! Try to solve this: <VP>"..questionasked )

end

function scramble(str)
local a={}
for i=1,str:len(),1 do table.insert(a,str:sub(i,i)) end
for i=1,math.random(20+(3*str:len()),40+(3*str:len())),1 do
local x=math.random(str:len())
local y=math.random(str:len())
local z=a[x]
a[x]=a[y]
a[y]=z
end
local scrambledString=""
for i=1,str:len(),1 do scrambledString=scrambledString..a end
return scrambledString
end

function eventNewPlayer(newplayer)
tfm.exec.respawnPlayer(newplayer)
end

function eventPlayerDied(deadplayer)
tfm.exec.respawnPlayer(deadplayer)
end

function eventChatCommand(player,guess)
if guess:sub(1,1)==" " then guess=guess:sub(2) end
if guess==answerbyplayer and answergiven==false
then tfm.exec.giveCheese(player)
tfm.exec.playerVictory(player)
tfm.exec.setPlayerScore(player, 1, true)
ui.addTextArea(0, player .. " won. The word was <VP>"..answerbyplayer.."<N>.")
answergiven=true
tfm.exec.setGameTime(10,true)
end

end

function eventLoop(time,remaining)
if remaining<=10000 then eventChatCommand("No one",answerbyplayer) end -- reveal answer
if remaining<=0
then tfm.exec.newGame(maps[math.random(#maps)])
answergiven=false
ui.removeTextArea(0)
end
end

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.
Issey
« Citoyen »
1383216600000
    • Issey#0000
    • Profil
    • Derniers messages
#10
  0
Leafileaf a dit :
Suggested code:
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.

why not just
a dit :

for a in pairs(answer) do
system.disableChatCommandDisplay(a,true)
end

ehe
Leafileaf
« Citoyen »
1383216720000
    • Leafileaf#0000
    • Profil
    • Derniers messages
    • Tribu
#11
  0
Issey a dit :
why not just


ehe

No. What about wrong answers?
ex. ! sapple
Issey
« Citoyen »
1383217920000
    • Issey#0000
    • Profil
    • Derniers messages
#12
  0
Leafileaf a dit :
No. What about wrong answers?
ex. ! sapple

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
    • Pmcarpan#0000
    • Profil
    • Derniers messages
    • Tribu
#13
  0
Issey 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

I found out a simpler way lol. Thanks for the ideas @Leafi and @Issey
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Tutorial] [Script] Anagram Minigame
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27