×

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][LUA] Basic Shop
[Tutorial][LUA] Basic Shop
Mawcn
« Citoyen »
1484381640000
    • Mawcn#0000
    • Profil
    • Derniers messages
    • Tribu
#1
  0
Hello and welcome to my first tutorial! I'll present how to create basic shop with likely skills (meep, shaman). So let's go!


So our first step will be define variables - admin (he will have 888888 coins) and player (he will have 0 coins).

Code Lua

1
2
admin = "Mawcn" -- put nick of admin here
cash = {}


OK, next step is creating shop area, set up cash for players and creating cash area.

Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
function eventNewPlayer(pN)
ui.addTextArea(1, "<a href = 'event:shop'>Shop!</a>", pN, 6, 25, 100, 20, 0x111111, 0x111111, 1, true) -- add shop area for player
system.bindMouse(pN, true)
if pN == admin then
cash[pN] = 888888 -- admin has 888888 cash
else
cash[pN] = 0 -- but the rest of players has 0 cash
end
ui.addTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- ..cash[pN].. will show cash quantity
end

for pN in pairs(tfm.get.room.playerList) do
eventNewPlayer(pN)
end -- set all players as new players


So, now let's do adding cash for all players every 500 ms

Code Lua

1
2
3
4
5
6
function eventLoop(eT,  rT)
for pN in pairs(tfm.get.room.playerList) do -- for all players in room do
cash[pN] = cash[pN] + 1 -- to actual cash value add cash enlarged by 1
ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- update cash area
end
end


And this is our last step - create shop interface

Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function eventTextAreaCallback(id, pN, req)
if req == "shop" then -- "shop" is our 'event:shop' in shop area code
ui.addTextArea(1, "Shop!\n-> <a href = 'event:meep'>Meep - 250 coins</a>\n-> <a href = 'event:vampire'>Vampire - 300 coins</a>\n-> <a href = 'event:shaman'>Shaman - 350 coins</a>", pN, 6, 25, 200, 85, 0x111111, 0x111111, 1, true) -- update shop area
elseif req == "meep" then -- "meep" is our 'event:meep' in updated shop area code
if cash[pN] >= 250 then -- check if player has more or same as 250 coins
cash[pN] = cash[pN] - 250 -- substract actual cash value for 250
tfm.exec.giveMeep(pN) -- give meep for player
ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true) -- update cash area
end
elseif req == "vampire" then
if cash[pN] >= 300 then
cash[pN] = cash[pN] - 300
tfm.exec.setVampirePlayer(pN)
ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true)
end
elseif req == "shaman" then
if cash[pN] >= 350 then
cash[pN] = cash[pN] - 350
tfm.exec.setShaman(pN)
ui.updateTextArea(2, "You have "..cash[pN].." coins!", pN, 625, 25, 170, 20, 0x111111, 0x111111, 1, true)
end
end
end



I hope guys you will like this tutorial and you will understand something... (bad english + my first tutorial)
PS: For editing text areas you can use online TextArea editor: http://laagtfm.esy.es/textarea/
Zoomapro
« Citoyen »
1484382540000
    • Zoomapro#0000
    • Profil
    • Derniers messages
#2
  0
Nice <3 thx u
Zajaci
« Censeur »
1484404140000
    • Zajaci#8309
    • Profil
    • Derniers messages
    • Tribu
#3
  0
Good luck! :)
Wentasre
« Censeur »
1484408340000
    • Wentasre#0000
    • Profil
    • Derniers messages
    • Tribu
#4
  0
nice guide
tried it and worked really well
Ajnoobz
« Citoyen »
1486377720000
    • Ajnoobz#0000
    • Profil
    • Derniers messages
#5
  0
Nice! Works well. Also, I now know more about lua programming! This tutorial is actually better than I expected! I didn't know too much about programming and now i know more :)

this is good make more

Dernière modification le 1493741340000
Ajnoobz
1490876820000
    • Ajnoobz#0000
    • Profil
    • Derniers messages
#6
[Modéré par Batt_mellamy, raison : Double post. Please edit your original post next time by clicking on your avatar/ username and pressing "Edit".]
Muutluerkek
« Citoyen »
1490884200000
    • Muutluerkek#0000
    • Profil
    • Derniers messages
    • Tribu
#7
  0
http://klasiktestdomain.tk/tedit/
old version textarea editor
Laagaadoo
« Citoyen »
1490900220000
    • Laagaadoo#0000
    • Profil
    • Derniers messages
    • Tribu
#8
  0
Muutluerkek a dit :
http://klasiktestdomain.tk/tedit/
old version textarea editor

you can still access it in http://laagtfm.esy.es/textarea/flash/ too.

nice tutorial
Haytam
« Citoyen »
1490973420000
    • Haytam#0000
    • Profil
    • Derniers messages
    • Tribu
#9
  0
that great thanks a lot how i can create i new event
like Shaman or meep
i want add speed and gravity and teleport
some thing like that can you please help me about that
Loghorizonph
« Citoyen »
1491792720000
    • Loghorizonph#0000
    • Profil
    • Derniers messages
    • Tribu
#10
  0
how to Add snowball cannon in shop ?
Borntolol
« Citoyen »
1496279760000
    • Borntolol#0000
    • Profil
    • Derniers messages
    • Tribu
#11
  0
Sorry to bother but would u know how to make a coin multiplier>?
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Tutorial][LUA] Basic Shop
© Atelier801 2018

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

Version 1.27