×

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 Snippets
[Tutorial] Lua Snippets
Bolodefchoco
« Sénateur »
1558010280000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#1
  5

http://img.atelier801.com/9124f272.png

Um snippet, traduzido ao pé da letra como fragmento, é um pedacinho de código pequeno que faz algo interessante mas não precisa de um tópico só para ele.

Regras e recomendações:
• Não poste códigos extremamente grandes. Utilize o pastebin para isso.
• Procure sempre utilizar o formato [code=Lua]Código[/code], dessa forma deixará seu código legível e colorido.
• Caso seu código não seja extremamente grande, mas também não extremamente pequeno, utilize um spoiler:
Código que faz malabarismo

Code Lua

1
-- Aqui

• Escreva uma breve descrição da funcionalidade do seu código, assim saberão o que ele faz sem a necessidade de teste.


Exemplo a dit :
Mover os jogadores aleatoriamente no mapa!
Code Lua

1
2
3
4
5
eventLoop = function()
for n in next, tfm.get.room.playerList do
tfm.exec.movePlayer(n, math.random(800), math.random(400))
end
end

Dernière modification le 1558010400000
Mashmellliiiiiw
« Censeur »
1558023600000
    • Mashmellliiiiiw#7990
    • Profil
    • Derniers messages
    • Tribu
#2
  0
:''O Meow
Infectsoul
1558054860000
    • Infectsoul#2048
    • Profil
    • Derniers messages
    • Tribu
#3
[Modéré par Kiwrimai, raison : Removido a pedido do autor.]

Dernière modification le 1575922080000
Hugotitas
« Citoyen »
1558084080000
    • Hugotitas#0000
    • Profil
    • Derniers messages
    • Tribu
#4
  4
Ratufufu a dit :
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

https://i.imgur.com/VTPv6DK.png

ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

ㅤ▸Uma simples função para criar circunferências com partículas, pisos ou textArea.
Partículas a dit :
Code Lua

1
2
3
4
5
6
7
8
9
10
-- circumference(Coordenada x,Coordenada y,Raio,Ângulo inicial,Ângulo Final,Espaçamento entre os ângulos)

circumference = function(x,y,radius,sa,fa,spacing)
for i = sa,fa,(sa < fa and spacing or -spacing) do
local ad = (math.cos(math.rad(i)) * radius)
local op = (math.sin(math.rad(i)) * radius)
tfm.exec.displayParticle (11,(x + ad),(y - op),0,0,0,0,nil)
end
end
circumference(400,200,100,0,360,10)

ㅤ▸ Podendo substituir ohttps://i.imgur.com/qa4RWpQ.png por:


Piso a dit :
tfm.exec.addPhysicObject (i,(x + ad),(y - op),{type = 0, width = 20, height = 20, friction = 0.3, restitution = 0.2, angle = (-i + 90)})

ㅤㅤㅤㅤㅤㅤㅤㅤㅤSem ângulo: https://i.imgur.com/VkuTk9J.pngㅤㅤㅤCom ângulo (-i + 90): https://i.imgur.com/jm1P4py.png

textArea a dit :
ui.addTextArea(i,'',nil,(x + ad) - 5,(y - op) - 5,10,10,'0x2e334d','0x25293d',1,true)

Exemplos
Efeitos a dit :
Ondas:
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
-- circumference(Coordenada x,Coordenada y,Raio,Ângulo inicial,Ângulo Final,Espaçamento entre os ângulos)

circumference = function(x,y,radius,sa,fa,spacing)
local value = 0
for i = sa,fa,(sa < fa and spacing or -spacing) do
value = (value + 0.08)
local ad = (math.cos(math.rad(i + value)) * radius)
local op = (math.sin(math.rad(i - value)) * radius)
tfm.exec.displayParticle (11,(x + ad - value),(y - op),0,0,0,0,nil)
end
end
circumference(800,200,100,0,100000,10)
Paleta:
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
local value = 0

circumference = function(x,y,radius,sa,fa,spacing)
for i = sa,fa,(sa < fa and spacing or -spacing) do
local ad = (math.cos(math.rad(i)) * radius)
local op = (math.sin(math.rad(i)) * radius)
tfm.exec.displayParticle (11,(x + ad),(y - op),0,0,0,0,nil)
tfm.exec.addPhysicObject (i,x + ad,y - op,{type = 12, width = 20, height = 60, friction = 0.3, restitution = 0.2, angle = (-i+90), color = '0x'..string.format("%x",math.random(1,16777215))})
end
end

eventLoop = function()
if value == 36 then value = 0 end
value = (value + 1)
circumference(400,200,100,(value - 1) * 10,value * 10,5)
end


Amei, muito bom!
Infectsoul
1558106340000
    • Infectsoul#2048
    • Profil
    • Derniers messages
    • Tribu
#5
[Modéré par Kiwrimai, raison : Removido a pedido do autor.]

Dernière modification le 1575922080000
Infectsoul
1560721260000
    • Infectsoul#2048
    • Profil
    • Derniers messages
    • Tribu
#6
[Modéré par Kiwrimai, raison : Removido a pedido do autor.]

Dernière modification le 1575922080000
Bolodefchoco
« Sénateur »
1560780180000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#7
  0
Ameeeei ↑
Gamedroit
« Citoyen »
1562540640000
    • Gamedroit#3347
    • Profil
    • Derniers messages
    • Tribu
#8
  1
Ratufufu a dit :
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

https://i.imgur.com/okEILbn.png

ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
a dit :
Shader
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
shader = function(color,merge,saturation,brightness)
local color = (type(color) == 'table' and (#color == 0 and {'ffffff'} or color) or color and {color} or {'ffffff'})
local merge = (merge and (merge < 0 and 0 or merge > 100 and 100 or merge) or 0)
local config = {_id = 0,_current = (#color == 1 and 1 or math.ceil(merge / (100 / (#color - 1)))),_division = (100 / (#color - 1)),_rgb = {},_hex = {}}
for v,c in next, color do
if (v == config._current or v == config._current + 1) then
config._id = (config._id + 1)
config._rgb[config._id] = {}
for convert in string.gmatch(c,'(..)') do
config._rgb[config._id][#config._rgb[config._id] + 1] = tonumber(convert,16)
end
end
end
while merge > config._division do merge = merge - config._division end
for v,c in next, config._rgb[1] do
for _,b in next, {(config._rgb[2] and (merge > 0 and merge <= 100) and {config._rgb[2][v],merge * (#color - 1)} or nil),((saturation or 0) ~= 0 and {255,saturation} or nil),((brightness or 0) ~= 0 and {0,brightness}) or nil} do
config._rgb[1][v] = config._rgb[1][v] + ((b[1] - config._rgb[1][v]) * (b[2]) / 100)
end
config._hex[#config._hex + 1] = string.format('%x', (config._rgb[1][v] > 255 and 255 or config._rgb[1][v] < 0 and 0 or config._rgb[1][v]))
end
for i=1,#config._hex do config._hex[i] = (config._hex[i]:len() == 1 and '0'..config._hex[i] or config._hex[i]) end
return table.concat(config._hex,'')
end

• shader(color,merge,saturation,brightness)
ㅤUma função que retorna a cor primária modificada em relação ao ((gradiente/degradê)/saturação/brilho)
ㅤParâmetros:
ㅤㅤ- color(table): uma tabela com uma ou mais cores (valor padrão = {'ffffff'})
ㅤㅤ- merge(int)(0% - 100%): caso (color) haja mais de uma cor, o valor de (merge) vai formando uma transição suave entre as cores (valor padrão = 0)
ㅤㅤ- saturation(int)(0% - 100%): modifica a saturação da cor primária (valor padrão = 0)
ㅤㅤ- brightness(int)(0% - 100%): modifica o brilho da cor primária (valor padrão = 0)

Lista com alguns exemplos:

Merge/Saturation/Brightness

Merge:
https://i.imgur.com/oxfmD0w.png

Saturation:
https://i.imgur.com/iylBeSO.png

Brightness:
https://i.imgur.com/5wEx40a.png


Interface
Criar uma interface manipulável.

Barra:
https://i.imgur.com/JVssxu0.png

Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
-- Coloque a função shader acima.

local color = {'ffff00','00ffff'}
local background = '505050'

local id = 0

eventLoop = function()
id = (id + 1)
if id >= 100 then id = 100 end
ui.addTextArea(1,'',nil,50,182,700,30,'0x'..shader(background,0,20,0),'0x'..shader(background,0,20,0),1,true)
ui.addTextArea(2,'',nil,50,188,700,30,'0x'..shader(background,0,0,20),'0x'..shader(background,0,0,20),1,true)
ui.addTextArea(3,'',nil,50,185,700,30,'0x'..shader(background,0,0,0),'0x'..shader(background,0,0,0),1,true)
ui.addTextArea(4,'',nil,55,190,690,20,'0x'..shader(background,0,0,40),'0x'..shader(background,0,0,40),1,true)
ui.addTextArea(5,'',nil,55,190,(690 / 100) * id,20,'0x'..shader(color,id,0,0),'0x'..shader(color,id,0,0),1,true)
end



Caixa de texto:
https://i.imgur.com/sUt0BKc.png

Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
-- Coloque a função shader acima.

local background = 'ff6060'

ui.addTextArea(1,'',nil,300,96,200,200,'0x'..shader(background,0,20,0),'0x'..shader(background,0,20,0),1,true)
ui.addTextArea(2,'',nil,300,104,200,200,'0x'..shader(background,0,0,20),'0x'..shader(background,0,0,20),1,true)
ui.addTextArea(3,'',nil,300,100,200,200,'0x'..shader(background,0,0,0),'0x'..shader(background,0,0,0),1,true)
ui.addTextArea(4,'',nil,340,118,120,20,'0x'..shader(background,0,0,70),'0x'..shader(background,0,0,70),1,true)
ui.addTextArea(5,'',nil,340,122,120,20,'0x'..shader(background,0,0,30),'0x'..shader(background,0,0,30),1,true)
ui.addTextArea(6,'',nil,340,120,120,20,'0x'..shader(background,0,0,50),'0x'..shader(background,0,0,50),1,true)
ui.addTextArea(7,'<font size="14" color="#'..shader(background,0,60,0)..'"><p align="center">Título</p></font>',nil,340,120,120,30,'0x1','0x1',0,true)
ui.addTextArea(8,'<font size="10" color="#'..shader(background,0,100,0)..'">Escreva seu texto aqui!</font>',nil,305,150,190,150,'0x1','0x1',0,true)


Joints/Desenho

Armchair
https://i.imgur.com/wVDBzaD.png

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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- Coloque a função shader acima.

local color = {'ffff40'}

armchair = function(x,y)
local id_joint,id_ground = 0,0
local grounds = {
['type'] = {14,14,14},
['x'] = {(x - 1),(x - 72),(x + 70)},
['y'] = {(y + 13),(y + 8),(y + 7)},
['width'] = {110,28,28},
['height'] = {30,52,52},
['foreground'] = {0,0,0},
['friction'] = {0.3,0.3,0.3},
['restitution'] = {0.7,0.4,0.4},
['angle'] = {0,0,0},
['color'] = {'f75c1','48cffe','e3cbb6'},
['miceCollision'] = {true,true,true},
['groundCollision'] = {true,true,true},
['dynamic'] = {0,0,0},
['fixedRotation'] = {0,0,0},
['mass'] = {0,0,0},
['linearDamping'] = {0,0,0},
['angularDamping'] = {0,0,0},
}
local joints = {
['type'] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
['m1'] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
['m2'] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
['point1'] = {(x + 5)..','..(y + 7),(x - 51)..','..(y + 7),(x + 53)..','..(y + 3),(x - 54)..','..(y + 3),(x + 75)..','..(y - 11),(x + 68)..','..(y - 11),(x + 62)..','..(y - 15),(x + 81)..','..(y - 15),(x + 62)..','..(y + 13),(x - 75)..','..(y - 11),(x - 68)..','..(y - 11),(x - 82)..','..(y - 14),(x - 62)..','..(y - 15),(x - 62)..','..(y + 13),(x - 83)..','..(y + 29),(x + 71)..','..(y + 28),(x + 80)..','..(y + 29),(x - 71)..','..(y + 28),(x - 85)..','..(y + 18),(x + 84)..','..(y + 18),(x - 85)..','..(y + 19),(x - 85)..','..(y + 22),(x - 85)..','..(y + 23),(x - 59)..','..(y - 5),(x - 61)..','..(y + 6),(x - 64)..','..(y + 10),(x - 68)..','..(y + 13),(x - 72)..','..(y + 13),(x - 78)..','..(y + 12),(x - 82)..','..(y + 10),(x - 61)..','..(y + 8),(x - 62)..','..(y + 12),(x - 63)..','..(y + 15),(x - 79)..','..(y + 15),(x - 59)..','..(y + 5),(x - 56)..','..(y + 9),(x - 54)..','..(y + 10),(x - 50)..','..(y + 11),(x - 43)..','..(y + 12),(x - 34)..','..(y + 13),(x - 22)..','..(y + 13),(x - 15)..','..(y + 12),(x - 8)..','..(y + 10),(x - 4)..','..(y + 7),(x - 1)..','..(y + 2),(x + 1)..','..(y + 8),(x + 3)..','..(y + 10),(x + 7)..','..(y + 12),(x + 15)..','..(y + 13),(x + 27)..','..(y + 14),(x + 39)..','..(y + 14),(x + 49)..','..(y + 13),(x + 54)..','..(y + 11),(x + 57)..','..(y + 7),(x - 57)..','..(y + 15),(x - 43)..','..(y + 14),(x - 56)..','..(y + 12),(x - 15)..','..(y + 14),(x + 3)..','..(y + 12),(x - 11)..','..(y + 12),(x + 56)..','..(y + 15),(x + 51)..','..(y + 14),(x + 59)..','..(y + 7),(x + 62)..','..(y + 10),(x + 65)..','..(y + 12),(x + 68)..','..(y + 13),(x + 73)..','..(y + 14),(x + 75)..','..(y + 14),(x + 78)..','..(y + 12),(x + 81)..','..(y + 9),(x + 83)..','..(y + 8),(x + 81)..','..(y + 15),(x + 60)..','..(y + 11),(x + 76)..','..(y + 15),(x + 56)..','..(y + 17),(x + 57)..','..(y - 1),(x + 57)..','..(y - 1),(x + 59)..','..(y + 17),(x + 84)..','..(y - 15),(x - 4)..','..(y + 17),(x - 1)..','..(y + 14),(x - 1)..','..(y + 1),(x - 3)..','..(y - 1),(x - 57)..','..(y - 1),(x - 58)..','..(y - 1),(x - 59)..','..(y + 15),(x - 85)..','..(y + 16),(x - 85)..','..(y - 15),(x - 62)..','..(y - 18),(x - 82)..','..(y - 18),(x - 59)..','..(y - 15),(x + 84)..','..(y + 26),(x + 70)..','..(y + 26),(x + 70)..','..(y + 31),(x - 84)..','..(y + 26),(x - 84)..','..(y + 31),(x - 68)..','..(y + 26),(x - 86)..','..(y + 26),(x - 87)..','..(y + 24),(x - 87)..','..(y + 19),(x - 1)..','..(y + 17),(x + 84)..','..(y + 26),(x - 86)..','..(y + 26),(x - 1)..','..(y + 26),(x + 86)..','..(y + 24),(x + 86)..','..(y + 19),(x - 86)..','..(y + 17),(x - 1)..','..(y + 17),(x - 84)..','..(y - 17),(x - 60)..','..(y - 17),(x - 1)..','..(y + 1),(x + 2)..','..(y - 1),(x + 59)..','..(y - 15),(x + 60)..','..(y - 17),(x + 62)..','..(y - 18),(x + 81)..','..(y - 18),(x + 83)..','..(y - 17),(x - 2)..','..(y - 15),(x - 6)..','..(y - 18),(x - 64)..','..(y - 27),(x - 60)..','..(y - 26),(x - 43)..','..(y - 29),(x - 29)..','..(y - 29),(x - 53)..','..(y - 13),(x - 6)..','..(y - 29),(x - 53)..','..(y - 20),(x - 40)..','..(y - 10),(x - 15)..','..(y - 9),(x + 2)..','..(y - 27),(x + 4)..','..(y - 26),(x + 13)..','..(y - 27),(x + 21)..','..(y - 28),(x + 33)..','..(y - 28),(x + 42)..','..(y - 29),(x + 50)..','..(y - 28),(x + 62)..','..(y - 27),(x + 60)..','..(y - 27),(x + 31)..','..(y - 6),(x + 10)..','..(y - 21),(x + 15)..','..(y - 19),(x - 64)..','..(y - 26),(x - 62)..','..(y - 24),(x - 60)..','..(y - 24),(x - 57)..','..(y - 19),(x - 53)..','..(y - 16),(x - 48)..','..(y - 14),(x - 45)..','..(y - 14),(x - 38)..','..(y - 14),(x - 33)..','..(y - 15),(x - 39)..','..(y - 12),(x - 39)..','..(y - 13),(x - 36)..','..(y - 14),(x - 61)..','..(y - 23),(x - 63)..','..(y - 25),(x - 59)..','..(y - 20),(x - 44)..','..(y - 10),(x - 41)..','..(y - 7),(x - 37)..','..(y - 5),(x - 33)..','..(y - 4),(x - 25)..','..(y - 3),(x - 20)..','..(y - 3),(x - 13)..','..(y - 4),(x - 9)..','..(y - 6),(x - 6)..','..(y - 10),(x - 5)..','..(y - 13),(x - 5)..','..(y - 6),(x - 6)..','..(y - 8),(x - 8)..','..(y - 3),(x - 25)..','..(y - 1),(x - 57)..','..(y - 17),(x - 44)..','..(y - 12),(x - 53)..','..(y - 13),(x - 49)..','..(y - 11),(x - 5)..','..(y - 14),(x - 5)..','..(y - 26),(x - 4)..','..(y - 27),(x - 7)..','..(y - 25),(x - 6)..','..(y - 25),(x + 2)..','..(y - 26),(x + 3)..','..(y - 25),(x + 2)..','..(y - 21),(x + 3)..','..(y - 16),(x + 5)..','..(y - 10),(x + 7)..','..(y - 7),(x + 9)..','..(y - 6),(x + 13)..','..(y - 5),(x + 20)..','..(y - 5),(x + 29)..','..(y - 6),(x + 36)..','..(y - 5),(x + 39)..','..(y - 5),(x + 44)..','..(y - 6),(x + 49)..','..(y - 8),(x + 55)..','..(y - 12),(x + 58)..','..(y - 17),(x + 59)..','..(y - 23),(x + 63)..','..(y - 26),(x + 60)..','..(y - 23),(x + 63)..','..(y - 26),(x + 63)..','..(y - 28),(x + 2)..','..(y - 26),(x + 3)..','..(y - 26),(x + 1)..','..(y - 14),(x + 1)..','..(y - 6),(x + 2)..','..(y - 15),(x + 4)..','..(y - 7),(x + 9)..','..(y - 2),(x + 43)..','..(y - 3),(x + 57)..','..(y - 4),(x + 30)..','..(y - 6),(x + 37)..','..(y - 10),(x + 35)..','..(y - 8),(x - 63)..','..(y - 18),(x - 63)..','..(y - 22),(x - 65)..','..(y - 27),(x - 65)..','..(y - 29),(x - 60)..','..(y - 28),(x - 56)..','..(y - 29),(x - 51)..','..(y - 30),(x - 41)..','..(y - 31),(x - 31)..','..(y - 31),(x - 19)..','..(y - 30),(x - 10)..','..(y - 29),(x - 6)..','..(y - 30),(x - 2)..','..(y - 30),(x - 4)..','..(y - 27),(x - 5)..','..(y - 24),(x - 4)..','..(y - 17),(x - 4)..','..(y - 7),(x + 1)..','..(y - 1),(x)..','..(y - 6),(x)..','..(y - 14),(x + 1)..','..(y - 19),(x + 2)..','..(y - 25),(x)..','..(y - 27),(x)..','..(y - 29),(x + 4)..','..(y - 28),(x + 10)..','..(y - 29),(x + 19)..','..(y - 30),(x + 33)..','..(y - 30),(x + 39)..','..(y - 31),(x + 44)..','..(y - 31),(x + 50)..','..(y - 30),(x + 56)..','..(y - 28),(x + 61)..','..(y - 29),(x + 64)..','..(y - 29),(x + 64)..','..(y - 26),(x + 63)..','..(y - 23),(x + 62)..','..(y - 21)},
['point2'] = {(x + 50)..','..(y + 7),(x - 7)..','..(y + 7),(x + 53)..','..(y + 8),(x - 54)..','..(y + 9),(x + 75)..','..(y + 10),(x + 68)..','..(y + 9),(x + 81)..','..(y - 15),(x + 81)..','..(y + 12),(x + 62)..','..(y - 16),(x - 76)..','..(y + 8),(x - 67)..','..(y + 8),(x - 82)..','..(y + 12),(x - 83)..','..(y - 15),(x - 62)..','..(y - 15),(x - 70)..','..(y + 29),(x + 82)..','..(y + 28),(x + 82)..','..(y + 29),(x - 70)..','..(y + 28),(x - 85)..','..(y + 25),(x + 84)..','..(y + 25),(x + 83)..','..(y + 19),(x + 83)..','..(y + 22),(x + 83)..','..(y + 23),(x - 61)..','..(y + 6),(x - 64)..','..(y + 10),(x - 68)..','..(y + 13),(x - 72)..','..(y + 13),(x - 78)..','..(y + 12),(x - 82)..','..(y + 10),(x - 85)..','..(y + 6),(x - 61)..','..(y + 15),(x - 71)..','..(y + 14),(x - 83)..','..(y + 15),(x - 83)..','..(y + 11),(x - 56)..','..(y + 9),(x - 54)..','..(y + 10),(x - 50)..','..(y + 11),(x - 43)..','..(y + 12),(x - 34)..','..(y + 13),(x - 22)..','..(y + 13),(x - 15)..','..(y + 12),(x - 8)..','..(y + 10),(x - 4)..','..(y + 7),(x - 1)..','..(y + 2),(x + 1)..','..(y + 8),(x + 3)..','..(y + 10),(x + 7)..','..(y + 12),(x + 15)..','..(y + 13),(x + 27)..','..(y + 14),(x + 39)..','..(y + 14),(x + 49)..','..(y + 13),(x + 54)..','..(y + 11),(x + 57)..','..(y + 7),(x + 59)..','..(y),(x + 57)..','..(y + 15),(x - 57)..','..(y + 12),(x - 58)..','..(y + 8),(x + 6)..','..(y + 13),(x - 2)..','..(y + 7),(x)..','..(y + 9),(x + 57)..','..(y + 9),(x + 55)..','..(y + 13),(x + 62)..','..(y + 10),(x + 65)..','..(y + 12),(x + 68)..','..(y + 13),(x + 73)..','..(y + 14),(x + 75)..','..(y + 14),(x + 78)..','..(y + 12),(x + 81)..','..(y + 9),(x + 84)..','..(y + 3),(x + 82)..','..(y + 15),(x + 60)..','..(y + 15),(x + 67)..','..(y + 15),(x + 82)..','..(y + 11),(x + 59)..','..(y + 14),(x + 59)..','..(y - 4),(x + 59)..','..(y + 1),(x + 59)..','..(y - 15),(x + 84)..','..(y + 17),(x - 1)..','..(y + 14),(x + 2)..','..(y + 17),(x - 1)..','..(y + 17),(x - 1)..','..(y + 1),(x - 59)..','..(y + 1),(x - 3)..','..(y - 1),(x - 56)..','..(y + 17),(x - 85)..','..(y - 15),(x - 84)..','..(y - 17),(x - 60)..','..(y - 17),(x - 62)..','..(y - 18),(x - 59)..','..(y + 16),(x + 84)..','..(y + 31),(x + 70)..','..(y + 31),(x + 84)..','..(y + 31),(x - 84)..','..(y + 31),(x - 68)..','..(y + 31),(x - 68)..','..(y + 31),(x - 87)..','..(y + 24),(x - 87)..','..(y + 19),(x - 86)..','..(y + 17),(x - 1)..','..(y + 25),(x + 86)..','..(y + 24),(x - 1)..','..(y + 26),(x + 84)..','..(y + 26),(x + 86)..','..(y + 19),(x + 85)..','..(y + 17),(x - 1)..','..(y + 17),(x + 84)..','..(y + 17),(x - 82)..','..(y - 18),(x - 59)..','..(y - 15),(x + 2)..','..(y - 1),(x + 58)..','..(y - 1),(x + 60)..','..(y - 17),(x + 62)..','..(y - 18),(x + 81)..','..(y - 18),(x + 83)..','..(y - 17),(x + 84)..','..(y - 15),(x - 2)..','..(y + 2),(x + 4)..','..(y - 18),(x - 6)..','..(y - 13),(x - 43)..','..(y - 29),(x - 29)..','..(y - 29),(x - 7)..','..(y - 27),(x - 6)..','..(y - 28),(x - 4)..','..(y - 29),(x - 23)..','..(y - 22),(x - 13)..','..(y - 9),(x - 13)..','..(y - 21),(x + 6)..','..(y - 26),(x + 14)..','..(y - 27),(x + 21)..','..(y - 28),(x + 33)..','..(y - 28),(x + 42)..','..(y - 29),(x + 50)..','..(y - 28),(x + 59)..','..(y - 25),(x + 17)..','..(y - 4),(x + 10)..','..(y - 5),(x + 53)..','..(y - 18),(x + 12)..','..(y - 12),(x + 46)..','..(y - 22),(x - 62)..','..(y - 24),(x - 60)..','..(y - 24),(x - 57)..','..(y - 19),(x - 53)..','..(y - 16),(x - 48)..','..(y - 14),(x - 40)..','..(y - 13),(x - 38)..','..(y - 14),(x - 33)..','..(y - 15),(x - 39)..','..(y - 12),(x - 44)..','..(y - 9),(x - 48)..','..(y - 7),(x - 40)..','..(y - 13),(x - 60)..','..(y - 15),(x - 57)..','..(y - 2),(x - 56)..','..(y - 2),(x - 41)..','..(y - 7),(x - 37)..','..(y - 5),(x - 33)..','..(y - 4),(x - 25)..','..(y - 3),(x - 15)..','..(y - 3),(x - 13)..','..(y - 4),(x - 9)..','..(y - 6),(x - 6)..','..(y - 10),(x - 5)..','..(y - 15),(x - 5)..','..(y - 6),(x - 6)..','..(y - 2),(x - 8)..','..(y - 3),(x - 15)..','..(y - 2),(x - 53)..','..(y - 3),(x - 52)..','..(y - 4),(x - 55)..','..(y - 14),(x - 46)..','..(y - 4),(x - 38)..','..(y - 2),(x - 5)..','..(y - 21),(x - 6)..','..(y - 12),(x - 7)..','..(y - 25),(x - 5)..','..(y - 23),(x - 5)..','..(y - 24),(x + 3)..','..(y - 25),(x + 1)..','..(y - 14),(x + 3)..','..(y - 16),(x + 5)..','..(y - 10),(x + 7)..','..(y - 7),(x + 9)..','..(y - 6),(x + 13)..','..(y - 5),(x + 20)..','..(y - 5),(x + 29)..','..(y - 6),(x + 36)..','..(y - 5),(x + 39)..','..(y - 5),(x + 44)..','..(y - 6),(x + 49)..','..(y - 8),(x + 55)..','..(y - 12),(x + 58)..','..(y - 17),(x + 59)..','..(y - 23),(x + 63)..','..(y - 26),(x + 53)..','..(y - 2),(x + 51)..','..(y - 2),(x + 64)..','..(y - 29),(x + 59)..','..(y - 22),(x)..','..(y - 28),(x)..','..(y - 29),(x + 1)..','..(y - 6),(x + 3)..','..(y),(x + 4)..','..(y - 3),(x + 9)..','..(y - 2),(x + 57)..','..(y - 2),(x + 61)..','..(y - 9),(x + 60)..','..(y - 12),(x + 37)..','..(y - 10),(x + 32)..','..(y - 4),(x + 30)..','..(y - 5),(x - 63)..','..(y - 22),(x - 65)..','..(y - 27),(x - 65)..','..(y - 29),(x - 60)..','..(y - 28),(x - 56)..','..(y - 29),(x - 51)..','..(y - 30),(x - 41)..','..(y - 31),(x - 31)..','..(y - 31),(x - 19)..','..(y - 30),(x - 10)..','..(y - 29),(x - 6)..','..(y - 30),(x - 2)..','..(y - 30),(x - 4)..','..(y - 27),(x - 5)..','..(y - 24),(x - 4)..','..(y - 17),(x - 4)..','..(y - 7),(x - 5)..','..(y - 1),(x)..','..(y - 6),(x)..','..(y - 14),(x + 1)..','..(y - 19),(x + 2)..','..(y - 25),(x)..','..(y - 27),(x)..','..(y - 29),(x + 4)..','..(y - 28),(x + 10)..','..(y - 29),(x + 19)..','..(y - 30),(x + 33)..','..(y - 30),(x + 39)..','..(y - 31),(x + 44)..','..(y - 31),(x + 50)..','..(y - 30),(x + 56)..','..(y - 28),(x + 61)..','..(y - 29),(x + 64)..','..(y - 29),(x + 64)..','..(y - 26),(x + 63)..','..(y - 23),(x + 62)..','..(y - 21),(x + 61)..','..(y - 18)},
['point3'] = {},
['point4'] = {},
['frequency'] = {},
['damping'] = {},
['axis'] = {},
['angle'] = {},
['limit1'] = {},
['limit2'] = {},
['forceMotor'] = {},
['speedMotor'] = {},
['ratio'] = {},
['color'] = {10,10,10,10,15,15,15,15,15,15,15,15,15,15,65,70,70,70,50,50,55,50,50,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,62,62,62,53,53,62,62,62,62,62,53,62,52,52,52,52,52,68,68,68,70,70,70,59,59,59,67,64,72,74,64,64,63,66,52,52,62,53,53,53,53,53,53,70,70,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60,60},
['line'] = {16,16,10,10,10,10,4,4,4,14,14,4,4,4,4,4,4,4,2,2,4,4,4,2,2,2,2,2,2,2,4,4,4,5,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4,4,4,4,4,2,2,2,2,2,2,2,2,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,6,4,3,4,4,4,4,2,16,16,16,2,4,4,4,4,4,4,4,4,16,16,16,2,2,2,2,2,2,1,1,1,1,2,1,4,2,4,2,2,2,2,2,2,2,2,2,2,2,4,4,4,4,4,6,6,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2,2,4,6,6,6,6,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
['alpha'] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
['foreground'] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
}

for v = 1,#grounds['type'] do
tfm.exec.addPhysicObject(id_ground + v,grounds['x'][v],grounds['y'][v],{type = grounds['type'][v] ,width = grounds['width'][v] , height = grounds['height'][v] , foreground = (grounds['foreground'][v] ~= 0) , friction = grounds['friction'][v] , restitution = grounds['restitution'][v] , angle = grounds['angle'][v] , color = '0x'..(grounds['color'][v] or '000000') , miceCollision = grounds['miceCollision'][v] , groundCollision = grounds['groundCollision'][v] , dynamic = (grounds['dynamic'][v] ~= 0) , fixedRotation = (grounds['fixedRotation'][v] ~= 0) , mass = grounds['mass'][v] , linearDamping = grounds['linearDamping'][v] , angularDamping = grounds['angularDamping'][v]})
end

for v = 1,#joints['type'] do
tfm.exec.addJoint(id_joint + v,id_ground + joints['m1'][v],id_ground + joints['m2'][v],{type = joints['type'][v] , point1 = joints['point1'][v] , point2 = joints['point2'][v] , point3 = joints['point3'][v] , point4 = joints['point4'][v] , frequency = joints['frequency'][v] , damping = joints['damping'][v] , axis = joints['axis'][v] , angle = joints['angle'][v] , limit1 = joints['limit1'][v] , limit2 = joints['limit2'][v] , forceMotor = joints['forceMotor'][v] , speedMotor = joints['speedMotor'][v] , ratio = joints['ratio'][v] , color = '0x'..shader(color,0,0,joints['color'][v]) , line = joints['line'][v] , alpha = joints['alpha'][v] , foreground = (joints['foreground'][v] ~= 0) })
end
end
armchair(400,200)

Sphere
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤhttps://i.imgur.com/cdHaWCj.pngㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
Code Lua

1
2
3
4
5
6
7
-- Coloque a função shader acima.

local color = {'2020ff','90ffff'}

for i=1,50 do
tfm.exec.addPhysicObject (i,400 - (i/2),200 - (i / 1.2),{type = 13, width = (60 - i), height = 10, friction = 0.3, restitution = 0.2, angle = -i, color = '0x'..shader(color,(i * 2),0,(90 - (i * 2)))})
end

Circumference

https://i.imgur.com/EzEjeYh.png

Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
-- Coloque a função shader acima.

local color = {'2020ff','90ffff','00ff00','ff00ff'}

circumference = function(x,y,radius,sa,fa,spacing)
for i = sa,fa,(sa < fa and spacing or -spacing) do
local ad = (math.cos(math.rad(i)) * radius)
local op = (math.sin(math.rad(i)) * radius)
tfm.exec.addPhysicObject (i,x + ad,y - op,{type = 12, width = 40, height = 10, friction = 0.3, restitution = 0.2, angle = -i, color = '0x'..shader(color,(i / (fa / 100)),0,0)})
end
end
circumference(400,200,80,0,360,2)


wow :3 incrível como um código tão pequeno pode fazer algo tão grandioso ...
Sklag
« Citoyen »
1585014420000
    • Sklag#2552
    • Profil
    • Derniers messages
    • Tribu
#9
  1
Previnindo Itens de Shaman

Code Lua

1
2
3
4
5
eventSummoningEnd = function(playerName, objectType, xPosition, yPosition, angle, objectDescription)
tfm.exec.removeObject(objectDescription.id)
end

tfm.exec.newGame(1)

Dernière modification le 1662762540000
Jp_darkuss
« Citoyen »
1588440780000
    • Jp_darkuss#4806
    • Profil
    • Derniers messages
#10
  0
Rainbow Nickname

Code Lua

1
2
3
4
5
6
local colors= {"0xff6666", "0x66ff66", "0x6666ff", "0xFF8E00", "0x22287D", "0xA33FA4", "0xFFFF0D"}
eventLoop= function()
for i in next, tfm.get.room.playerList do
tfm.exec.setNameColor(i, colors[math.random(1, #colors)])
end
end


Esse script fica mudando a cor do nome de todos os players de forma aleatória. Ele varia nas cores do arco-íris (Vermelho, Laranja, Amarelo, Verde, Azul, Anil e Violeta). Bom uso! :)

Dernière modification le 1588450860000
Bolodefchoco
« Sénateur »
1588442820000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#11
  0
Era bom criar a tabela fora, não tem sentido recriar toda hora
Jp_darkuss
« Citoyen »
1588450920000
    • Jp_darkuss#4806
    • Profil
    • Derniers messages
#12
  0
Bolodefchoco a dit :
Era bom criar a tabela fora, não tem sentido recriar toda hora

Já consertei, mas na real terminei agora, tava faltando cor e nem funcionava. Vlw.
Gamedroit
« Citoyen »
1623353580000
    • Gamedroit#3347
    • Profil
    • Derniers messages
    • Tribu
#13
  0
Este é um script de física 2D simples que serve para verificar colisões entre pontos, objetos retangulares e circulares.
https://pastebin.com/1rksXT2f

Exemplos

Digamos que você precisa saber se um piso dinâmico circular colidiu com outro piso circular, basta ter suas coordendas (x, y) e seu raio (largura) para que o sistema possa calcular se eles colidiram ou não.
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
local piso1 = {
x = 50,
y = 20,
radius = 30 -- tamanho (x)
}

local piso2 = {
x = 70,
y = 30,
radius = 40 -- tamanho (x)
}

if (system.physics.collidecircle(piso1.x, piso1.y, piso2.x, piso2.y, piso1.radius, piso2.radius)) then
print('Os pisos circulares colidiram!')
end

Agora digamos que precisa fazer um jogo de tiro básico mas não sabe como dizer se a bala atingiu outro jogador, nesse caso você somente vai precisar das coordenadas de quem atirou, também é necessário (no caso do transformice) as coordenadas de onde o jogador clicou e opcionalmente você pode definir uma distância limite como 200 ou 400
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local player = {
x = 200,
y = 100
}
local mouseClick = {
x = 300,
y = 200
}

-- A função retorna uma tabela contendo informações como mapeamento (desde onde o jogador atirou até o limite), distância, ângulo e offset
local info = system.physics.raycast(player.x, player.y, mouseClick.x, mouseClick.y, 400)

-- Para saber se colide com outro jogador podemos fazer:
-- Pode ser um pouco lento, mas o mice é muito limitado
for k, v in next, info.map do
for player, data in next, tfm.get.room.playerList do
if (system.physics.collidepoint(data.x, data.y, v.x, v.y, 15, 15)) then
print('colidiu com '..player)
end
end
end



As funções disponíveis são system.physics.collidepoint(x, y, x2, y2, w, h), system.physics.collidecircle(x, y, x2, y2, radius1, radius2), system.physics.colliderect(x, y, x2, y2, width, height, width2, height2) e system.physics.raycast(x, y, x2, y2, range)
Preuclides
« Consul »
1672838220000
    • Preuclides#3383
    • Profil
    • Derniers messages
    • Tribu
#14
  0
particula que vai na direção do mouse
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
local xcos = math.cos
local xsin = math.sin
local xparticle = tfm.exec.displayParticle

eventNewPlayer = function(j)
system.bindMouse(j, true)
end

for k in next, tfm.get.room.playerList do
eventNewPlayer(k)
end

eventMouse = function(j, x, y)
local ratoX = tfm.get.room.playerList[j].x
local ratoY = tfm.get.room.playerList[j].y
local direcaoX = -((ratoX-x)/29)
local direcaoY = -((ratoY-y)/29)
for i=1, 45 do
xparticle(9, ratoX+(xcos(i)), ratoY+(xsin(i)), direcaoX, direcaoY)
end
end


minimapa que mostra onde está cada jogador (só pra mapas 800x400, mas vc pode aprimorar)
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
24
25
26
27
28
local ximg = tfm.exec.addImage
local xrimg = tfm.exec.removeImage

local imagens = {
['j'] = '1856d77edec.png',
['m'] = '1718435fa5c.png' --300*2.666666666666, 100*4
}

tfm.exec.newGame('@0')

ximg(imagens['m'], '?1', 15, 35, nil, 2.666667/9, 4/9)

do local arquivo = {}
eventLoop = function()
for k in next, tfm.get.room.playerList do
xrimg(arquivo[k] or -1)
arquivo[k] = ximg(imagens['j'], '!2', 15+(tfm.get.room.playerList[k].x/10), 35+(tfm.get.room.playerList[k].y/10), nil, 6, 6)
end
end
end

eventNewGame = function()
ximg(imagens['m'], '?1', 15, 35, nil, 2.666667/9, 4/9)
end

eventNewPlayer = function(j)
ximg(imagens['m'], '?1', 15, 35, j, 2.666667/9, 4/9)
end


uma loadbar primitiva que faz algo quando clica espaço
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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local loadBarSize = 5 --the size of the bar (number)
local loadBarTime = 12 --the time to complete in 0.5 seconds, so 12 = 6 seconds (int)

local _loadBarPlayers = {}

eventNewPlayer = function(playerName)
system.bindKeyboard(playerName, 32, false, true)
if _loadBarPlayers[playerName] == nil then
_loadBarPlayers[playerName] = {seconds = loadBarTime, imageStorage = {}, canPressSpace = false, loadBarSpace = 0, secondsNoChange = loadBarTime} --each 10 seconds, put all players with loadBar
end
end

for k in next, tfm.get.room.playerList do
eventNewPlayer(k)
end

eventPlayerRespawn = function(playerName)
_loadBarPlayers[playerName] = {seconds = loadBarTime, imageStorage = {}, canPressSpace = false, loadBarSpace = 0, secondsNoChange = loadBarTime}
end

eventLoop = function()
for k, v in next, _loadBarPlayers do
if _loadBarPlayers[k].seconds > 0 then
_loadBarPlayers[k].imageStorage[(#_loadBarPlayers[k].imageStorage)+1] = tfm.exec.addImage('185269e5376.png', '$'..k, -((_loadBarPlayers[k].secondsNoChange*loadBarSize)/2)+_loadBarPlayers[k].loadBarSpace+(loadBarSize/2), -(32+(loadBarSize/2)), k, loadBarSize, loadBarSize, nil, nil, 0.5, 0.5)
_loadBarPlayers[k].loadBarSpace = (_loadBarPlayers[k].loadBarSpace)+loadBarSize
elseif _loadBarPlayers[k].canPressSpace == false then
_loadBarPlayers[k].canPressSpace = true
end
_loadBarPlayers[k].seconds = _loadBarPlayers[k].seconds-1
end
end

eventKeyboard = function(playerName, keyCode)
if _loadBarPlayers[playerName].canPressSpace and keyCode == 32 then
for i=1, #_loadBarPlayers[playerName].imageStorage do
tfm.exec.removeImage(_loadBarPlayers[playerName].imageStorage[i])
end
_loadBarPlayers[playerName] = {seconds = loadBarTime, imageStorage = {}, canPressSpace = false, loadBarSpace = 0, secondsNoChange = loadBarTime}

----------------
--DO SOMETHING--
----------------

end
end

Dernière modification le 1672850220000
Gamedroit
« Citoyen »
1677864900000
    • Gamedroit#3347
    • Profil
    • Derniers messages
    • Tribu
#15
  1

Conjunto de Utilitários para Tabelas


table.every( self, predicate )
 Esta função testa se todos os elementos da tabela passam pelo teste implementado pela função fornecida.
 Parâmetros:
  - self(table) : A tabela a ser testada
  - predicate(function(value, key)) : A função que testa cada elemento, recebe dois parametros:
    - value(?) : O elemento atual sendo processado na tabela
    - key(?) : A chave/índice do elemento atual sendo processado na tabela
 Retorna: (boolean) true se a função predicate retorna um valor verdadeiro para cada um dos elementos da tabela; caso contrário, false.
 
Code Lua

1
2
3
4
5
6
7
8
9
function table.every(self, predicate)
for key, value in next, self do
if not predicate(value, key) then
return false
end
end

return true
end

table.map( self, predicate, ordered )
 Esta função invoca a função predicate passada por argumento para cada elemento da tabela e devolve uma nova tabela como resultado.
 Parâmetros:
  - self(table) : A tabela a ser mapeada
  - predicate(function(value, key)) : A função cujo retorno produz o elemento da nova tabela. Recebe dois argumentos:
    - value(?) : O valor do elemento original da tabela de origem
    - key(?) : A chave/índice do elemento atual sendo processado na tabela
    - Retorna: (?) Um novo elemento a ser inserido na tabela resultante.
  - ordered(boolean) : Se true a tabela resultante será ordenada com índices númericos crescentes ignorando as chaves da tabela original
 Retorna: (table) Uma tabela contendo os novos elementos gerados pela função predicate.
 
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function table.map(self, predicate, ordered)
local t = {}

for k, v in next, self do
local value = predicate(v, k)

if not ordered then
t[k] = value
else
table.insert(t, value)
end
end

return t
end

table.filter( self, predicate, ordered )
 Esta função cria uma nova tabela com todos os elementos que passaram no teste implementado pela função fornecida.
 Parâmetros:
  - self(table) : A tabela a ser mapeada
  - predicate(function(value, key)) : A função para testar cada elemento da tabela. Retorna true para manter o elemento, false caso contrário, recebendo dois argumentos:
    - value(?) : O elemento que está sendo processado na tabela
    - key(?) : A chave/índice do elemento atual sendo processado na tabela
    - Retorna: (boolean) true para manter o elemento, false caso contrário
  - ordered(boolean) : Se true a tabela resultante será ordenada com índices númericos crescentes ignorando as chaves da tabela original
 Retorna: (table) Uma nova tabela com os elementos que passaram no teste.
 
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function table.filter(self, predicate, ordered)
local t = {}

for key, value in next, self do
if predicate(value, key) then
if not ordered then
t[key] = value
else
table.insert(t, value)
end
end
end

return t
end

table.extend( self, other, ordered )
 Esta função cria uma nova tabela com todos os elementos da tabela(self) e adiciona ao final da tabela resultante todos os elementos da tabela(other).
 Parâmetros:
  - self(table) : A tabela a ser extendida
  - other(table) : A tabela para concatenar (unir) a tabela retornada.
  - ordered(boolean) : Se true a tabela resultante será ordenada com índices númericos crescentes ignorando as chaves das tabelas originais
 Retorna: (table) Uma nova tabela com os elementos da tabela self e da tabela other.
 
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function table.extend(self, other, ordered)
if ordered then
return { table.unpack(self), table.unpack(other) }
else
local newT = {}

for k, v in next, self do
newT[k] = v
end

for k, v in next, other do
newT[k] = v
end

return newT
end
end

table.find( self, predicate )
 Esta função retorna o valor do primeiro elemento da tabela que satisfizer a função de teste provida. Caso contrario, nil é retornado.
 Parâmetros:
  - self(table) : A tabela contendo os elementos
  - predicate(function(value, key)) : A função executada a cada iteração da tabela, recebendo dois argumentos:
    - value(?) : O elemento que está sendo processado na tabela
    - key(?) : A chave/índice do elemento atual sendo processado na tabela
    - Retorna: (boolean) true para caso o elemento tenha sido encontrado, false caso contrário
 Retorna: (?) O valor do primeiro elemento da tabela que satisfaz a função de teste fornecida; caso contrário, nil.
 
Code Lua

1
2
3
4
5
6
7
8
9
function table.find(self, predicate)
for key, value in next, self do
if predicate(value, key) then
return value
end
end

return nil
end

table.contains( self, value )
 Esta função determina se uma tabela contém um determinado elemento, retornando true ou false apropriadamente.
 Parâmetros:
  - self(table) : A tabela contendo os elementos
  - value(?) : O elemento a buscar
 Retorna: (boolean) true se o elemento for encontrado; caso contrário, false.
 
Code Lua

1
2
3
4
5
6
7
8
9
function table.contains(self, value)
for _, v in next, self do
if v == value then
return true
end
end

return false
end

table.hasKey( self, key )
 Esta função retorna um booleano indicando se o elemento com a chave especificada existe ou não.
 Parâmetros:
  - self(table) : A tabela contendo os elementos
  - key(?) : A chave/índice do elemento que será testado na tabela
 Retorna: (boolean) true se o elemento com a chave ou índice especificado existe na tabela, de outra forma será retornado false.
 
Code Lua

1
2
3
4
5
6
7
8
9
function table.hasKey(self, key)
for k in next, self do
if k == key then
return true
end
end

return false
end

table.length( self )
 Esta função obtém o tamanho de uma tabela, caso esteja usando o metamétodo __len ele será invocado e seu valor de retorno utilizado.
 Parâmetros:
  - self(table) : A tabela da qual será extraída o tamanho
 Retorna: (number) o tamanho da tabela passada como parâmetro.
 
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
function table.length(self)
local mt = getmetatable(self)

if mt ~= nil and mt.__len ~= nil then
return mt:__len()
end

local count = 0
for _, _ in next, self do
count = count + 1
end
return count
end

table.freeze( self )
 Está função congela uma tabela: isto é, impede que novas propriedades sejam adicionadas a ela; impede que as propriedades existentes sejam removidas; e impede que propriedades existentes sejam alteradas. Em essência a tabela é efetivamente imutável. A função retorna uma metatabela imutável com acesso a tabela original.
 Parâmetros:
  - self(table) : A tabela a qual será congelada
 Retorna: (table) Uma metatabela imutável com acesso aos elementos da tabela de origem.
 Esta função pode ser usada em conjunto com a função table.length
 
Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function table.freeze(self)
return setmetatable({}, {
__index = function(_, key)
return self[key]
end,

__newindex = function(_, key, value)
error(("Cannot set property '%s' to '%s', table is frozen"):format(key, tostring(value)))
end,

__len = function()
return table.length(self)
end
})
end

Todo o código pode ser encontrado aqui: table-utils.lua
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Tutorial] Lua Snippets
© Atelier801 2018

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

Version 1.27