Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GLITTERS = {0, 1, 2, 9, 11, 13}
- explosionData = {
- --[[ FORMAT START
- {
- function(trailParticleId,extraParticles,centerX,centerY)
- -- trailParticleId is the particle id from the trail
- -- extraParticles gets passed on from this table to this function
- -- centerX is the center X coordinate from the explosion
- -- centerY ............. Y .............................
- -- do stuff here
- end,
- extraParticles,
- timeBeforeExplosion
- }
- FORMAT END ]]--
- {function(id,p,x,y) -- 2014
- textEffect(id,p,x,y,true,'2014',2)
- end, {0, 2}, 1000},
- {function(id,p,x,y) -- face
- textEffect(id,p,x,y,false,'f',1)
- end, GLITTERS, 1000},
- {function(id,p,x,y) -- beard
- textEffect(id,p,x,y,false,'b',1)
- end, GLITTERS, 1000},
- {function(id,p,x,y) -- drawing
- textEffect(id,p,x,y,false,drawing,1)
- end, GLITTERS, 1000}
- }
- fireworkSets = {
- --[[ FORMAT START
- {
- trailId or {trailId1, trailId2}, -- if it's a number, it will pick that, if it's a table, it will pick a random one
- explosionIndex, -- index in explosionData
- probability
- }
- FORMAT END]]--
- {GLITTERS, 1, 0}, -- face
- {GLITTERS, 2, 0}, -- beard
- {GLITTERS, 3, 0}, -- omo
- {GLITTERS, 4, 0} -- drawing
- }
- ASCII_TABLE = {}
- ASCII_TABLE[0] = {{0,0}} -- null / unknown
- players = {}
- drawing = {{-3,13},{-6,9},{-10,5},{-14,2},{-16,-3},{-15,-8},{-12,-11},{-8,-12},{-4,-11},{3,13},{6,9},{10,5},{14,2},{16,-3},{15,-8},{12,-11},{8,-12},{4,-11},{0,-9},{0,16}}
- drawers = {Evilsantah=true}
- mult = 3
- width = 24 * mult
- function eventMouse(n,x,y)
- if drawers[n] then
- x = x - 2
- y = y - 2
- local diffX = x - 400
- local diffY = y - 200
- if diffX >= -width and diffX <= width and diffY >= -width and diffY <= width then
- local p = players[n]
- if p ~= nil then
- local point = {math.floor(diffX / mult), math.floor(diffY / mult)}
- local index = #drawing + 1
- drawing[index] = point
- addHistoryAction(n, index)
- end
- else
- selectAndFire(x,y,4)
- end
- end
- end
- function velocityEffect(x,y,dx,dy,particles)
- local dist = math.dist(x, y, dx, dy)
- local angle = math.atan2(dy - y, dx - x)
- local vx = dist * math.cos(angle)
- local vy = dist * math.sin(angle)
- local ax = -vx / dist / 15
- local ay = (-vy / dist / 15) + 0.05 -- +0.05 for gravity
- for _,p in ipairs(particles) do
- tfm.exec.displayParticle(p, dx, dy, vx, vy, ax, ay, nil)
- end
- end
- function drawParam1(arg)
- local x,y,a,b,c,d,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7]
- local dx,dy,j,k=0,0,3,3
- for t=0,10,0.1 do
- dx=x+(math.cos(a*t)-math.pow(math.cos(b*t),j))*20
- dy=y+(math.sin(c*t)-math.pow(math.sin(d*t),k))*20
- velocityEffect(x,y,dx,dy,particles)
- end
- end
- function drawParam2(arg)
- local x,y,k,a,m,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]
- local b=a/k
- local dx,dy=0,0
- for t=0,math.pi*4,math.pi/36 do -- step math.pi/18 is every 10 degrees
- dx=x+((a-b)*math.cos(t)+b*math.cos(t*((a/b)-1)))*m
- dy=y+((a-b)*math.sin(t)-b*math.sin(t*((a/b)-1)))*m
- velocityEffect(x,y,dx,dy,particles)
- end
- end
- function roseCurves(arg)
- local x,y,a,n,particles=arg[1],arg[2],arg[3],arg[4],arg[5]
- local dx,dy=0,0
- local intervalTraced = math.pi
- if a % 2 == 0 then
- intervalTraced = math.pi*2
- end
- for t=0,math.pi*4,math.pi/36 do
- --doing sin
- dx=x+a*(math.sin(n*t))*(math.cos(t))
- dy=y+a*(math.sin(n*t))*(math.sin(t))
- velocityEffect(x,y,dx,dy,particles)
- end
- end
- function defaultEffect(id,p,x,y,rand)
- local minDist = 1
- local outerBorder = 20
- local maxDist = 30
- local totalParticles = 75
- for i = 1, totalParticles do
- if rand then
- id = p[math.random(#p)]
- end
- local dist = math.min(math.random(minDist, maxDist), outerBorder)
- local angle = math.random(0, 360)
- local r = math.rad(angle)
- local dx = math.cos(r)
- local dy = math.sin(r)
- local vx = dist * dx / 10
- local vy = dist * dy / 10
- local ax = -vx / dist / 15
- local ay = (-vy / dist / 15) + 0.05
- tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
- end
- end
- function textEffect(id,p,x,y,rand,txt,spread)
- if txt == drawing then
- ASCII_TABLE[string.byte('d')] = txt
- txt = 'd'
- end
- local half = math.floor(#txt / 2)
- local velocitySlowDown = #txt * 6
- local mod2 = #txt % 2
- local widthLetter = 48 -- predefined resolution width of letter (see ASCII_TABLE)
- local shiftX = (1 - mod2) * (widthLetter / 2) -- if #txt is even, we have to shift it half a letter to the right to center it
- local marginBetweenLetters = 5 -- margin between each letter
- -- say if #txt is 4, then loop from -2 to 1
- -- if #txt is 3, then loop from -1 to 1
- for i = -half, half - (1 - mod2) do
- local charIndex = i + half + 1
- local c = txt:sub(charIndex,charIndex)
- local asciiValue = string.byte(c)
- for _,v in pairs(ASCII_TABLE[asciiValue] or ASCII_TABLE[0]) do
- if rand then
- id = p[math.random(#p)]
- end
- local dx = shiftX + (i * (widthLetter + marginBetweenLetters)) + v[1]
- local dy = v[2]
- local dist = math.sqrt(dy^2 + dx^2) * spread
- local angle = math.atan2(dy, dx)
- local vx = dist * math.cos(angle) / velocitySlowDown
- local vy = dist * math.sin(angle) / velocitySlowDown
- local ax = -vx / dist / 15
- local ay = (-vy / dist / 15) + 0.05 -- +0.05 for gravity
- for j = 1, 3 do
- tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
- end
- end
- end
- end
- function defaultEffect(id,p,x,y,rand)
- local minDist = 1
- local outerBorder = 20
- local maxDist = 30
- local totalParticles = 75
- for i = 1, totalParticles do
- if rand then
- id = p[math.random(#p)]
- end
- local dist = math.min(math.random(minDist, maxDist), outerBorder)
- local angle = math.random(0, 360)
- local r = math.rad(angle)
- local dx = math.cos(r)
- local dy = math.sin(r)
- local vx = dist * dx / 10
- local vy = dist * dy / 10
- local ax = -vx / dist / 15
- local ay = (-vy / dist / 15) + 0.05
- tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
- end
- end
- function firework(id, initX, initY, vx, vy, ax, ay, magnitude, length, explosion)
- local params = nil
- local xMultiplier = 3
- if explosion == nil then
- xMultiplier = 5
- end
- -- Launch firework
- for i = magnitude, 1, -1 do
- local timeT = xMultiplier * (-i / magnitude)
- local velX = timeT * ax + vx
- local velY = timeT * ay + vy
- local x = initX + (velX + vx) / 2 * timeT
- local y = initY + (velY + vy) / 2 * timeT
- if params == nil then
- params = {x, y, velX, velY, ax, ay, id} -- we use these to calculate our explosion position
- end
- for j = 1, magnitude - i do
- tfm.exec.displayParticle(id, x, y, velX, velY, ax, ay, nil)
- end
- end
- if explosion ~= nil then
- --system.newTimer(function(timerId, expl, params)
- -- local tx = expl[3] / (math.pi * 10) -- guesstimation
- local t = explosion[3] / (math.pi * 10)
- local dx = params[3] * t + 0.5 * params[5] * t^2 -- change in x = vxi*changeintime+0.5*ax*t^2
- local x = params[1] + dx
- local dy = params[4] * t + 0.5 * params[6] * t^2 -- change in y = vyi*changeintime+0.5*ay*t^2
- local y = params[2] + dy
- local f = explosion[1]
- local particles = explosion[2]
- f(params[7], particles, x, y)
- -- system.removeTimer(timerId)
- --end, math.max(explosion[3], 1000), false, explosion, params)
- end
- end
- function selectAndFire(x, y, setI)
- local vx = 0
- if setI == nil then
- vx = math.random(-3, 3)
- -- calculate a random set based on probabilities
- local total = 0
- for _,s in ipairs(fireworkSets) do
- total = total + s[3]
- end
- local r = math.random(0, total - 1)
- total = 0
- for i,s in ipairs(fireworkSets) do
- total = total + s[3]
- if total > r then
- setI = i
- break
- end
- end
- end
- local fireworkSet = fireworkSets[setI] or {GLITTERS, }
- if fireworkSet ~= nil then
- local id = fireworkSet[1]
- if type(id) == 'table' then
- id = id[math.random(#id)]
- end
- firework(id, x, y, vx, -20, 0, math.random(8, 9) / 10, 5, 30, explosionData[fireworkSet[2]])
- end
- end
- function addHistoryAction(n, ...)
- local p = players[n]
- if p ~= nil then
- p.history[#p.history + 1] = arg
- end
- end
- function undoHistoryAction(n)
- local hist = players[n].history
- if #hist > 0 then
- local action = table.remove(players[n].history, #hist)
- for _,v in ipairs(action) do
- if type(v) == 'number' then
- -- drawing[v] = nil
- table.remove(drawing, v)
- else
- for i = #v, 1, -1 do
- table.remove(drawing, v[i])
- end
- end
- end
- end
- end
- function eventKeyboard(n,key,down)
- if drawers[n] then
- if key == 17 then -- ctrl
- players[n].ctrl = down
- elseif key == 8 then -- backspace
- undoHistoryAction(n)
- elseif key == 32 then -- space
- -- print the drawing as lua table
- local str = ''
- for i,v in ipairs(drawing) do
- str = string.format('%s{%d,%d}', str, v[1], v[2])
- if i < #drawing then
- str = str .. ','
- end
- end
- tfm.exec.chatMessage(string.format('{%s}', str), n)
- elseif key == 46 then -- del
- drawing = {}
- elseif key == 77 then -- M
- -- mirror the current drawing
- local toAdd = {}
- if players[n].ctrl then
- -- along x axis
- for _,v in ipairs(drawing) do
- toAdd[#toAdd + 1] = {v[1], -v[2]}
- end
- else
- -- along y axis
- for _,v in ipairs(drawing) do
- toAdd[#toAdd + 1] = {-v[1], v[2]}
- end
- end
- local indices = {}
- for _,v in ipairs(toAdd) do
- local index = #drawing + 1
- drawing[index] = v
- indices[#indices + 1] = index
- end
- addHistoryAction(n, indices)
- end
- end
- end
- function eventLoop(a,b)
- for _,v in ipairs(drawing) do
- local dx = v[1] * mult
- local dy = v[2] * mult
- tfm.exec.displayParticle(0, 400 + dx, 200 + dy, 0, 0, 0, 0, nil)
- end
- end
- function eventNewPlayer(n)
- players[n] = {history = {}, ctrl = false}
- system.bindMouse(n, true)
- tfm.exec.bindKeyboard(n, 17, true, true) -- ctrl down
- tfm.exec.bindKeyboard(n, 17, false, true) -- ctrl up
- tfm.exec.bindKeyboard(n, 8, true, true) -- backspace
- tfm.exec.bindKeyboard(n, 32, true, true) -- space
- tfm.exec.bindKeyboard(n, 46, true, true) -- del
- tfm.exec.bindKeyboard(n, 77, true, true) -- M
- end
- function eventPlayerLeft(n)
- players[n] = nil
- end
- function eventChatCommand(n,m)
- local args = split(m, "%s")
- local text = table.remove(args, 1)
- if drawers[n] and text == "add" then
- if #args > 0 then
- drawers[tostring(args[1])] = true
- end
- end
- end
- function main()
- for n in pairs(tfm.get.room.playerList) do
- eventNewPlayer(n)
- end
- tfm.exec.disableAutoTimeLeft(true)
- tfm.exec.disableAutoNewGame(true)
- tfm.exec.disableAllShamanSkills(true)
- tfm.exec.disableAfkDeath(true)
- -- tfm.exec.newGame('<C><P /><Z><S><S L="740" Y="400" P="0,0,0.3,0.2,0,0,0,0" T="0" H="43" X="400" /><S o="324650" L="10" Y="200" P="0,0,0.3,0.2,0,0,0,0" T="12" X="322" H="166" /><S o="324650" L="10" Y="200" P="0,0,0.3,0.2,0,0,0,0" T="12" X="477" H="166" /><S o="324650" L="10" Y="122" P="0,0,0.3,0.2,90,0,0,0" T="12" X="400" H="166" /><S o="324650" L="10" Y="277" P="0,0,0.3,0.2,90,0,0,0" T="12" X="400" H="166" /></S><D><DS X="398" Y="356" /></D><O /></Z></C>')
- tfm.exec.newGame('@5110612')
- end
- function split(input, sep)
- local res = {}
- for part in string.gmatch(input, "[^" .. sep .. "]+") do
- table.insert(res, part)
- end
- return res
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment