[Module API] [Tutorial] Map Rotation |
Shamousey « Consul » 1380725460000
| 3 | ||
When writing a script to handle map rotation, there are several factors to take into account that you need to consider when you may want a new round to start. • You may want a custom set of maps. • Transformice's own new game feature will take into effect when the time reaches 0. • A new game should start when the time reaches 0. • A new game should start if there are no mice left alive. This tutorial will go through these things one by one until we have a working map rotation. • You may want a custom set of maps. Map lists are easy enough to set up in a table. a dit : In order to get a random map from this list, we first need to get a random number from it. #maps returns the number of items in the table, and math.random(#maps) will return a random integer between 1 and the number of items in the table. We can use this as the key in the table to return a random item from it, and then use that to load a new game. a dit : • Transformice's own new game feature will take into effect when the time reaches 0. This can be solved simply by disabling this feature, using an existing function. a dit : • A new game should start when the time reaches 0. The eventLoop function runs every 500ms, but also has two arguments that it gives; the current time of the map, and the time remaining. We can use the second argument to start a new game if there's no time left. Bear in mind that the second argument drops below 0 occasionally, so we'll use the "less-than or equal to" operator just in case that happens. a dit : • A new game should start if there are no mice left alive. You can check if a player is alive by using tfm.get.room.playerList["Shamousey"].isDead, it'll return true if the player is dead or false if they're not. We can use this to keep a number of how many players are alive, and then start a new round as we need if there is no-one left. Looping through the tfm.get.room.playerList table with pairs, we can check for each player whether they're dead or alive and increase a number to get the number of dead players. However we want to see how many are alive, so we'll use "not" to return the opposite. a dit : The variable "i" will now be the number of alive players. Since the number of alive players will alter each time a player dies, we can run this on that event to ensure the number is up to date. We can then go on to use "i" to start a new game if its value is 0. a dit : Note that the word "local" is before we define "i". This means that the variable can't be used outside the eventPlayerDied() function. With all of this put together, we should have a complete map rotation system that will play a random map from a list under the same conditions that Transformice usually does. a dit : This tutorial may have not used the most efficient methods to get a map rotation, and different minigames may need some things changed to get working as intended, however I hope it has taught you some basic concepts that you can go on and use in your own development. Dernière modification le 1472313840000 |
Tailtong « Citoyen » 1380726360000
| 0 | ||
oh thanks, now i can make a map rotation for my cale of dooty game |
0 | ||
Thanks!! |
0 | ||
Great tutorial Shamousey! |
Thetroz « Citoyen » 1380727260000
| 0 | ||
Thanks Shamousey Good tutorial!! |
Myutsu « Citoyen » 1380727380000
| 0 | ||
thanks |
Brkeeee « Censeur » 1380727680000
| 0 | ||
thanks! |
Julioforum « Citoyen » 1381196520000
| 0 | ||
thanks shamousey |
Xanmeow « Citoyen » 1381281000000
| 0 | ||
thx but I need something to play on mechanical maps |
Shamousey « Consul » 1381281660000
| 0 | ||
Xanmeow a dit : You can play mech maps (P6) with tfm.exec.newGame("#6"), but unfortunately that doesn't work in tribe houses. Collect a list of them yourself and put them in the maps table. |
Safwanrockz « Censeur » 1381354860000
| 0 | ||
Thanks for the tutorial, it's really useful to use your own map rotation in your tribe house. |
Crizfm « Citoyen » 1381768920000
| 0 | ||
Thanks a lot Shamousey.I want to ask you a question.Can we make a countdown in tribe house? If we can how? I use that Lua code a dit : and it doesn't work |
Shamousey « Consul » 1381824600000
| 0 | ||
Crizfm a dit : The arguments in eventLoop use milliseconds. Try using "if remaining<=3000 then" for example. |
Theleetcoder « Citoyen » 1382966220000
| 0 | ||
Shamousey a dit : You can also do that : Theleetcoder a dit : |
Nathaan « Citoyen » 1382971740000
| 0 | ||
Theleetcoder a dit : Or you can use that : a dit : |
Theleetcoder « Citoyen » 1382971980000
| 0 | ||
Nathaan a dit : a bug*, yes but it's the same way i've purposed. FR : Ouais mais c'est la même chose que ce que j'ai proposé :p. |
Nathaan « Citoyen » 1382973420000
| 0 | ||
Theleetcoder a dit : No, it's not same. You the start timer is "0", me it's the time. But it's same result. |
Xanmeow « Citoyen » 1385934960000
| 0 | ||
why doesnt this work? maps={2821033,3808004} function eventLoop(time,remaining) if remaining<=0 then tfm.exec.newGame(maps[math.random(#maps)]) end end function eventPlayerDied() local i=0 for n,player in pairs(tfm.get.room.playerList) do if not player.isDead then i=i+1 end end if i==0 then tfm.exec.newGame(maps[math.random(#maps)]) end end |
Shamousey « Consul » 1385935440000
| 0 | ||
Xanmeow a dit : It works just fine. One problem you may have is Transformice's own new game function excecuting before eventLoop reaches 0, so try adding tfm.exec.disableAutoNewGame(true) |
Xanmeow « Citoyen » 1385935440000
| 0 | ||
Shamousey a dit : oh sorry, I have that. I just must of missed it when posting! well when I load the script none of the maps just play |