SHARE
TWEET

Untitled

Wav May 25th, 2020 921 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. system.disableChatCommandDisplay("help",true)
  2. tfm.exec.disableAutoShaman(true)
  3. tfm.exec.disableAutoNewGame(true)
  4. tfm.exec.disableAutoTimeLeft(true)
  5.  
  6. sin=math.sin
  7. cos=math.cos
  8. exp=math.exp
  9. pow=math.pow
  10. random=math.random
  11. sqrt=math.sqrt
  12. atan2=math.atan2
  13.  
  14. images={bell={img="RYDr1bs.png",x=-63,y=-85},heart={img="xkXRpBD.png",x=10,y=30},full={img="SngMG3F.png",x=7,y=55},toys={img={"RGFcIjz.png","7qwZeWD.png","5oDZUVp.png","wUjtCfa.png","ZjAWge2.png"},x={-10,-13,-5,-10,-10},y={-3,-20,-22,-5,-10}},jingle={img={"Irj5Jr7.png","0qnwm23.png","NlBfXFc.png","xoDTQqV.png"},x={-30,-20,-26,-20},y={-35,-34,-34,-35}},barrelBig={img={"f1VWEbt.png","jeLpl8e.png"},imgFlash={"0pNTLJK.png","L92T4yP.png"},x={-29,-29},y={-28,-28}},barrelLittle={img={"jFavdFn.jpg","UzCNqBy.jpg"},imgFlash={"7XPuAGy.jpg","znT4QCH.jpg"},x={-15,-15},y={-15,-15}},fireworks={img={"sHQtkLP.png","SGNDjGy.png"},imgFlash={"28Y3L3w.png","28Y3L3w.png"},x={-27,-27},y={-6,-6}},numbers={"7OTfA2O.png","aIap6r2.png","1mVCFSC.png","TipiF3Y.png","O7T8836.png","ym778Bo.png","Q7fnIlX.png","6Y7Bjsk.png","asWg9Tz.png","BpNdwFQ.png","oWtyTh5.png"},help={{img="DgigJ4B.png",x=112,y=33},{img="WgQuEc0.png",x=614,y=34},{img="NeoqaqN.png",x=596,y=40},{img="nS1NIp6.png",x=596,y=65}},elves={x=-32,y=-60},boxletter={img="Eus9r3H.png",x=0,y=0},letter={img="44O0SPP.png",x=150,y=25},gift={img="3v4KgmE.png",x=-5,y=-15},rocket={{img="GpOKrbg.png",x=151,y=30},{img="xLgyAVh.png",x=609,y=74},{img="Ng5pX6d.png",x=609,y=30},{img="EaCRTo8.png",x=639,y=43}}}
  15.  
  16. boxPattern={{{id=2,x=0,y=0,angle=0,time=0}},{{id=60,x=-30,y=10,angle=-60,time=0},{id=60,x=-20,y=10,angle=-90,time=0},{id=2,x=0,y=0,angle=0,time=0}},{{id=60,x=30,y=10,angle=-120,time=0},{id=60,x=20,y=10,angle=-90,time=0},{id=2,x=0,y=0,angle=0,time=0}},{{id=60,x=-20,y=10,angle=-90,time=0},{id=2,x=0,y=0,angle=0,time=0}},{{id=60,x=-55,y=10,angle=0,time=0},{id=60,x=-55,y=5,angle=0,time=0},{id=60,x=-55,y=0,angle=0,time=0},{id=2,x=0,y=0,angle=0,time=0}}, {{id=60,x=-20,y=0,angle=-60,time=0},{id=60,x=0,y=0,angle=-90,time=0},{id=60,x=20,y=0,angle=-120,time=0}},{{id=60,x=0,y=10,angle=0,time=0},{id=60,x=0,y=5,angle=0,time=0},{id=60,x=-30,y=0,angle=-60,time=0}},{{id=1,x=0,y=0,angle=0,time=0},{id=1,x=30,y=0,angle=0,time=0},{id=1,x=0,y=-20,angle=0,time=0}},{{id=60,x=-20,y=0,angle=-60,time=0},{id=60,x=0,y=0,angle=-90,time=0},{id=60,x=20,y=0,angle=-120,time=0}},{{id=60,x=0,y=10,angle=0,time=0},{id=60,x=0,y=5,angle=0,time=0},{id=60,x=-30,y=0,angle=-60,time=0}},{{id=1,x=0,y=0,angle=0,time=0},{id=1,x=30,y=0,angle=0,time=0},{id=1,x=20,y=-20,angle=0,time=0}},{{id=1,x=0,y=0,angle=0,time=0}},{{id=60,x=0,y=0,angle=0,time=0}},{{id=60,x=0,y=0,angle=0,time=0},{id=60,x=0,y=-10,angle=0,time=0}},{{id=60,x=-30,y=0,angle=-60,time=0},{id=1,x=0,y=0,angle=0,time=0}},}
  17.  
  18. map={
  19.     code='<C><P L="1600" Ca="" H="800" /><Z><S><S P="0,0,0.3,0.2,0,0,0,0" L="1500" o="ffffffffffff" X="850" Y="788" T="12" H="25" /><S L="104" X="52" H="416" Y="593" T="11" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="120" o="ffffffffffff" H="32" c="3" Y="699" T="12" X="291" /><S P="0,0,0.3,0.2,0,0,0,0" L="524" o="ffffffffffff" X="365" Y="371" T="12" H="27" /><S P="0,0,0.3,0.2,0,0,0,0" L="74" o="ffffffffffff" X="139" Y="765" T="12" H="25" /><S L="728" X="1236" H="24" Y="374" T="11" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.8,0.2,0,0,0,0" L="31" o="ffffffffffff" X="181" Y="152" T="12" H="304" /><S P="0,0,0.3,0.2,0,0,0,0" L="632" o="ffffffffffff" X="512" Y="13" T="12" H="26" /><S P="0,0,0.3,0.2,0,0,0,0" L="146" o="ffffffffffff" X="799" Y="371" T="12" H="27" /><S P="0,0,0.3,0.2,-37,0,0,0" L="500" o="ffffffffffff" X="539" Y="550" T="12" H="37" /><S P="0,0,0.8,0.2,0,0,0,0" L="30" o="ffffffffffff" X="815" Y="213" T="12" H="206" /><S P="0,0,0.3,0.2,0,0,0,0" L="154" o="ffffffffffff" H="36" Y="130" T="12" X="906" /><S P="0,0,0.3,0.2,0,0,0,0" L="34" o="ffffffffffff" H="53" Y="27" T="12" X="813" /><S P="0,0,0.3,0.8,0,0,0,0" L="35" o="ffffffffffff" H="10" Y="174" T="13" X="1165" /><S P="0,0,0.3,0.8,0,0,0,0" L="25" o="ffffffffffff" H="10" Y="216" T="13" X="1107" /><S L="25" o="ffffffffffff" H="10" X="1218" Y="233" T="13" P="0,0,0.3,0.8,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="216" o="ffffffffffff" H="18" Y="153" T="12" X="352" /><S P="0,0,0.3,0.2,0,0,0,0" L="170" o="ffffffffffff" H="11" Y="332" T="12" X="407" /><S P="0,0,0.3,0.2,0,0,0,0" L="77" o="ffffffffffff" H="13" Y="196" T="12" X="546" /><S P="0,0,0.3,0.2,0,0,0,0" L="103" o="ffffffffffff" H="14" Y="158" T="12" X="646" /><S P="0,0,0.3,0.2,0,0,0,0" L="132" o="ffffffffffff" H="10" Y="562" T="12" X="290" /><S L="132" o="ffffffffffff" H="10" X="290" Y="509" T="12" P="0,0,0.3,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="132" o="ffffffffffff" X="290" Y="450" T="12" H="10" /><S P="0,0,0.3,0.2,0,0,0,0" L="15" o="ffffffffffff" H="10" Y="479" T="13" X="742" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="ffffffffffff" H="10" Y="499" T="13" X="777" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="ffffffffffff" H="10" Y="485" T="13" X="814" /><S P="0,0,0.3,0.2,0,0,0,0" L="262" o="ffffffffffff" H="10" Y="732" T="12" X="741" /><S P="0,0,0.3,0.2,0,0,0,0" L="221" o="ffffffffffff" H="11" Y="687" T="12" X="769" /><S P="0,0,0.3,0.2,0,0,0,0" L="132" o="ffffffffffff" H="10" Y="457" T="12" X="914" /><S P="0,0,0.3,0.2,0,0,0,0" L="105" o="ffffffffffff" H="16" Y="659" T="12" X="936" /><S P="0,0,0.3,0.2,0,0,0,0" L="93" o="ffffffffffff" H="17" Y="607" T="12" X="1027" /><S P="0,0,0.8,0.2,0,0,0,0" L="43" o="ffffffffffff" H="318" Y="544" T="12" X="1094" /><S P="0,0,0.3,0.2,0,0,0,0" L="107" o="ffffffffffff" H="16" Y="469" T="12" X="1169" /><S P="0,0,0.3,0.2,0,0,0,0" L="169" o="ffffffffffff" H="15" Y="477" T="12" X="1410" /><S P="0,0,0.3,0.2,0,0,0,0" L="147" o="ffffffffffff" H="15" Y="542" T="12" X="1496" /><S P="0,0,0.3,0.2,0,0,0,0" L="151" o="ffffffffffff" H="16" Y="580" T="12" X="1292" /><S P="0,0,0.3,0.2,0,0,0,0" L="196" o="ffffffffffff" H="16" Y="664" T="12" X="1211" /><S P="0,0,0.8,0.2,0,0,0,0" L="31" o="ffffffffffff" H="392" Y="581" T="12" X="1585" /><S P="0,0,0.3,0.2,0,0,0,0" L="127" o="ffffffffffff" H="15" Y="680" T="12" X="1507" /><S P="0,0,0.3,0.2,-40,0,0,0" L="90" o="ffffffffffff" H="15" Y="707" T="12" X="1415" /><S L="51" o="ffffffffffffff" H="816" X="-26" Y="395" T="12" P="0,0,0,0.2,0,0,0,0" /><S P="0,0,0,0.2,0,0,0,0" L="51" o="ffffffffffffff" X="1626" Y="380" T="12" H="816" /><S L="1600" o="ffffffffffffff" H="50" X="800" Y="-25" T="12" P="0,0,0,0.2,0,0,0,0" /><S P="0,0,0.3,0.2,0,0,0,0" L="10" o="ffffffffffff" X="434" c="2" Y="689" T="12" H="90" /><S P="0,0,0.3,0.2,45,0,0,0" L="90" o="ffffffffffff" X="1395" c="2" Y="766" T="12" H="90" /><S P="0,0,0.3,0.2,0,0,0,0" L="90" o="ffffffffffff" X="845" c="2" Y="316" T="12" H="90" /><S H="150" L="10" o="ffffffffffff" X="766" c="2" Y="296" T="12" P="0,0,0.3,0.2,30,0,0,0" /></S><D><DS Y="369" X="28" /></D><O /></Z></C>',
  20.     background={img="mRKhmjS.png",x=0,y=0},
  21.     posJingle={x={1424,178,256,964},y={348,343,668,761},img={4,2,3,1}},
  22.     mistletoe={x={840,320},y={97,668},r={50,50},kiss={{},{}}},
  23.     toysPos={
  24.         x={330,510,256,520,1493,609,842,883,1163,1220,1105,736,240,240,240,300,1041,630,673,902,995,866,745,1458,1130,1235,1437,1346,1130},
  25.         y={311,342,129,174,346,136,97,346,124,193,176,342,542,489,430,761,761,712,666,636,583,437,449,657,641,557,519,454,446},
  26.         l={145,100,185,60,90,75,128,460,2,2,2,123,99,99,99,541,510,230,191,77,62,100,2,94,160,116,113,132,76}
  27.     },
  28.     barrels={
  29.         x={284,549,633,878,900,240,240,240,118,400,626,630,681,989,856,749,1190,1130,1235,1522,1346,1130,340,507},
  30.         y={129,174,136,97,348,542,489,430,737,761,737,712,666,583,437,450,761,641,557,519,454,446,311,342},
  31.         l={134,5,10,60,405,99,99,99,30,152,264,218,175,68,110,60,369,160,116,30,132,76,130,105},
  32.         w={1,6,6,1,1,12,12,12,12,6,12,12,1,6,12,12,12,12,1,6,1,1,6,6}}
  33. }
  34.  
  35. settings={life=3,bagMax=3,toysNum=30,timestamp=8000,radius=75,barrels=36,explosionPower=42}
  36. players={}
  37. toys={}
  38. barrels={}
  39. boxTimers={}
  40. globalTime=0
  41.  
  42. text={
  43. name="<J>The Toy Factory",give="<J>Oh! %s more toy(s)! Thank you!",empty="<J>Your bag is empty :(",full="<J>Your bag is full ^_^",elf="UDYkbja.png",
  44. RU={name="<J> Игрушечная фабрика",give="<J>Ох! %s большие игрушки! Спасибо!",empty="<J>Ваша сумка пуста :(",full="<J> Ваша сумка полная ^_^",elf="KVxylyj.png"},
  45. HU={name="<J>A Játékgyár",give="<J>Ó! Még %s játék! Köszönjük!",empty="<J>A táskád üres :(",full="<J>Tele a táskád ^_^",elf="UDYkbja.png"},
  46. FR={name="<J>La Fabrique de Jouets",give="<J>Oh ! %s jouet(s) en plus ! Merci !",empty="<J>Ton sac est vide :(",full="<J>Ton sac est plein ^_^",elf="UAqX7CF.png"},
  47. ES={name="<J>La Fábrica de Juguetes",give="<J>¡Oh! %s ¡más juguetes! ¡Gracias!",empty="<J>Tu bolsa está vacia :(",full="<J>Tu bolsa está llena ^_^",elf="Ta5bjeI.png"},
  48. BR={name="<J>A Fabrica de Brinquedos",give="<J>Oh! Mais %s brinquedos! Obrigado!!",empty="<J>Sua bolsa é vazia :(",full="<J>Sua bolsa é cheia ^_^",elf="emrREal.png"},
  49. RO={name="Fabrica de Jucării",give="<J> Vai! Încă %s jucării! Mulțumesc!",empty="<J>Sacul tău e gol :(",full="<J> Sacul tău e plin ^_^",elf="UDYkbja.png"},
  50. VK={name="Leketøy fabrikken",give="<J>Du ga meg %s flere leker. Tusen takk.",empty="<J>Sekken din er tom :(",full="<J>Sekken din er full ^_^",elf="Nl9PMWh.png"},
  51. DE={name="Die Spielzeugfabrik",give="<J>Ach! %s mehr Spielzeuge!Danke dir!",empty="<J>Deine Tüte ist leer :(",full="<J>Deine Tüte ist voll! ^_^",elf="UDYkbja.png"},
  52. NL={name="<J>Het Speelgoedfabriek",give="<J>Ooh! %s meer speelgoed! Dankje wel!",empty="<J>Je tas is leeg :(",full="<J>Je tas is vol ^_^",elf="ir5mPsN.png"},
  53. NL={name="<J>Het Speelgoedfabriek",give="<J>Ooh! %s meer speelgoed! Dankje wel!",empty="<J>Je tas is leeg :(",full="<J>Je tas is vol ^_^",elf="ir5mPsN.png"},
  54. ID={name="<J>Pabrik Mainan",give="<J>Oh! %s tambahan mainan! Terima kasih!",empty="<J>Tas kamu kosong :(",full="<J>Tas kamu penuh ^_^",elf="kM9rblM.png"},
  55. PL={name="<J>Fabryka Zabawek",give="<J>Oh! %s więcej zabawek! Dzięki!",empty="<J>Twoja torba jest pusta :(",full="<J>Twoja torba jest pełna ^_^",elf="wRajSrK.png"},
  56. CN={name="<J>&#29609;&#20855;&#24037;&#21378;",give="<J>&#21734;&#65281;&#20320;&#24102;&#26469;&#20102; %s &#20010;&#29609;&#20855;&#65281;&#35874;&#35874;&#65281;",empty="<J>&#20320;&#30340;&#21253;&#27809;&#26377;&#29609;&#20855; :(",full="<J>&#20320;&#30340;&#21253;&#24050;&#32463;&#28385;&#20102; ^_^",elf="jZaeS2r.png"},
  57. TR={name="<J>Oyuncak Atölyesi",give="<J>Oh! %s tane daha oyuncak! Teşekkürler!",empty="<J>Çantan boş :(",full="<J>Çantan dolu ^_^",elf="UDYkbja.png"}}
  58.  
  59. lang=tfm.get.room.community
  60. if text[lang] then
  61.     for id,message in pairs(text[lang]) do
  62.         text[id]=message
  63.     end
  64. end
  65.  
  66. --Utils
  67.  
  68. function table.contains(t,element)
  69.     for key,value in ipairs(t) do
  70.         if value==element then
  71.             return true
  72.         end
  73.     end
  74.     return false
  75. end
  76.  
  77. function string.split(str,s)
  78.     local res = {}
  79.     for part in string.gmatch(str, "[^" .. s .. "]+") do
  80.         table.insert(res, part)
  81.     end
  82.     return res
  83. end
  84.  
  85. function table.random(t)
  86.     return t[random(1,#t)]
  87. end
  88.  
  89. function tfm.get.room.isAlive()
  90.     for name,player in pairs(tfm.get.room.playerList) do
  91.         if not player.isDead then return true end
  92.     end
  93.     return false
  94. end
  95.  
  96. -- Collision
  97.  
  98. function pythag(x1,y1,x2,y2,r)
  99.     local x=x2-x1
  100.     local y=y2-y1
  101.     local r=r+r
  102.     return x*x+y*y<r*r
  103. end
  104.  
  105. function nearObject(x1,y1,nearPixel,table)
  106.     for id,pos in ipairs(table) do 
  107.         if pythag(x1,y1,pos.x,pos.y,nearPixel) then return id end
  108.     end
  109.     return nil
  110. end
  111.  
  112. -- Ui
  113.  
  114. function ui.updateScores(name)
  115.     local str=players[name].bag.."/"..settings.bagMax
  116.     local x,y,num=0,0,0
  117.     for i,k in pairs(players[name].scoreImg) do
  118.         tfm.exec.removeImage(k)
  119.     end
  120.     players[name].scoreImg={}
  121.     for i=1,#str do
  122.         num=((tonumber(str:sub(i,i)))or 10)+1
  123.         if num==11 then x,y=1,-1 else x,y=0,0 end
  124.         table.insert(players[name].scoreImg,tfm.exec.addImage(images.numbers[num],"&3",40+(i-1)*14+x,60+y,name,true))
  125.     end
  126.     tfm.exec.addImage(images.full.img,"&3",images.full.x,images.full.y,name,true)
  127.     ui.addTextArea(-2, "<J><b><font size='12'>      "..players[name].toys.."</font></b>", name, 735, 350, 100, 20,nil,nil, 0.6,true)
  128.     tfm.exec.addImage(images.toys.img[1],"&3",745+images.toys.x[1],353+images.toys.y[1],name,true) 
  129. end
  130.  
  131. function ui.updateHeart(name)
  132.     tfm.exec.removeImage(players[name].life[#players[name].life] or -500)
  133.     table.remove(players[name].life,#players[name].life)
  134. end
  135.  
  136. function ui.help(name)
  137.     if not players[name].help[1] then
  138.         for i=1,#images.help do
  139.             table.insert(players[name].help,tfm.exec.addImage(images.help[i].img,"&5",images.help[i].x,images.help[i].y,name))
  140.         end
  141.         ui.addTextArea(50,"<a href='event:help'><b><font size='2'> </font><font color='#040404'>X</font></b></a>", name, 598,49,15,15,0x7E8182,0x7E8182,1,true)
  142.     end
  143. end
  144.  
  145. -- Explosions
  146.  
  147. function spawnBoxes(boxTable,x,y)
  148.     local boxId,imgTale,imgId= 0,0,0
  149.     for id,box in ipairs(boxTable) do
  150.         boxId=tfm.exec.addShamanObject(box.id, x+box.x, y+box.y, box.angle, 0, 0,false)
  151.         if box.id==2 then imgTable=images.barrelBig
  152.         elseif box.id==1 then imgTable=images.barrelLittle
  153.         elseif box.id==60 then imgTable=images.fireworks end
  154.         imgId=random(1,#imgTable.img)
  155.         tfm.exec.addImage(imgTable.img[imgId],"#"..boxId,imgTable.x[imgId],imgTable.y[imgId])
  156.         table.insert(boxTimers,{boxId,os.time(),random(6,90)*1000,0,box.id,imgId,false,false})
  157.     end
  158. end
  159.  
  160. function explosionFlash(id,box,remove)
  161.     local imgTable=nil
  162.     if box[5]==2 then imgTable=images.barrelBig
  163.     elseif box[5]==1 then imgTable=images.barrelLittle
  164.     elseif box[5]==60 then imgTable=images.fireworks end
  165.     if imgTable then
  166.         if remove then tfm.exec.addImage(imgTable.img[box[6]],"#"..box[1],imgTable.x[box[6]],imgTable.y[box[6]])
  167.         else tfm.exec.addImage(imgTable.imgFlash[box[6]],"#"..box[1],imgTable.x[box[6]],imgTable.y[box[6]])  end
  168.     end
  169. end
  170.  
  171. -- Events
  172.  
  173. function eventChatCommand(name,msg)
  174.     if msg=="help" then ui.help(name) end
  175. end
  176.  
  177. function eventNewPlayer(name)
  178.     tfm.exec.addImage(map.background.img,"?1",map.background.x,map.background.y,name)
  179.     tfm.exec.setUIMapName(text.name)   
  180. end
  181.  
  182. function eventMouse(name,x,y)  
  183.     if players[name].letter[1] then
  184.         tfm.exec.removeImage(players[name].letter[1])
  185.         players[name].letter[1]=nil
  186.     end
  187.     if players[name].power[1] then 
  188.         if os.difftime(os.time(),players[name].power[1])>=15000 and os.difftime(os.time(),globalTime)>=2000 then
  189.             tfm.exec.removeImage(players[name].power[2])
  190.             local choice=random(1,3)   
  191.             local glitter={13,11,9,2,21,23,24}
  192.             drawParam2(0,{x,y,-10,9.8955,7,{13,11,9,2,1}})
  193.             drawCircle(0,{{x=x,y=y},{x=x,y=y+40},{13,11,9,2,1}})
  194.             if choice==1 then
  195.                 drawButterfly(0,{x,y,{table.random(glitter)}})
  196.             elseif choice==2 then
  197.                 drawParam2(0,{x,y,5,0.5,60,{table.random(glitter)}})
  198.                 drawParam2(0,{x,y,1.6,0.5,25,{table.random(glitter)}})
  199.             elseif choice==3 then
  200.                 drawParam1(0,{x,y,5,1,5,1,{table.random(glitter)}})
  201.             end
  202.             players[name].power[1]=os.time()
  203.             globalTime=os.time()
  204.         end
  205.     end
  206. end
  207.  
  208. function eventKeyboard(name,key,down,x,y)
  209.     if key==32 or key==83 or key==40 then
  210.         local near=nearObject(x,y,20,toys)
  211.         for id=1,#map.posJingle.x do
  212.             if pythag(x,y,map.posJingle.x[id],map.posJingle.y[id],20) then
  213.                 if players[name].bag>0 then
  214.                     tfm.exec.chatMessage(string.format(text.give,players[name].bag),name)
  215.                     players[name].spam=os.time()
  216.                     local particleHearts={{x=0,y=-0.5},{x=0.5,y=-0.5},{x=-0.5,y=-0.5}}
  217.                     for i=1,players[name].bag do
  218.                         tfm.exec.displayParticle(5, map.posJingle.x[id], map.posJingle.y[id]-20, particleHearts[i].x, particleHearts[i].y, 0, 0,name)
  219.                     end
  220.                     eventTextAreaCallback(0,name,"jingle") 
  221.                     near=nil
  222.                 else
  223.                     if os.difftime(os.time(),players[name].spam)>1000 then  
  224.                         tfm.exec.chatMessage(text.empty,name)  
  225.                         players[name].spam=os.time()
  226.                     end                
  227.                 end
  228.             end
  229.         end    
  230.         if near and not table.contains(players[name].toysTaken,near)then
  231.             if not (players[name].bag>=settings.bagMax) then
  232.                 table.insert(players[name].toysTaken,near)
  233.                 tfm.exec.removeImage(players[name].toysList[near])         
  234.                 players[name].bag=players[name].bag+1
  235.                 tfm.exec.displayParticle(15,x+15,y-15,0,-1,0,0,name)
  236.                 ui.updateScores(name)
  237.             end
  238.             if players[name].bag>=settings.bagMax then
  239.                 if os.difftime(os.time(),players[name].spam)>1000 then  
  240.                     tfm.exec.chatMessage(text.full,name)
  241.                     players[name].spam=os.time()
  242.                 end
  243.             end
  244.         end
  245.         if pythag(87,370,x,y,20) and players[name].toys>=115 and not players[name].letter[2] then
  246.             players[name].letter[1],players[name].letter[2]=tfm.exec.addImage(images.letter.img,"&1",images.letter.x,images.letter.y,name),true
  247.             players[name].gift=1
  248.             saveData(name)
  249.             tfm.exec.removeImage(players[name].letter[3])
  250.             system.newTimer(function(timeId,arg1) if arg1[1] then tfm.exec.removeImage(arg1[1]) end end,6000,false,players[name].letter)
  251.             if players[name].toys>=200 and not players[name].power[1] then
  252.                 players[name].power[2]=tfm.exec.addImage(images.gift.img,"?10",291+images.gift.x,342+images.gift.y,name)
  253.             end
  254.         end
  255.         if pythag(291,342,x,y,20) and players[name].toys>=200 and players[name].gift==1 and not players[name].power[1] then
  256.             players[name].power[1]=0
  257.             tfm.exec.addImage(images.bell.img,"$"..name,images.bell.x,images.bell.y,name)
  258.             saveData(name)
  259.             for i=1,#images.rocket do
  260.                 table.insert(players[name].rocket,tfm.exec.addImage(images.rocket[i].img,"&2",images.rocket[i].x,images.rocket[i].y,name))
  261.             end
  262.             ui.addTextArea(50,"<a href='event:rocket'><b><font size='6'> </font><font size='15' color='#ffffff'> X</font></b></a>", name, 609,47,30,31,0x00000a,0x00000a,0.95,true)
  263.             tfm.exec.removeImage(players[name].power[2])
  264.         end
  265.     end
  266. end
  267.  
  268. function eventTextAreaCallback(id,name,callback)
  269.     if callback=="jingle" then
  270.         players[name].toys=players[name].toys+players[name].bag
  271.         if players[name].toys>999 then players[name].toys=999 end
  272.         if players[name].toys>=100 and players[name].toys-players[name].bag<100 then
  273.             system.giveEventGift(name,"titre_elfette")
  274.         elseif players[name].toys>=50 and players[name].toys-players[name].bag<50 then
  275.             system.giveEventGift(name,"nezrouge_noel2013")
  276.         elseif players[name].toys>=150 and players[name].toys-players[name].bag<150 then
  277.             system.giveEventGift(name,"echarpe_noel2013")
  278.         elseif players[name].toys>=200 and players[name].toys-players[name].bag<200 and players[name].gift==1 then
  279.             players[name].power[2]=tfm.exec.addImage(images.gift.img,"?10",291+images.gift.x,342+images.gift.y,name)
  280.         end
  281.         if #players[name].toysList == #players[name].toysTaken then
  282.             tfm.exec.giveCheese(name)          
  283.             tfm.exec.playerVictory(name)
  284.         end
  285.         players[name].bag=0
  286.         saveData(name)
  287.         ui.updateScores(name)  
  288.     elseif callback=="help" then
  289.         for k,v in pairs(players[name].help) do
  290.             tfm.exec.removeImage(v)
  291.         end
  292.         players[name].help={}
  293.         ui.removeTextArea(id,name)
  294.     elseif callback=="rocket" then
  295.         for k,v in pairs(players[name].rocket) do
  296.             tfm.exec.removeImage(v)
  297.         end
  298.         players[name].rocket={}
  299.         ui.removeTextArea(id,name)
  300.     end
  301. end
  302.  
  303. function eventPlayerDataLoaded(name,data)
  304.     players[name].gift=tonumber(string.sub(data,1,1)) or 0
  305.     players[name].toys=tonumber(string.sub(data,2,4)) or 0
  306.     players[name].power[1]=tonumber(string.sub(data,5,5)) or nil
  307.     ui.updateScores(name)
  308.     if  players[name].power[1] then tfm.exec.addImage(images.bell.img,"$"..name,images.bell.x,images.bell.y,name) end
  309.     if players[name].toys==0 then ui.help(name)
  310.     elseif players[name].toys>=115 then
  311.         system.bindMouse(name,true)
  312.         players[name].letter[3]=tfm.exec.addImage(images.boxletter.img,"?1",images.boxletter.x,images.boxletter.y,name)
  313.     end
  314.     if players[name].toys>=200 and players[name].gift==1 and not players[name].power[1] then players[name].power[2]=tfm.exec.addImage(images.gift.img,"?10",291+images.gift.x,342+images.gift.y,name) end
  315. end
  316.  
  317. function eventPlayerDied(name)
  318.     if not tfm.get.room.isAlive() then system.exit() end
  319. end
  320.  
  321. function eventPlayerWon(name)
  322.     eventPlayerDied(name)
  323. end
  324.  
  325. function eventLoop(time,remain)
  326.     if remain<500 then
  327.         system.exit()
  328.     end
  329.     for id,box in ipairs(boxTimers) do
  330.         local object = tfm.get.room.objectList[box[1]] or nil
  331.         if object then
  332.             local difftime=os.difftime(os.time(),box[2])
  333.             if difftime>=box[3] then   
  334.                 tfm.exec.explosion(object.x,object.y,settings.explosionPower,settings.radius, true)
  335.                 for name,player in pairs(tfm.get.room.playerList) do
  336.                     if pythag(player.x,player.y,object.x,object.y,settings.radius/2) and os.difftime(os.time(),players[name].timestamp)>=settings.timestamp then
  337.                         ui.updateHeart(name)
  338.                         players[name].timestamp=os.time()
  339.                         if #players[name].life == 0 then tfm.exec.killPlayer(name) end
  340.                     end
  341.                 end                
  342.                 tfm.exec.removeObject(box[1])
  343.                 tfm.get.room.objectList[box[1]]=object
  344.                 table.remove(boxTimers,id)
  345.             elseif difftime>=box[3]-1700 and difftime<box[3]-1000 and not box[8]then
  346.                 box[8]=true                    
  347.                 system.newTimer(function(timerId,arg1)  arg1=tfm.get.room.objectList[arg1] tfm.exec.removeObject(tfm.exec.addShamanObject(32,arg1.x+random(10,20),arg1.y+random(10,20))) for i=1,3 do tfm.exec.displayParticle(random(0,2),arg1.x+random(-5,5),arg1.y+random(0,15),random(-0.1,0.1),-0.5,0,-0.3) end end,box[3]-difftime+100,false,box[1])
  348.                 fireworks(box[1],box[3]-difftime)
  349.             elseif difftime>=box[3]-2700 and difftime<box[3]-2000 and not box[7]then
  350.                 box[7]=true
  351.                 system.newTimer(explosionFlash,1000,false,box)
  352.                 system.newTimer(explosionFlash,1700,false,box,true)
  353.                 system.newTimer(explosionFlash,2000,false,box)
  354.             end    
  355.         end
  356.     end
  357.  
  358. end
  359.  
  360. function eventEmotePlayed(name,emote)
  361.     if emote==3 then
  362.         local player=tfm.get.room.playerList[name]
  363.         for i=1,#map.mistletoe.x do
  364.             if pythag(player.x,player.y,map.mistletoe.x[i],map.mistletoe.y[i],map.mistletoe.r[i]) then
  365.                 for id,arg in ipairs(map.mistletoe.kiss[i]) do
  366.                     if os.difftime(os.time(),arg[1])<2000 and name~=arg[2]  then
  367.                         x=(player.x+(tfm.get.room.playerList[arg[2]].x or player.x))/2
  368.                         for j=1,10 do
  369.                             tfm.exec.displayParticle(table.random({30,30,31,31,32,33}),x+(j*5)*pow(-1,j),map.mistletoe.y[i]-40+cos(j)*20,table.random({-0.5,0.5}),0.5, 0,0)
  370.                         end
  371.                         table.remove(map.mistletoe.kiss[i],id)
  372.                         return nil
  373.                     else
  374.                         table.remove(map.mistletoe.kiss[i],id)
  375.                     end
  376.                 end
  377.                 table.insert(map.mistletoe.kiss[i],{os.time(),name})
  378.             end
  379.         end
  380.     end
  381. end
  382.  
  383. -- Database
  384.  
  385. function saveData(name)
  386.     if players[name].toys>999 then players[name].toys=999 end
  387.     local toys=tostring(players[name].toys)
  388.     if #toys==2 then toys="0"..toys
  389.     elseif #toys==1 then toys="00"..toys end
  390.     if players[name].power[1] then
  391.         system.savePlayerData(name,players[name].gift..toys.."0")
  392.     else
  393.         system.savePlayerData(name,players[name].gift..toys)
  394.     end
  395. end
  396.  
  397. --Fireworks
  398.  
  399. function drawCircle(id,arg)
  400.     local point1,point2,particle=arg[1],arg[2],arg[3]
  401.     r=sqrt(pow((point1.x-point2.x),2)+pow((point1.y-point2.y),2))
  402.     res=1-r*pow(10,-2)
  403.     if(res<0.1)then res =0.04 end
  404.     for i=0,2*math.pi,res do
  405.         tfm.exec.displayParticle(particle,point1.x+r*cos(i),point1.y+r*sin(i),random(-1,1),random(-1,1),0,0)
  406.     end
  407. end
  408.  
  409. function drawButterfly(id,arg)
  410.     local x,y,particles=arg[1],arg[2],arg[3]
  411.     for t=0,10,0.09 do
  412.         velocityEffect(x,y,x+(sin(t)*(exp(cos(t))-2*cos(4*t)-5*pow(sin(t/12),5))*-15),y+(cos(t)*(exp(cos(t))-2*cos(4*t)-5*pow(sin(t/12),5))*-15),particles)
  413.     end
  414. end
  415.  
  416. function drawParam1(id,arg)
  417.     local x,y,a,b,c,d,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7]
  418.     local j,k=3,3
  419.     for t=0,10,0.1 do
  420.         velocityEffect(x,y,x+(cos(a*t)-pow(cos(b*t),j))*20,y+(sin(c*t)-pow(sin(d*t),k))*20,particles)
  421.     end
  422. end
  423.  
  424. function drawParam2(id,arg)
  425.     local x,y,k,a,m,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]
  426.     local b=a/k
  427.     for t=0,30,0.5 do
  428.         velocityEffect(x,y,x+((a-b)*cos(t)+b*cos(t*((a/b)-1)))*m,y+((a-b)*sin(t)-b*sin(t*((a/b)-1)))*m,particles)
  429.     end
  430. end
  431.  
  432. function drawLines(id,arg)
  433.     local x,y=arg[1],arg[2]
  434.     local particles={13,11,9,2,1}
  435.     for t=-50,50,3 do
  436.         tfm.exec.displayParticle(table.random(particles),x+t,y+t-30,random(-1,1),random(-1,1),0,0)
  437.         tfm.exec.displayParticle(table.random(particles),x+t,y-t+30,random(-1,1),random(-1,1),0,0)
  438.         tfm.exec.displayParticle(table.random(particles),x+t,y-t-30,random(-1,1),random(-1,1),0,0)
  439.         tfm.exec.displayParticle(table.random(particles),x+t,y+t+30,random(-1,1),random(-1,1),0,0)
  440.     end
  441. end
  442.  
  443. function drawCircleVelocity(id,arg)
  444.     local x,y,particles=arg[1],arg[2],{13,11,9,2,1}
  445.     for i=0,360,20 do
  446.         tfm.exec.displayParticle(table.random(particles),x,y,cos(math.pi*i/180)*-2,-sin(math.pi*i/180)*-2,0,0)
  447.     end
  448.     x,y=x+random(-40,40),y+random(-40,40)
  449.     for i=0,360,20 do
  450.         tfm.exec.displayParticle(table.random(particles),x,y,cos(math.pi*i/180)*-3,-sin(math.pi*i/180)*-3,0,0)
  451.     end
  452. end
  453.  
  454. function drawHeart(id,arg)
  455.     local x,y,particles=arg[1],arg[2],{13,11,9,2,1,30,31}
  456.     for t=-60,60,3 do
  457.         if t<0 then
  458.             l=-t
  459.             x1=0.01*((-pow(l,2))+40*l+1200)*sin(math.pi*l/180)
  460.             y1=-0.01*((-pow(l,2))+40*l+1200)*cos(math.pi*l/180)
  461.         else
  462.             x1=-0.01*((-pow(t,2))+40*t+1200)*sin(math.pi*t/180)
  463.             y1=-0.01*((-pow(t,2))+40*t+1200)*cos(math.pi*t/180)
  464.         end
  465.         tfm.exec.displayParticle(table.random(particles),x1*5+x,y1*5+y,table.random({-0.5,0.5}),table.random({-0.5,0.5}),0,0)
  466.     end
  467. end
  468.  
  469. function drawCurve(id,arg)
  470.     local x,y,particles=arg[1],arg[2],arg[3]
  471.     for j=1,random(2,3) do
  472.         for i=0,100,2 do
  473.             tfm.exec.displayParticle(table.random(particles),x+cos(i)*10,y-i,table.random({-0.5,0.5}),random(-1,1),0,0)
  474.         end
  475.     end
  476. end
  477.  
  478. function drawBasic(id,arg)
  479.     tfm.exec.displayParticle(10,arg[1],arg[2],0,0,0,0)
  480.     tfm.exec.displayParticle(12,arg[1]+random(-20,20),arg[2]+random(-20,20),0,0,0,0)
  481. end
  482.  
  483. function drawCirclePlus(id,arg)
  484.     local last,particles=0,arg[3]
  485.     for j=1,random(2,3)do
  486.         rand=random(-40,40)
  487.         for i=1,random(2,3) do
  488.             repeat
  489.                 particleId=table.random(particles)
  490.             until particleId~=last
  491.             last=particleId
  492.             drawCircle(id,{{x=arg[1]+rand,y=arg[2]},{x=arg[1]+rand+(i+1)*10,y=arg[2]},last})
  493.         end
  494.         arg[1]=arg[1]+random(-40,40)
  495.     end
  496. end
  497.  
  498. function velocityEffect(xS,yS,xE,yE,particles)
  499.     local angle = atan2(yE - yS, xE - xS)
  500.     tfm.exec.displayParticle(table.random(particles),xE,yE,cos(angle),sin(angle),0,0)
  501. end
  502.  
  503. fireworksTable={drawBasic,drawHeart,drawLines,drawParam1,drawParam1,drawParam1,drawCurve,drawCirclePlus,drawCircleVelocity,drawParam1,drawParam1,drawParam1,drawParam1,drawParam1,drawParam1}
  504. glitter={13,11,9,2,1}
  505. fireworksArgs={{0,-130},{0,-130},{0,-130},{0,-130,7,1,7,1,glitter},{0,-130,1,5,1,5,glitter},{0,-130,1,3,3,1,glitter},{0,-130,glitter},{0,-130,glitter},{0,-130},{0,-130,4,1,4,1,glitter},
  506. {0,-130,2,1,2,1,glitter},{0,-130,1,2,1,2,glitter},{0,-130,1,4,1,4,glitter},{0,-130,4,1,4,1,glitter},{0,-130,1,3,3,1,glitter}}
  507.  
  508. function fireworks(boxId,time)
  509.     for i=0,math.random(0,1) do
  510.         local choice,args=random(1,#fireworksTable),{}
  511.         for k,v in pairs(fireworksArgs[choice])do table.insert(args,v) end
  512.         args[1],args[2]=tfm.get.room.objectList[boxId].x+math.random(-40*i,40*i)+fireworksArgs[choice][1],tfm.get.room.objectList[boxId].y+math.random(-40*i,-20*i)+fireworksArgs[choice][2]
  513.         system.newTimer(fireworksTable[choice],time+400+i*200,false,args)
  514.     end
  515. end
  516.  
  517. -- Main
  518.  
  519. function newRound()
  520.     tfm.exec.newGame(map.code) 
  521.     tfm.exec.addImage(map.background.img,"?1",map.background.x,map.background.y)
  522.     tfm.exec.setUIMapName("[Fierying & Thewav] "..text.name)
  523.     tfm.exec.setGameTime(180)
  524.     for name,player in pairs(tfm.get.room.playerList) do
  525.         tfm.exec.bindKeyboard(name,83,true,true)
  526.         tfm.exec.bindKeyboard(name,40,true,true)   
  527.         tfm.exec.bindKeyboard(name,32,true,true)   
  528.         players[name]={life={},toys=0,toysList={},toysTaken={},scoreImg={-2,-2,-2},timestamp=0,spam=0,bag=0,help={},rocket={},letter={nil,false,nil},power={nil,-800},gift=false}
  529.         system.loadPlayerData(name)
  530.         ui.updateScores(name)  
  531.         for i=0,settings.life-1 do
  532.             table.insert(players[name].life,tfm.exec.addImage(images.heart.img,"&4",images.heart.x+i*21,images.heart.y,name))
  533.         end
  534.     end
  535.     for id=1,#map.posJingle.x do
  536.         local info={map.posJingle.img[id],map.posJingle.x[id],map.posJingle.y[id]}
  537.         tfm.exec.addImage(images.jingle.img[info[1]],"?2",info[2]+images.jingle.x[info[1]],info[3]+images.jingle.y[info[1]])
  538.         tfm.exec.addImage(text.elf,"?2",info[2]+images.elves.x,info[3]+images.elves.y)
  539.     end
  540.     for i=1,settings.toysNum do
  541.         local j=0
  542.         repeat
  543.             id=random(1,#map.toysPos.x)
  544.             toysTemp={y=map.toysPos.y[id],x=random(map.toysPos.x[id],map.toysPos.x[id]+map.toysPos.l[id])}
  545.             j=j+1
  546.         until not nearObject(toysTemp.x,toysTemp.y,60,toys) or j>100
  547.         if j<=100 then
  548.             table.insert(toys,toysTemp)
  549.             local idTemp = random(1,#images.toys.img)
  550.             for name,player in pairs(tfm.get.room.playerList) do               
  551.                 local idImg=tfm.exec.addImage(images.toys.img[idTemp],"!2",toysTemp.x+images.toys.x[idTemp],toysTemp.y+images.toys.y[idTemp],name)
  552.                 table.insert(players[name].toysList,idImg)
  553.             end
  554.            
  555.         end
  556.     end
  557.     for i=1,settings.barrels do
  558.         local j=0
  559.         repeat
  560.             id=random(1,#map.barrels.x)
  561.             barrelTemp={y=map.barrels.y[id],x=random(map.barrels.x[id],map.barrels.x[id]+map.barrels.l[id]),w=map.barrels.w[id]}
  562.             j=j+1
  563.         until not nearObject(barrelTemp.x,barrelTemp.y,40,barrels) or j>100
  564.         if j<=100 then
  565.             table.insert(barrels,barrelTemp)
  566.             spawnBoxes(boxPattern[random(barrelTemp.w,#boxPattern)],barrelTemp.x,barrelTemp.y)
  567.         end
  568.     end
  569. end
  570.  
  571. system.newTimer(
  572. function()
  573.     for id,barrel in pairs(barrels) do
  574.             spawnBoxes(boxPattern[random(barrel.w,#boxPattern)],barrel.x,barrel.y)
  575.     end
  576. end,90500)
  577.  
  578. system.newTimer(newRound,1000)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top