Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- system.disableChatCommandDisplay("help",true)
- tfm.exec.disableAutoShaman(true)
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAutoTimeLeft(true)
- sin=math.sin
- cos=math.cos
- exp=math.exp
- pow=math.pow
- random=math.random
- sqrt=math.sqrt
- atan2=math.atan2
- 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}}}
- 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}},}
- map={
- 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>',
- background={img="mRKhmjS.png",x=0,y=0},
- posJingle={x={1424,178,256,964},y={348,343,668,761},img={4,2,3,1}},
- mistletoe={x={840,320},y={97,668},r={50,50},kiss={{},{}}},
- toysPos={
- 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},
- 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},
- 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}
- },
- barrels={
- 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},
- 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},
- 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},
- 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}}
- }
- settings={life=3,bagMax=3,toysNum=30,timestamp=8000,radius=75,barrels=36,explosionPower=42}
- players={}
- toys={}
- barrels={}
- boxTimers={}
- globalTime=0
- text={
- 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",
- RU={name="<J> Игрушечная фабрика",give="<J>Ох! %s большие игрушки! Спасибо!",empty="<J>Ваша сумка пуста :(",full="<J> Ваша сумка полная ^_^",elf="KVxylyj.png"},
- 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"},
- 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"},
- 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"},
- 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"},
- 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"},
- 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"},
- 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"},
- 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"},
- 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"},
- 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"},
- 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"},
- CN={name="<J>玩具工厂",give="<J>哦!你带来了 %s 个玩具!谢谢!",empty="<J>你的包没有玩具 :(",full="<J>你的包已经满了 ^_^",elf="jZaeS2r.png"},
- 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"}}
- lang=tfm.get.room.community
- if text[lang] then
- for id,message in pairs(text[lang]) do
- text[id]=message
- end
- end
- --Utils
- function table.contains(t,element)
- for key,value in ipairs(t) do
- if value==element then
- return true
- end
- end
- return false
- end
- function string.split(str,s)
- local res = {}
- for part in string.gmatch(str, "[^" .. s .. "]+") do
- table.insert(res, part)
- end
- return res
- end
- function table.random(t)
- return t[random(1,#t)]
- end
- function tfm.get.room.isAlive()
- for name,player in pairs(tfm.get.room.playerList) do
- if not player.isDead then return true end
- end
- return false
- end
- -- Collision
- function pythag(x1,y1,x2,y2,r)
- local x=x2-x1
- local y=y2-y1
- local r=r+r
- return x*x+y*y<r*r
- end
- function nearObject(x1,y1,nearPixel,table)
- for id,pos in ipairs(table) do
- if pythag(x1,y1,pos.x,pos.y,nearPixel) then return id end
- end
- return nil
- end
- -- Ui
- function ui.updateScores(name)
- local str=players[name].bag.."/"..settings.bagMax
- local x,y,num=0,0,0
- for i,k in pairs(players[name].scoreImg) do
- tfm.exec.removeImage(k)
- end
- players[name].scoreImg={}
- for i=1,#str do
- num=((tonumber(str:sub(i,i)))or 10)+1
- if num==11 then x,y=1,-1 else x,y=0,0 end
- table.insert(players[name].scoreImg,tfm.exec.addImage(images.numbers[num],"&3",40+(i-1)*14+x,60+y,name,true))
- end
- tfm.exec.addImage(images.full.img,"&3",images.full.x,images.full.y,name,true)
- ui.addTextArea(-2, "<J><b><font size='12'> "..players[name].toys.."</font></b>", name, 735, 350, 100, 20,nil,nil, 0.6,true)
- tfm.exec.addImage(images.toys.img[1],"&3",745+images.toys.x[1],353+images.toys.y[1],name,true)
- end
- function ui.updateHeart(name)
- tfm.exec.removeImage(players[name].life[#players[name].life] or -500)
- table.remove(players[name].life,#players[name].life)
- end
- function ui.help(name)
- if not players[name].help[1] then
- for i=1,#images.help do
- table.insert(players[name].help,tfm.exec.addImage(images.help[i].img,"&5",images.help[i].x,images.help[i].y,name))
- end
- 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)
- end
- end
- -- Explosions
- function spawnBoxes(boxTable,x,y)
- local boxId,imgTale,imgId= 0,0,0
- for id,box in ipairs(boxTable) do
- boxId=tfm.exec.addShamanObject(box.id, x+box.x, y+box.y, box.angle, 0, 0,false)
- if box.id==2 then imgTable=images.barrelBig
- elseif box.id==1 then imgTable=images.barrelLittle
- elseif box.id==60 then imgTable=images.fireworks end
- imgId=random(1,#imgTable.img)
- tfm.exec.addImage(imgTable.img[imgId],"#"..boxId,imgTable.x[imgId],imgTable.y[imgId])
- table.insert(boxTimers,{boxId,os.time(),random(6,90)*1000,0,box.id,imgId,false,false})
- end
- end
- function explosionFlash(id,box,remove)
- local imgTable=nil
- if box[5]==2 then imgTable=images.barrelBig
- elseif box[5]==1 then imgTable=images.barrelLittle
- elseif box[5]==60 then imgTable=images.fireworks end
- if imgTable then
- if remove then tfm.exec.addImage(imgTable.img[box[6]],"#"..box[1],imgTable.x[box[6]],imgTable.y[box[6]])
- else tfm.exec.addImage(imgTable.imgFlash[box[6]],"#"..box[1],imgTable.x[box[6]],imgTable.y[box[6]]) end
- end
- end
- -- Events
- function eventChatCommand(name,msg)
- if msg=="help" then ui.help(name) end
- end
- function eventNewPlayer(name)
- tfm.exec.addImage(map.background.img,"?1",map.background.x,map.background.y,name)
- tfm.exec.setUIMapName(text.name)
- end
- function eventMouse(name,x,y)
- if players[name].letter[1] then
- tfm.exec.removeImage(players[name].letter[1])
- players[name].letter[1]=nil
- end
- if players[name].power[1] then
- if os.difftime(os.time(),players[name].power[1])>=15000 and os.difftime(os.time(),globalTime)>=2000 then
- tfm.exec.removeImage(players[name].power[2])
- local choice=random(1,3)
- local glitter={13,11,9,2,21,23,24}
- drawParam2(0,{x,y,-10,9.8955,7,{13,11,9,2,1}})
- drawCircle(0,{{x=x,y=y},{x=x,y=y+40},{13,11,9,2,1}})
- if choice==1 then
- drawButterfly(0,{x,y,{table.random(glitter)}})
- elseif choice==2 then
- drawParam2(0,{x,y,5,0.5,60,{table.random(glitter)}})
- drawParam2(0,{x,y,1.6,0.5,25,{table.random(glitter)}})
- elseif choice==3 then
- drawParam1(0,{x,y,5,1,5,1,{table.random(glitter)}})
- end
- players[name].power[1]=os.time()
- globalTime=os.time()
- end
- end
- end
- function eventKeyboard(name,key,down,x,y)
- if key==32 or key==83 or key==40 then
- local near=nearObject(x,y,20,toys)
- for id=1,#map.posJingle.x do
- if pythag(x,y,map.posJingle.x[id],map.posJingle.y[id],20) then
- if players[name].bag>0 then
- tfm.exec.chatMessage(string.format(text.give,players[name].bag),name)
- players[name].spam=os.time()
- local particleHearts={{x=0,y=-0.5},{x=0.5,y=-0.5},{x=-0.5,y=-0.5}}
- for i=1,players[name].bag do
- tfm.exec.displayParticle(5, map.posJingle.x[id], map.posJingle.y[id]-20, particleHearts[i].x, particleHearts[i].y, 0, 0,name)
- end
- eventTextAreaCallback(0,name,"jingle")
- near=nil
- else
- if os.difftime(os.time(),players[name].spam)>1000 then
- tfm.exec.chatMessage(text.empty,name)
- players[name].spam=os.time()
- end
- end
- end
- end
- if near and not table.contains(players[name].toysTaken,near)then
- if not (players[name].bag>=settings.bagMax) then
- table.insert(players[name].toysTaken,near)
- tfm.exec.removeImage(players[name].toysList[near])
- players[name].bag=players[name].bag+1
- tfm.exec.displayParticle(15,x+15,y-15,0,-1,0,0,name)
- ui.updateScores(name)
- end
- if players[name].bag>=settings.bagMax then
- if os.difftime(os.time(),players[name].spam)>1000 then
- tfm.exec.chatMessage(text.full,name)
- players[name].spam=os.time()
- end
- end
- end
- if pythag(87,370,x,y,20) and players[name].toys>=115 and not players[name].letter[2] then
- players[name].letter[1],players[name].letter[2]=tfm.exec.addImage(images.letter.img,"&1",images.letter.x,images.letter.y,name),true
- players[name].gift=1
- saveData(name)
- tfm.exec.removeImage(players[name].letter[3])
- system.newTimer(function(timeId,arg1) if arg1[1] then tfm.exec.removeImage(arg1[1]) end end,6000,false,players[name].letter)
- if players[name].toys>=200 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
- end
- if pythag(291,342,x,y,20) and players[name].toys>=200 and players[name].gift==1 and not players[name].power[1] then
- players[name].power[1]=0
- tfm.exec.addImage(images.bell.img,"$"..name,images.bell.x,images.bell.y,name)
- saveData(name)
- for i=1,#images.rocket do
- table.insert(players[name].rocket,tfm.exec.addImage(images.rocket[i].img,"&2",images.rocket[i].x,images.rocket[i].y,name))
- end
- 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)
- tfm.exec.removeImage(players[name].power[2])
- end
- end
- end
- function eventTextAreaCallback(id,name,callback)
- if callback=="jingle" then
- players[name].toys=players[name].toys+players[name].bag
- if players[name].toys>999 then players[name].toys=999 end
- if players[name].toys>=100 and players[name].toys-players[name].bag<100 then
- system.giveEventGift(name,"titre_elfette")
- elseif players[name].toys>=50 and players[name].toys-players[name].bag<50 then
- system.giveEventGift(name,"nezrouge_noel2013")
- elseif players[name].toys>=150 and players[name].toys-players[name].bag<150 then
- system.giveEventGift(name,"echarpe_noel2013")
- elseif players[name].toys>=200 and players[name].toys-players[name].bag<200 and players[name].gift==1 then
- players[name].power[2]=tfm.exec.addImage(images.gift.img,"?10",291+images.gift.x,342+images.gift.y,name)
- end
- if #players[name].toysList == #players[name].toysTaken then
- tfm.exec.giveCheese(name)
- tfm.exec.playerVictory(name)
- end
- players[name].bag=0
- saveData(name)
- ui.updateScores(name)
- elseif callback=="help" then
- for k,v in pairs(players[name].help) do
- tfm.exec.removeImage(v)
- end
- players[name].help={}
- ui.removeTextArea(id,name)
- elseif callback=="rocket" then
- for k,v in pairs(players[name].rocket) do
- tfm.exec.removeImage(v)
- end
- players[name].rocket={}
- ui.removeTextArea(id,name)
- end
- end
- function eventPlayerDataLoaded(name,data)
- players[name].gift=tonumber(string.sub(data,1,1)) or 0
- players[name].toys=tonumber(string.sub(data,2,4)) or 0
- players[name].power[1]=tonumber(string.sub(data,5,5)) or nil
- ui.updateScores(name)
- if players[name].power[1] then tfm.exec.addImage(images.bell.img,"$"..name,images.bell.x,images.bell.y,name) end
- if players[name].toys==0 then ui.help(name)
- elseif players[name].toys>=115 then
- system.bindMouse(name,true)
- players[name].letter[3]=tfm.exec.addImage(images.boxletter.img,"?1",images.boxletter.x,images.boxletter.y,name)
- end
- 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
- end
- function eventPlayerDied(name)
- if not tfm.get.room.isAlive() then system.exit() end
- end
- function eventPlayerWon(name)
- eventPlayerDied(name)
- end
- function eventLoop(time,remain)
- if remain<500 then
- system.exit()
- end
- for id,box in ipairs(boxTimers) do
- local object = tfm.get.room.objectList[box[1]] or nil
- if object then
- local difftime=os.difftime(os.time(),box[2])
- if difftime>=box[3] then
- tfm.exec.explosion(object.x,object.y,settings.explosionPower,settings.radius, true)
- for name,player in pairs(tfm.get.room.playerList) do
- if pythag(player.x,player.y,object.x,object.y,settings.radius/2) and os.difftime(os.time(),players[name].timestamp)>=settings.timestamp then
- ui.updateHeart(name)
- players[name].timestamp=os.time()
- if #players[name].life == 0 then tfm.exec.killPlayer(name) end
- end
- end
- tfm.exec.removeObject(box[1])
- tfm.get.room.objectList[box[1]]=object
- table.remove(boxTimers,id)
- elseif difftime>=box[3]-1700 and difftime<box[3]-1000 and not box[8]then
- box[8]=true
- 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])
- fireworks(box[1],box[3]-difftime)
- elseif difftime>=box[3]-2700 and difftime<box[3]-2000 and not box[7]then
- box[7]=true
- system.newTimer(explosionFlash,1000,false,box)
- system.newTimer(explosionFlash,1700,false,box,true)
- system.newTimer(explosionFlash,2000,false,box)
- end
- end
- end
- end
- function eventEmotePlayed(name,emote)
- if emote==3 then
- local player=tfm.get.room.playerList[name]
- for i=1,#map.mistletoe.x do
- if pythag(player.x,player.y,map.mistletoe.x[i],map.mistletoe.y[i],map.mistletoe.r[i]) then
- for id,arg in ipairs(map.mistletoe.kiss[i]) do
- if os.difftime(os.time(),arg[1])<2000 and name~=arg[2] then
- x=(player.x+(tfm.get.room.playerList[arg[2]].x or player.x))/2
- for j=1,10 do
- 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)
- end
- table.remove(map.mistletoe.kiss[i],id)
- return nil
- else
- table.remove(map.mistletoe.kiss[i],id)
- end
- end
- table.insert(map.mistletoe.kiss[i],{os.time(),name})
- end
- end
- end
- end
- -- Database
- function saveData(name)
- if players[name].toys>999 then players[name].toys=999 end
- local toys=tostring(players[name].toys)
- if #toys==2 then toys="0"..toys
- elseif #toys==1 then toys="00"..toys end
- if players[name].power[1] then
- system.savePlayerData(name,players[name].gift..toys.."0")
- else
- system.savePlayerData(name,players[name].gift..toys)
- end
- end
- --Fireworks
- function drawCircle(id,arg)
- local point1,point2,particle=arg[1],arg[2],arg[3]
- r=sqrt(pow((point1.x-point2.x),2)+pow((point1.y-point2.y),2))
- res=1-r*pow(10,-2)
- if(res<0.1)then res =0.04 end
- for i=0,2*math.pi,res do
- tfm.exec.displayParticle(particle,point1.x+r*cos(i),point1.y+r*sin(i),random(-1,1),random(-1,1),0,0)
- end
- end
- function drawButterfly(id,arg)
- local x,y,particles=arg[1],arg[2],arg[3]
- for t=0,10,0.09 do
- 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)
- end
- end
- function drawParam1(id,arg)
- local x,y,a,b,c,d,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7]
- local j,k=3,3
- for t=0,10,0.1 do
- velocityEffect(x,y,x+(cos(a*t)-pow(cos(b*t),j))*20,y+(sin(c*t)-pow(sin(d*t),k))*20,particles)
- end
- end
- function drawParam2(id,arg)
- local x,y,k,a,m,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]
- local b=a/k
- for t=0,30,0.5 do
- 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)
- end
- end
- function drawLines(id,arg)
- local x,y=arg[1],arg[2]
- local particles={13,11,9,2,1}
- for t=-50,50,3 do
- tfm.exec.displayParticle(table.random(particles),x+t,y+t-30,random(-1,1),random(-1,1),0,0)
- tfm.exec.displayParticle(table.random(particles),x+t,y-t+30,random(-1,1),random(-1,1),0,0)
- tfm.exec.displayParticle(table.random(particles),x+t,y-t-30,random(-1,1),random(-1,1),0,0)
- tfm.exec.displayParticle(table.random(particles),x+t,y+t+30,random(-1,1),random(-1,1),0,0)
- end
- end
- function drawCircleVelocity(id,arg)
- local x,y,particles=arg[1],arg[2],{13,11,9,2,1}
- for i=0,360,20 do
- tfm.exec.displayParticle(table.random(particles),x,y,cos(math.pi*i/180)*-2,-sin(math.pi*i/180)*-2,0,0)
- end
- x,y=x+random(-40,40),y+random(-40,40)
- for i=0,360,20 do
- tfm.exec.displayParticle(table.random(particles),x,y,cos(math.pi*i/180)*-3,-sin(math.pi*i/180)*-3,0,0)
- end
- end
- function drawHeart(id,arg)
- local x,y,particles=arg[1],arg[2],{13,11,9,2,1,30,31}
- for t=-60,60,3 do
- if t<0 then
- l=-t
- x1=0.01*((-pow(l,2))+40*l+1200)*sin(math.pi*l/180)
- y1=-0.01*((-pow(l,2))+40*l+1200)*cos(math.pi*l/180)
- else
- x1=-0.01*((-pow(t,2))+40*t+1200)*sin(math.pi*t/180)
- y1=-0.01*((-pow(t,2))+40*t+1200)*cos(math.pi*t/180)
- end
- 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)
- end
- end
- function drawCurve(id,arg)
- local x,y,particles=arg[1],arg[2],arg[3]
- for j=1,random(2,3) do
- for i=0,100,2 do
- tfm.exec.displayParticle(table.random(particles),x+cos(i)*10,y-i,table.random({-0.5,0.5}),random(-1,1),0,0)
- end
- end
- end
- function drawBasic(id,arg)
- tfm.exec.displayParticle(10,arg[1],arg[2],0,0,0,0)
- tfm.exec.displayParticle(12,arg[1]+random(-20,20),arg[2]+random(-20,20),0,0,0,0)
- end
- function drawCirclePlus(id,arg)
- local last,particles=0,arg[3]
- for j=1,random(2,3)do
- rand=random(-40,40)
- for i=1,random(2,3) do
- repeat
- particleId=table.random(particles)
- until particleId~=last
- last=particleId
- drawCircle(id,{{x=arg[1]+rand,y=arg[2]},{x=arg[1]+rand+(i+1)*10,y=arg[2]},last})
- end
- arg[1]=arg[1]+random(-40,40)
- end
- end
- function velocityEffect(xS,yS,xE,yE,particles)
- local angle = atan2(yE - yS, xE - xS)
- tfm.exec.displayParticle(table.random(particles),xE,yE,cos(angle),sin(angle),0,0)
- end
- fireworksTable={drawBasic,drawHeart,drawLines,drawParam1,drawParam1,drawParam1,drawCurve,drawCirclePlus,drawCircleVelocity,drawParam1,drawParam1,drawParam1,drawParam1,drawParam1,drawParam1}
- glitter={13,11,9,2,1}
- 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},
- {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}}
- function fireworks(boxId,time)
- for i=0,math.random(0,1) do
- local choice,args=random(1,#fireworksTable),{}
- for k,v in pairs(fireworksArgs[choice])do table.insert(args,v) end
- 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]
- system.newTimer(fireworksTable[choice],time+400+i*200,false,args)
- end
- end
- -- Main
- function newRound()
- tfm.exec.newGame(map.code)
- tfm.exec.addImage(map.background.img,"?1",map.background.x,map.background.y)
- tfm.exec.setUIMapName("[Fierying & Thewav] "..text.name)
- tfm.exec.setGameTime(180)
- for name,player in pairs(tfm.get.room.playerList) do
- tfm.exec.bindKeyboard(name,83,true,true)
- tfm.exec.bindKeyboard(name,40,true,true)
- tfm.exec.bindKeyboard(name,32,true,true)
- 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}
- system.loadPlayerData(name)
- ui.updateScores(name)
- for i=0,settings.life-1 do
- table.insert(players[name].life,tfm.exec.addImage(images.heart.img,"&4",images.heart.x+i*21,images.heart.y,name))
- end
- end
- for id=1,#map.posJingle.x do
- local info={map.posJingle.img[id],map.posJingle.x[id],map.posJingle.y[id]}
- tfm.exec.addImage(images.jingle.img[info[1]],"?2",info[2]+images.jingle.x[info[1]],info[3]+images.jingle.y[info[1]])
- tfm.exec.addImage(text.elf,"?2",info[2]+images.elves.x,info[3]+images.elves.y)
- end
- for i=1,settings.toysNum do
- local j=0
- repeat
- id=random(1,#map.toysPos.x)
- toysTemp={y=map.toysPos.y[id],x=random(map.toysPos.x[id],map.toysPos.x[id]+map.toysPos.l[id])}
- j=j+1
- until not nearObject(toysTemp.x,toysTemp.y,60,toys) or j>100
- if j<=100 then
- table.insert(toys,toysTemp)
- local idTemp = random(1,#images.toys.img)
- for name,player in pairs(tfm.get.room.playerList) do
- local idImg=tfm.exec.addImage(images.toys.img[idTemp],"!2",toysTemp.x+images.toys.x[idTemp],toysTemp.y+images.toys.y[idTemp],name)
- table.insert(players[name].toysList,idImg)
- end
- end
- end
- for i=1,settings.barrels do
- local j=0
- repeat
- id=random(1,#map.barrels.x)
- 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]}
- j=j+1
- until not nearObject(barrelTemp.x,barrelTemp.y,40,barrels) or j>100
- if j<=100 then
- table.insert(barrels,barrelTemp)
- spawnBoxes(boxPattern[random(barrelTemp.w,#boxPattern)],barrelTemp.x,barrelTemp.y)
- end
- end
- end
- system.newTimer(
- function()
- for id,barrel in pairs(barrels) do
- spawnBoxes(boxPattern[random(barrel.w,#boxPattern)],barrel.x,barrel.y)
- end
- end,90500)
- system.newTimer(newRound,1000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement