×

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
  • /
  • [Module API] [Tutorial] Map Rotation
1 / 2 › »
[Module API] [Tutorial] Map Rotation
Shamousey
« Consul »
1380725460000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#1
  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.


http://i.imgur.com/4vSFf.png
• You may want a custom set of maps.

Map lists are easy enough to set up in a table.

a dit :
maps={0,1,2,3,4,5,6,7,8,9,10}

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 :
tfm.exec.newGame(maps[math.random(#maps)])

http://i.imgur.com/4vSFf.png
• 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 :
tfm.exec.disableAutoNewGame(true)

http://i.imgur.com/4vSFf.png
• 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 :
function eventLoop(time,remaining)
if remaining<=0 then
tfm.exec.newGame(maps[math.random(#maps)])
end
end

http://i.imgur.com/4vSFf.png
• 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 :
i=0
for n,player in pairs(tfm.get.room.playerList) do
if not player.isDead then
i=i+1
end
end

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 :
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

Note that the word "local" is before we define "i". This means that the variable can't be used outside the eventPlayerDied() function.


http://i.imgur.com/4vSFf.png
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 :
tfm.exec.disableAutoNewGame(true)
maps={0,1,2,3,4,5,6,7,8,9,10}

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

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
    • Tailtong#0000
    • Profil
    • Derniers messages
    • Tribu
#2
  0
oh thanks, now i can make a map rotation for my cale of dooty game
Zutto
« Citoyen »
1380727020000
    • Zutto#4451
    • Profil
    • Derniers messages
    • Tribu
#3
  0
Thanks!!
Jordy
« Consul »
1380727140000
    • Jordy#0015
    • Profil
    • Derniers messages
    • Tribu
#4
  0
Great tutorial Shamousey!
Thetroz
« Citoyen »
1380727260000
    • Thetroz#0000
    • Profil
    • Derniers messages
    • Tribu
#5
  0
Thanks Shamousey
Good tutorial!!
Myutsu
« Citoyen »
1380727380000
    • Myutsu#5266
    • Profil
    • Derniers messages
    • Tribu
#6
  0
thanks
Brkeeee
« Censeur »
1380727680000
    • Brkeeee#0000
    • Profil
    • Derniers messages
    • Tribu
#7
  0
thanks!
Julioforum
« Citoyen »
1381196520000
    • Julioforum#0000
    • Profil
    • Derniers messages
    • Tribu
#8
  0
thanks shamousey
Xanmeow
« Citoyen »
1381281000000
    • Xanmeow#0000
    • Profil
    • Derniers messages
    • Tribu
#9
  0
thx but I need something to play on mechanical maps
Shamousey
« Consul »
1381281660000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#10
  0
Xanmeow a dit :
thx but I need something to play on mechanical maps

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
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#11
  0
Thanks for the tutorial, it's really useful to use your own map rotation in your tribe house.
Crizfm
« Citoyen »
1381768920000
    • Crizfm#0000
    • Profil
    • Derniers messages
#12
  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 :


function eventLoop(time,remaining)
if remaining<=0 then
tfm.exec.newGame(maps[math.random(#maps)])
tfm.exec.setGameTime(60)
end
if remaining <= 3 then
print("3")
end
if remaining <= 2 then
print("2")
end
if remaining <= 1 then
print("1")
end
end

and it doesn't work
Shamousey
« Consul »
1381824600000
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#13
  0
Crizfm a dit :
Thanks a lot Shamousey.I want to ask you a question. Can we make a countdown in tribe house?
If we can how?

The arguments in eventLoop use milliseconds. Try using "if remaining&lt;=3000 then" for example.
Theleetcoder
« Citoyen »
1382966220000
    • Theleetcoder#0000
    • Profil
    • Derniers messages
    • Tribu
#14
  0
Shamousey a dit :
The arguments in eventLoop use milliseconds. Try using "if remaining&amp;lt;=3000 then" for example.

You can also do that :

Theleetcoder a dit :
timer = 0

function eventLoop(actual, remaining)
timer = timer + (1/2) -- eventLoop work every 0.5 seconds. So, add + 0.5 at refreshing event.

if timer == 10 then -- About 10 seconds after the start.
print("FIGHT !")
end
end

function eventNewGame()
timer = 0 -- A new game start, reset the timer to 0.
end

 
Nathaan
« Citoyen »
1382971740000
    • Nathaan#0000
    • Profil
    • Derniers messages
    • Tribu
#15
  0
Theleetcoder a dit :
You can also do that :

 

Or you can use that :

a dit :
time = 5 -- 5 seconds

function eventLoop(actual, remaining)
time = time - 0.5

if time == 0.5 then -- Need 0.5, and the function launch when the time is "0", this is an bug.
print("Timer ended")
end
end

function eventNewGame()
time = 5
end
Theleetcoder
« Citoyen »
1382971980000
    • Theleetcoder#0000
    • Profil
    • Derniers messages
    • Tribu
#16
  0
Nathaan a dit :
Or you can use that :

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
    • Nathaan#0000
    • Profil
    • Derniers messages
    • Tribu
#17
  0
Theleetcoder 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.

No, it's not same.
You the start timer is "0", me it's the time. But it's same result.
Xanmeow
« Citoyen »
1385934960000
    • Xanmeow#0000
    • Profil
    • Derniers messages
    • Tribu
#18
  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
    • Shamousey#0095
    • Profil
    • Derniers messages
    • Tribu
#19
  0
Xanmeow a dit :
why doesnt this work?

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
    • Xanmeow#0000
    • Profil
    • Derniers messages
    • Tribu
#20
  0
Shamousey 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 <b>tfm.exec.disableAutoNewGame(true)</b>

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
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Module API] [Tutorial] Map Rotation
1 / 2 › »
© Atelier801 2018

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

Version 1.27