Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Titles ]]--
- title = {
- [1] = "Packrat",
- [2] = "Reindeer",
- [3] = "Santa's Sack",
- --[[
- Panettone
- Naughty
- Secret Santa (Amigo secreto)
- Christmas Tree
- Snowman
- Snowmouse
- Frozen Mouse
- Snowglobe
- Old Saint Mouse
- Frosty Mouse
- Elf Mouse
- ]]
- }
- --[[ Lib ]]--
- math.pythag = function(x1,y1,x2,y2,range)
- return ((x1-x2)^2+(y1-y2)^2<range^2)
- end
- math.percent = function(x,of,total)
- return (x/of)*total
- end
- table.random = function(t,r)
- local i = math.random(#t)
- if r then return t[i],i else return t[i] end
- end
- table.destroy=function(list,value)
- for k,v in next,list do
- if v == value then
- table.remove(list,k);break
- end
- end
- end
- system.looping = function(f,tk)
- local s = 1000 / tk
- local t = {}
- for timer = 0,1000-s,s do
- system.newTimer(function() t[#t] = system.newTimer(f,1000,true) end,1000+timer,false)
- end
- return t
- end
- base64 = {}
- base64.base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
- base64.to = function(str)
- local str = {str:byte(1,#str)}
- local code = {}
- local bs
- for i = 1,#str,3 do
- bs = bit32.rshift(str[i] % 0xFD,2)
- code[#code + 1] = base64.base:sub(bs + 1,bs + 1)
- bs = bit32.lshift(str[i] % 0x04,4)
- if (i + 1 <= #str) then
- bs = bit32.bor(bs,bit32.rshift(str[i + 1] % 0xF1,4))
- code[#code + 1] = base64.base:sub(bs + 1,bs + 1)
- bs = bit32.lshift(str[i + 1] % 0x10,2)
- if (i + 2 <= #str) then
- bs = bit32.bor(bs,bit32.rshift(str[i + 2] % 0xC1,6))
- code[#code + 1] = base64.base:sub(bs + 1,bs + 1)
- bs = str[i + 2] % 0x40
- code[#code + 1] = base64.base:sub(bs + 1,bs + 1)
- else
- code[#code + 1] = base64.base:sub(bs + 1,bs + 1)
- code[#code + 1] = "="
- end
- else
- code[#code + 1] = base64.base:sub(bs + 1, bs + 1)
- code[#code + 1] = "=="
- end
- end
- return table.concat(code)
- end
- morse = {}
- morse.code = {a=".-",b="-...",c="-.-.",d="-..",e=".",f="..-.",g="--.",h="....",i="..",j=".---",k="-.-",l=".-..",m="--",n="-.",o="---",p=".--.",q="--.-",r=".-.",s="...",t="-",u="..-",v="...-",w=".--",x="-..-",y="-.--",z="--..",[1]=".----",[2]="..---",[3]="...--",[4]="....-",[5]=".....",[6]="-....",[7]="--...",[8]="---..",[9]="----.",[0]="-----"}
- morse.to = function(str)
- str = str:lower()
- str = str:gsub(" +"," / ")
- for i,v in next,morse.code do
- str = str:gsub(tostring(i),v.." ")
- end
- return str
- end
- enigma = {}
- enigma.words = {
- "Li4uLiAuLSAuLS0uIC4uICAvIC0uLi0gLi4gLS0gLi0gLi4uIC4uLSA=", -- Hapi Ximasu
- }
- enigma.verify = function(player,word)
- if not info[player].db.titles[3] then
- if info[player].db.enigma == base64.to(morse.to(word)) then
- info[player].db.titles[3] = true
- --system.giveEventGift(player,title[3])
- end
- end
- end
- --[[ Database ]]--
- info = {}
- serialization = {table={},string={}}
- serialization.table.tostring = function(t)
- local str = ""
- for index,value in next,t do
- local prefix,tbOption = (type(value)=="string" and "_@" or type(value)=="boolean" and "_!" or type(value)=="number" and "_#" or type(value)=="table" and "_%" or ""),(type(value)~="table" and tostring(value) or "+&"..serialization.table.tostring(value):gsub(";","?").."&-")
- str = str .. ':' .. tostring(index) .. prefix .. tbOption .. ";"
- end
- return str
- end
- serialization.string.totable = function(s)
- local list = {}
- for str in s:gmatch("(.-);") do
- local varName,valueType,value = str:match(':(.-)_(%p)(.+)')
- if varName~=nil then
- varName = tonumber(varName) or varName
- if valueType == "@" then
- list[varName] = tostring(value)
- elseif valueType == "!" then
- list[varName] = value=="true"
- elseif valueType == "#" then
- list[varName] = tonumber(value)
- elseif valueType == "%" then
- list[varName] = serialization.string.totable(value:gsub("+&",""):gsub("&-",""):gsub("%?",";"))
- end
- end
- end
- return list
- end
- --[[
- eventPlayerDataLoaded = function(n,d)
- local data
- if d == "" then
- data = {
- db = {
- gifts = {{0,0,0,0},0},
- aim = 5,
- titles = {false,false,false},
- enigma = table.random(enigma.words),
- },
- }
- --system.savePlayerData(n,serialization.table.tostring(data.db))
- else
- data = serialization.string.totable(d)
- end
- info[n] = data
- end
- ]]
- --[[ Sets ]]--
- tfm.exec.disableAutoShaman()
- tfm.exec.disableAfkDeath()
- --[[ Map ]]--
- local xml = '<C><P /><Z><S o="47F6E1"><S o="47F6E1" X="400" L="800" Y="400" H="70" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S o="47F6E1" X="-5" L="10" Y="200" H="400" P="0,0,0,0,0,0,0,0" T="12" /><S o="47F6E1" X="457" L="80" Y="154" H="12" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S o="47F6E1" X="805" L="10" Y="200" H="400" P="0,0,0,0,0,0,0,0" T="12" /><S o="47F6E1" X="157" L="92" Y="303" H="12" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S o="47F6E1" X="400" L="800" Y="-5" H="10" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S o="47F6E1" X="307" L="110" Y="236" H="12" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S o="47F6E1" X="270" L="70" Y="140" H="12" P="0,0,0.3,0.2,0,0,0,0" T="12" /><S o="47F6E1" X="77" L="155" Y="200" H="12" P="0,0,0.3,0.2,0,0,0,0" T="12" /></S><D /><O /></Z></C>'
- tfm.exec.newGame(xml)
- system.start = false
- --[[ Player ]]--
- system.displayBar = function(id,player,value,nvalue,color,sig,size,height)
- sig = sig or ""
- size = size or 100
- height = height or 20
- ui.addTextArea(id,"",player,5,(height+8) * id,size + 4,height,0xC7CED2,1,1,true)
- if value ~= 0 then
- ui.addTextArea(id.."0","",player,6,(height+8) * id + 2,nvalue + 2,height - 4,color,color,1,true)
- end
- ui.addTextArea(id.."00","<B><font color='#0'>"..value..sig,player,(size-20)/2,(height+8) * id + 1,50,height,1,1,0,true)
- end
- system.updateBar = function(n)
- local bar = {{0xB73535,19},{0x358CB7,10},{0x35B765,6},{0xB7B735,4}}
- system.displayBar(1,n,(type(info[n].db.aim)=="number" and math.floor(info[n].db.gifts[2]) .. " / "..info[n].db.aim or info[n].db.aim),math.percent(info[n].db.gifts[2],(type(info[n].db.aim)=="number" and info[n].db.aim or 10),100),0xFF0000)
- for i = 1,4 do
- system.displayBar(i+2,n,info[n].db.gifts[1][i],math.percent(info[n].db.gifts[1][i],bar[i][2],50),bar[i][1],"G",50,15)
- end
- end
- eventNewGame = function()
- tfm.exec.addImage("158c1b8aa5a.png","?0",0,0)
- system.start = not system.start
- tfm.exec.setGameTime(120)
- ui.setMapName("<J>#Christmas")
- ui.setShamanName("<R>S4NT4 M4U5")
- for k,v in next,tfm.get.room.playerList do
- --system.loadPlayerData(k)
- info[k] = {
- db = {
- gifts = {{0,0,0,0},0},
- aim = 5,
- titles = {false,false,false},
- enigma = table.random(enigma.words),
- },
- }
- info[k].keyboard = 0
- if not v.isDead then
- system.bindKeyboard(k,32,true,true)
- end
- system.updateBar(k)
- end
- end
- eventPlayerDied = function(n)
- if system.start then
- system.bindKeyboard(n,32,true,false)
- end
- end
- --[[ AI ]]---
- local despawnObjects = {}
- local currentGifts = {}
- local messaged = false
- local gifts = {
- [1] = {
- [1] = "158bb1db61b",
- [2] = 15000,
- };
- [2] = {
- [1] = "158bb1c95e0",
- [2] = 10000,
- };
- [3] = {
- [1] = "158bb1cc6ec",
- [2] = 6000,
- };
- [4] = {
- [1] = "158bb1ce1aa",
- [2] = 3000,
- };
- }
- local giftSequence = {}
- local insertGift = function(k,n)
- for i = 1,k do
- giftSequence[#giftSequence + 1] = n
- end
- end
- insertGift(19,0)
- insertGift(10,1)
- insertGift(6,2)
- insertGift(4,3)
- local noel = {}
- local initx,inity = 450,135
- noel.x = initx
- noel.y = inity
- noel.isEscaping = {0,false}
- noel.isTired[1] = 0
- noel.timers = {
- teleport = 0,
- prize = 0
- }
- noel.img = {
- tired = {"158bb1dccb6","158bb1cf9a8","158bb1d6489","158bb1e2518"},
- right = "158bb1d8069",
- left = "158bb1e0daf",
- flying = "158bb1d470a",
- stop = "158bb1d9b67",
- }
- noel.updateImage = function(img)
- tfm.exec.removeImage(noel.imgId)
- noel.imgId = tfm.exec.addImage(img..".png","#"..noel.id,-23,-32)
- end
- noel.particles = function(id)
- for i = 1,5 do
- tfm.exec.displayParticle(id,noel.x + math.random(-50,50),noel.y + math.random(-50,50),table.random({-.2,.2}),table.random({-.2,.2}))
- end
- end
- noel.move = function(x,y)
- tfm.exec.moveObject(noel.id,0,0,false,x,y,false)
- end
- noel.nearMouse = function(range)
- local player = {"",{dist=math.random(800),x=0,y=0}}
- for k,v in next,tfm.get.room.playerList do
- if not v.isDead then
- if math.pythag(v.x,v.y,noel.x,noel.y,range) then
- local m = v.x-noel.x
- if math.abs(m) < player[2].dist then
- player = {k,{dist=m,x=v.x,y=v.y}}
- end
- end
- end
- end
- noel.isEscaping = player[1] ~= ""
- return player
- end
- noel.escape = function(id)
- local player = noel.nearMouse(80)
- local mul = (player[1] ~= "" and (player[2].dist < 0 and 1 or -1) or table.random({-1,1}))
- local img = (mul < 0 and "left" or "right")
- local rand = 9 - math.random(9)
- if id == 0 or (rand < 6) then
- noel.move(mul * math.random(30,60),0)
- noel.updateImage(noel.img[img])
- elseif id == 1 or (rand < 9) then
- noel.move(mul * math.random(40,50),-80)
- noel.updateImage(table.random({noel.img[img],noel.img.flying}))
- elseif id == 2 or rand == 9 then
- noel.move(mul * math.random(1,5),-math.random(70,100))
- noel.updateImage(noel.img.flying)
- end
- end
- noel.meep = function()
- tfm.exec.displayParticle(20,noel.x,noel.y)
- tfm.exec.explosion(noel.x,noel.y,20,50)
- end
- noel.cannon = function()
- local player = noel.nearMouse(100)
- if player[1] ~= "" then
- local x = noel.x + (noel.x > player[2].x and -40 or 40)
- local y = noel.y + (noel.y > player[2].y and -40 or 40)
- local angle = math.deg(math.atan2(player[2].y-noel.y,player[2].x-noel.x)) + 90
- table.insert(despawnObjects,{
- [1] = tfm.exec.addShamanObject(1703,x,y,angle),
- [2] = os.time() + 3000
- })
- local effect = function(id,sx,sy,xs,ys,e)
- for i = 1,2 do
- tfm.exec.displayParticle(id[i] and id[i] or id[1],x + sx * e,y - sy * e,xs/1.5,ys/1.5)
- end
- end
- for i = 1,20 do
- effect({9,11},math.cos(i),math.sin(i),math.cos(i),-math.sin(i),22)
- effect({13},math.cos(i),math.sin(i),math.sin(i),math.cos(i),19)
- end
- end
- end
- noel.teleport = function()
- if os.time() > noel.timers.teleport then
- noel.timers.teleport = os.time() + 8000
- tfm.exec.displayParticle(37,noel.x,noel.y)
- local x,y = math.random(10,790),math.random(50,300)
- tfm.exec.moveObject(noel.id,x,y)
- tfm.exec.displayParticle(37,x,y)
- else
- noel.escape(2)
- end
- end
- noel.gift = function()
- if os.time() > noel.timers.prize then
- noel.timers.prize = os.time() + 5000
- noel.updateImage(noel.img.stop)
- if #giftSequence > 0 then
- local gift = table.random(giftSequence)
- table.destroy(giftSequence,gift)
- for k,v in next,gifts do
- if gift == (k-1) then
- gift = k
- break
- end
- end
- local gen = {}
- gen[1] = tfm.exec.addShamanObject(6300,noel.x,noel.y)
- gen[2] = os.time() + gifts[gift][2]
- gen[3] = tfm.exec.addImage(gifts[gift][1]..".png","#"..gen[1],-15,-15)
- gen[4] = gift
- table.insert(currentGifts,gen)
- end
- else
- noel.escape(0)
- end
- end
- noel.tired = function(timer)
- if os.time() > noel.timers.prize then
- noel.isTired[1] = os.time() + 8000
- else
- noel.escape(2)
- end
- end
- eventLoop = function(currentTime)
- if system.start and (currentTime/1000)>4 then
- if not messaged then
- messaged = true
- if os.date("%m") == "12" and tonumber(os.date("%d")) >= 18 then
- tfm.exec.snow(60)
- local t = "<V><B>[S4NT4]</B> <R>%s!</R>\n<V><B>[S4NT4]</B> <VP>%s</VP>"
- local l = {
- en = "Merry Christmas",
- fr = "Joyeux Noel",
- br = "Feliz Natal",
- tr = "Mutlu Noeller",
- pl = "Wesołych Świąt",
- hu = "Boldog Karácsonyt",
- ro = "Craciun Fericit",
- ar = "عيد ميلاد سعيد",
- vk = "God Jul",
- nl = "Vrolijk Kerstfeest",
- id = "Selamat Natal",
- de = "Fröhliche Weihnachten",
- ru = "С Рождеством",
- cn = "聖誕快樂",
- ph = "Maligayang Pasko",
- lt = "Linksmų Kalėdų",
- jp = "メリークリスマス",
- fi = "Hyvää Joulua",
- it = "Buon Natale",
- cz = "Veselé Vánoce",
- hr = "Sretan Božić",
- bg = "Весела Коледа",
- lv = "Priecīgus Ziemassvētkus",
- et = "Häid Jõule",
- }
- l.pt = l.br
- local f = l.en
- for k,v in next,l do
- if k == tfm.get.room.community then
- f = v
- break
- end
- end
- for k,v in next,info do
- tfm.exec.chatMessage(t:format(f:upper(),v.db.enigma),k)
- end
- end
- end
- if not noel.id then
- noel.id = tfm.exec.addShamanObject(6300,noel.x,noel.y)
- noel.updateImage(noel.img.stop)
- end
- local ox,oy
- if tfm.get.room.objectList[noel.id] then
- ox,oy = tfm.get.room.objectList[noel.id].x,tfm.get.room.objectList[noel.id].y
- else
- ox,oy = noel.x,noel.y
- end
- if (ox < -10 or ox > 810) or (oy > 400 or oy < -50) then
- tfm.exec.removeObject(noel.id)
- noel.x,noel.y = initx,inity
- noel.id = nil
- end
- if noel.id then
- noel.x = ox
- noel.y = oy
- end
- for k,v in ipairs(despawnObjects) do
- if os.time() > v[2] then
- tfm.exec.removeObject(v[1])
- end
- end
- for k,v in ipairs(currentGifts) do
- if os.time() > v[2] then
- tfm.exec.removeObject(v[1])
- tfm.exec.removeImage(v[3])
- giftSequence[#giftSequence + 1] = math.random(0,1)
- end
- end
- if os.time() > noel.isTired[1] then
- noel.particles(13)
- if math.floor(currentTime/1000) % 24 == 0 then
- noel.tired()
- elseif math.floor(currentTime/1000) % 10 == 0 then
- noel.gift()
- elseif math.floor(currentTime/1000) % 2 == 0 then
- local option = math.random((noel.isEscaping and 15 or 10))
- if option > 3 then
- noel.escape()
- else
- noel.updateImage(noel.img.stop)
- if (currentTime/1000)>7 and math.random(1,2) == 1 then
- if option == 3 then
- noel.cannon()
- elseif option == 2 then
- noel.teleport()
- elseif option == 1 then
- noel.meep()
- end
- end
- end
- else
- noel.updateImage(noel.img.stop)
- end
- else
- noel.particles(1)
- if not noel.isTired[2] then
- noel.isTired[2] = true
- noel.timers.prize = os.time() + 5000
- local imgId = #noel.img.tired
- local animation = {}
- local numb = 1
- animation = system.looping(function()
- noel.updateImage(noel.img.tired[imgId])
- if imgId == #noel.img.tired or imgId == 1 then
- numb = -numb
- end
- imgId = imgId + numb
- if (os.time()+250) > noel.isTired[1] then
- for k,v in next,animation do
- system.removeTimer(v)
- end
- noel.isTired[2] = false
- end
- end,9)
- end
- end
- end
- end
- eventKeyboard = function(n,k,d,x,y)
- if system.start then
- if os.time() > info[n].keyboard then
- if k == 32 then
- if os.time() < noel.isTired[1] then
- if math.pythag(x,y,noel.x,noel.y,32) then
- info[n].db.gifts[2] = info[n].db.gifts[2] + (info[n].db.gifts[1][1]/10) + (info[n].db.gifts[1][2]/10) + (info[n].db.gifts[1][3]/10) + (info[n].db.gifts[1][4]/10)
- info[n].db.gifts[1] = {0,0,0,0}
- if not info[n].db.titles[1] then
- if info[n].db.gifts[2] >= 5 then
- info[n].db.aim = 10
- info[n].db.titles[1] = true
- --system.giveEventGift(n,title[1])
- end
- end
- if not info[n].db.titles[2] then
- if info[n].db.gifts[2] >= 10 then
- info[n].db.aim = "<font letterSpacing='5'>!!!!!!"
- info[n].db.titles[2] = true
- --system.giveEventGift(n,title[2])
- end
- end
- --system.savePlayerData(n,serialization.table.tostring(info[n].db))
- system.updateBar(n)
- end
- else
- for k,v in next,currentGifts do
- local o = tfm.get.room.objectList[v[1]]
- if o and math.pythag(x,y,o.x,o.y,25) then
- local maximum = {19,10,6,4}
- if (info[n].db.gifts[1][v[4]]+v[4]) <= maximum[v[4]] then
- tfm.exec.removeObject(v[1])
- tfm.exec.removeImage(v[3])
- currentGifts[k][2] = 0
- info[n].db.gifts[1][v[4]] = info[n].db.gifts[1][v[4]] + v[4]
- --system.savePlayerData(n,serialization.table.tostring(info[n].db))
- system.updateBar(n)
- break
- end
- end
- end
- end
- end
- info[n].keyboard = os.time() + 1500
- end
- end
- end
- eventChatMessage = function(n,c)
- if os.date("%m") == "12" and tonumber(os.date("%d")) >= 18 then
- if os.time() > noel.isTired[1] then
- if math.pythag(tfm.get.room.playerList[n].x,tfm.get.room.playerList[n].y,noel.x,noel.y,32) then
- enigma.verify(n,c)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement