×

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
  • /
  • [Script] Joint Translator
[Script] Joint Translator
Bolodefchoco
« Sénateur »
1514848440000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#1
  5

JOINT TRANSLATOR
Source here


This script allows translations from XML code to joints inserted with Lua, giving the possibility of setting both the drawing's position and the drawing's depth (background or foreground). It can also contain functions that are triggered when a player touches the lines.

The script requires 4 basic functions that must not be replaced:


  • string.split -> Fragments a string in a table (regex)
  • math.intersects -> Verifies if a point (x, y) is located between two points (x1, y1) and (x2, y2)
  • math.minmax -> Returns the given parameters sorted decrescently
  • table.copy -> Copies a table and returns its copy


There are 4 functions in the script:

• translateJoint(id, xml, x, y, foreground, f)
Draws the joints
* id (int) -> Drawing's ID. This value may not be given when this function is called, the ID value will be the last given ID + 1, [0 > 1, 1 > 2, 2 > 3, ...]
* xml (string) -> The drawing's ID or XML . There are drawing samples in the script that works like IDs, they are: "bomb", "cannon", "cheese", "chicken", "ghost", "hole", "mouse", "portal_blue", "portal_orange", "troll"
* x (int) -> Horizontal drawing's position
* y (int) -> Vertical drawing's position
* foreground (boolean) -> Boolean to decides the depth. True for Foreground, False for Background, Nil for Automatic. This parameter can be a function and will work like the parameter listed below.
* f (function) -> A function(playerName, playerData) that is triggered when a player touches the drawing

Returns:
#1 (Int) ID
#2 (Int) Number of drawing lines

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
eventNewGame = function()
-- Obligatory
tfm.exec.addPhysicObject(0, 0, 0, { type = 14, miceCollision = false, groundCollision = false })

-- Draws a cheese that gives cheese to anyone who touches it.
translateJoint(0, "cheese", 300, 330, function(playerName)
tfm.exec.giveCheese(playerName)
end)

-- Draws a hole that gives victory to anyone who touches it.
translateJoint("hole", 210, 320, true, function(player)
tfm.exec.playerVictory(player)
end)

-- Draws a no-function cannon.
-- It erases the last drawing, "hole", because "hole" has ID = 1 too.
-- (even if it was not set in the function call).
translateJoint(1, "cannon", 400, 200)

-- Draws a "Hi"
local xml = '<C><P/><Z><S /><D /><O /><L><JD P1="235,198"P2="215,67"c="78e67c,2"/><JD P1="227,136"P2="296,126"c="78e67c,2"/><JD P1="309,187"P2="281,43"c="78e67c,2"/><JD P1="381,205"P2="353,123"c="78e67c,2"/><JD P1="353,113"P2="357,92"c="78e67c,2"/><JD P1="357,92"P2="341,70"c="78e67c,2"/><JD P1="341,70"P2="336,97"c="78e67c,2"/><JD P1="336,97"P2="352,113"c="78e67c,2"/><JD P1="340,93"P2="342,80"c="78e67c,2"/><JD P1="342,80"P2="345,99"c="78e67c,2"/><JD P1="345,99"P2="349,83"c="78e67c,2"/><JD P1="349,83"P2="352,108"c="78e67c,2"/><JD P1="214,65"P2="227,66"c="78e67c,2"/><JD P1="227,66"P2="237,128"c="78e67c,2"/><JD P1="237,128"P2="294,119"c="78e67c,2"/><JD P1="281,45"P2="265,50"c="78e67c,2"/><JD P1="265,50"P2="281,119"c="78e67c,2"/><JD P1="281,128"P2="293,189"c="78e67c,2"/><JD P1="293,189"P2="308,187"c="78e67c,2"/><JD P1="237,195"P2="251,193"c="78e67c,2"/><JD P1="251,192"P2="241,132"c="78e67c,2"/><L /></L></Z></C>'
translateJoint(10, xml, 100, 200, true)
end

• removeJoint(id)
Erases a drawing
* id (int) -> ID of the drawing that must be removed

Returns:
#1 (Boolean) If it was removed or not

Code Lua

1
2
3
4
5
6
7
8
9
eventNewGame = function()
-- Obligatory
tfm.exec.addPhysicObject(0, 0, 0, { type = 14, miceCollision = false, groundCollision = false })

-- Draws a cheese that disappears when someone touches it.
translateJoint(0, "cheese", 200, 330, function()
removeJoint(0)
end)
end

• executeJoint
Executes once all the drawing functions (only the verifications)
Code Lua

1
2
3
eventLoop = function()
executeJoint()
end

• setFunction(id, f)
Set or remove a drawing's function
* id (int) -> Drawing's ID
* f (function) -> New function. If nil, the drawing's function will be removed

Returns:
#1 (Boolean) If it was set or not

Code Lua

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
eventNewGame = function()
-- Obligatory
tfm.exec.addPhysicObject(0, 0, 0, { type = 14, miceCollision = false, groundCollision = false })

-- Draws a cheese that gives cheese once and then will act like a hole
translateJoint(0, "cheese", 300, 330, function(playerName)
tfm.exec.giveCheese(playerName)
setFunction(0, function(playerName)
tfm.exec.playerVictory(playerName)
end)
end)

-- Draws a hole that gives victory once and then will act like a cheese
translateJoint(1, "hole", 200, 330, function(playerName)
tfm.exec.playerVictory(playerName)
setFunction(1, function(playerName)
tfm.exec.giveCheese(playerName)
end)
end)
end

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
-- Sample code
eventNewGame = function()
-- Obligatory
tfm.exec.addPhysicObject(0, 0, 0, { type = 14, miceCollision = false, groundCollision = false })

translateJoint(0, 'cheese', 500, 310, function(n)
tfm.exec.giveCheese(n)
end)

translateJoint(1, 'hole', 650, 310, true, function(n)
tfm.exec.playerVictory(n)
end)

local sha_id
sha_id = translateJoint('cannon', 200, 340, function(n)
tfm.exec.setShaman(n)
setFunction(sha_id)
end)

translateJoint('<C><P/><Z><S /><D /><O /><L><JPL P1="133,138"P3="134,138"P4="135,139"P2="138,140"c="6570e6,5"/><JPL P1="138,140"P3="142,142"P4="146,144"P2="151,145"c="6570e6,5"/><JPL P1="151,145"P3="157,147"P4="163,148"P2="170,149"c="6570e6,5"/><JPL P1="170,149"P3="177,150"P4="184,150"P2="191,149"c="6570e6,5"/><JPL P1="191,149"P3="198,147"P4="205,145"P2="212,141"c="6570e6,5"/><JPL P1="212,141"P3="218,136"P4="224,130"P2="230,122"c="6570e6,5"/><JPL P1="230,122"P3="235,112"P4="239,101"P2="235,112"c="6570e6,5"/><JPL P1="238,100"P3="223,91"P4="211,85"P2="200,84"c="6570e6,5"/><JPL P1="200,84"P3="192,86"P4="186,91"P2="182,98"c="6570e6,5"/><JPL P1="182,98"P3="179,108"P4="177,119"P2="176,132"c="6570e6,5"/><JPL P1="176,132"P3="177,146"P4="178,161"P2="180,175"c="6570e6,5"/><JPL P1="180,175"P3="183,190"P4="185,204"P2="188,216"c="6570e6,5"/><JPL P1="188,216"P3="191,228"P4="193,237"P2="195,245"c="6570e6,5"/><JPL P1="195,245"P3="197,249"P4="197,251"P2="197,249"c="6570e6,5"/><JD P1="248,235"P2="268,96"c="6570e6,5"/><JPL P1="198,252"P3="197,251"P4="194,249"P2="189,246"c="6570e6,5"/><JPL P1="189,246"P3="183,243"P4="176,238"P2="169,233"c="6570e6,5"/><JPL P1="169,233"P3="163,227"P4="156,221"P2="151,216"c="6570e6,5"/><JPL P1="151,216"P3="147,210"P4="145,204"P2="146,200"c="6570e6,5"/><JPL P1="146,200"P3="149,195"P4="155,192"P2="165,189"c="6570e6,5"/><JPL P1="165,189"P3="179,188"P4="197,188"P2="221,189"c="6570e6,5"/><JPL P1="221,189"P3="250,192"P4="284,197"P2="250,192"c="6570e6,5"/><JD P1="335,131"P2="366,106"c="6570e6,5"/><JD P1="336,133"P2="338,220"c="6570e6,5"/><JD P1="337,219"P2="381,209"c="6570e6,5"/><JD P1="337,169"P2="360,158"c="6570e6,5"/><JD P1="406,100"P2="448,157"c="6570e6,5"/><JD P1="427,216"P2="481,62"c="6570e6,5"/><JD P1="523,50"P2="532,184"c="e665ae,5"/><JD P1="532,211"P2="532,212"c="e665ae,15"/><JD P1="536,210"P2="536,211"c="e665ae,15"/><JD P1="539,219"P2="539,220"c="e665ae,15"/><JD P1="530,220"P2="530,221"c="e665ae,15"/><L /></L></Z></C>', 200, 200, true)

local id, joints
id, joints = translateJoint('ghost', 50, 320, function()
ui.setMapName("A ghost with " .. joints .. " lines just disappeared...")
removeJoint(id)
end)
end

eventLoop = function()
executeJoint()
end

tfm.exec.disableAutoNewGame()
tfm.exec.disableAutoShaman()
tfm.exec.newGame(0)


https://image.prntscr.com/image/UpAxxg8bQ2S6UAzTH1c8FA.png
Thanks to Mescouleur, he partially gave me this idea to improve his ground editor in lua


Dernière modification le 1514922300000
Kimsterjay
« Consul »
1514879700000
    • Kimsterjay#0000
    • Profil
    • Derniers messages
    • Tribu
#2
  2
Fantastic!
Bolodefchoco
« Sénateur »
1514907000000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#3
  1
Kimsterjay a dit :
Fantastic!

Thank you!
Sebafrancuz
« Consul »
1514909340000
    • Sebafrancuz#0000
    • Profil
    • Derniers messages
    • Tribu
#4
  2
Good job ;)
Bolodefchoco
« Sénateur »
1514910060000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#5
  1
Sebafrancuz a dit :
Good job ;)

Thanks!
Glozell
« Censeur »
1514913840000
    • Glozell#3017
    • Profil
    • Derniers messages
#6
  2
Good job bolo
"And thanks my best friend "mecouleur
3>>
Bolodefchoco
« Sénateur »
1514914200000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#7
  2
Jkhggjkgjgfy a dit :
Good job bolo
"And thanks my best friend "mecouleur
3>>

hahaha
Thanks ^^'
Boucharma
« Censeur »
1514922000000
    • Boucharma#0000
    • Profil
    • Derniers messages
#8
  2
Wow amazing script!
Bolodefchoco
« Sénateur »
1514922240000
    • Bolodefchoco#0095
    • Profil
    • Derniers messages
    • Tribu
#9
  1
Boucharma a dit :
Wow amazing script!

Thanks :)
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Script] Joint Translator
© Atelier801 2018

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

Version 1.27