Guest User

Evilsantah

a guest
Jun 9th, 2014
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.16 KB | None | 0 0
  1. GLITTERS = {0, 1, 2, 9, 11, 13}
  2.  
  3. explosionData = {
  4.     --[[ FORMAT START
  5.     {
  6.         function(trailParticleId,extraParticles,centerX,centerY)
  7.             -- trailParticleId is the particle id from the trail
  8.             -- extraParticles gets passed on from this table to this function
  9.             -- centerX is the center X coordinate from the explosion
  10.             -- centerY ............. Y .............................
  11.             -- do stuff here
  12.         end,
  13.         extraParticles,
  14.         timeBeforeExplosion
  15.     }
  16.     FORMAT END ]]--
  17.     {function(id,p,x,y) -- 2014
  18.         textEffect(id,p,x,y,true,'2014',2)
  19.     end, {0, 2}, 1000},
  20.     {function(id,p,x,y) -- face
  21.         textEffect(id,p,x,y,false,'f',1)
  22.     end, GLITTERS, 1000},
  23.     {function(id,p,x,y) -- beard
  24.         textEffect(id,p,x,y,false,'b',1)
  25.     end, GLITTERS, 1000},
  26.     {function(id,p,x,y) -- drawing
  27.         textEffect(id,p,x,y,false,drawing,1)
  28.     end, GLITTERS, 1000}
  29. }
  30.  
  31. fireworkSets = {
  32.     --[[ FORMAT START
  33.     {
  34.         trailId or {trailId1, trailId2}, -- if it's a number, it will pick that, if it's a table, it will pick a random one
  35.         explosionIndex, -- index in explosionData
  36.         probability
  37.     }
  38.     FORMAT END]]--
  39.     {GLITTERS, 1, 0}, -- face
  40.     {GLITTERS, 2, 0}, -- beard
  41.     {GLITTERS, 3, 0}, -- omo
  42.     {GLITTERS, 4, 0} -- drawing
  43. }
  44.  
  45. ASCII_TABLE = {}
  46.  
  47. ASCII_TABLE[0] = {{0,0}} -- null / unknown
  48.  
  49. players = {}
  50. 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}}
  51. drawers = {Evilsantah=true}
  52.  
  53. mult = 3
  54. width = 24 * mult
  55.  
  56. function eventMouse(n,x,y)
  57.     if drawers[n] then
  58.         x = x - 2
  59.         y = y - 2
  60.         local diffX = x - 400
  61.         local diffY = y - 200
  62.         if diffX >= -width and diffX <= width and diffY >= -width and diffY <= width then
  63.             local p = players[n]
  64.             if p ~= nil then
  65.                 local point = {math.floor(diffX / mult), math.floor(diffY / mult)}
  66.                 local index = #drawing + 1
  67.                 drawing[index] = point
  68.                 addHistoryAction(n, index)
  69.             end
  70.         else
  71.             selectAndFire(x,y,4)
  72.         end
  73.     end
  74. end
  75.  
  76. function velocityEffect(x,y,dx,dy,particles)
  77.     local dist = math.dist(x, y, dx, dy)
  78.     local angle = math.atan2(dy - y, dx - x)
  79.     local vx = dist * math.cos(angle)
  80.     local vy = dist * math.sin(angle)
  81.     local ax = -vx / dist / 15
  82.     local ay = (-vy / dist / 15) + 0.05 -- +0.05 for gravity
  83.     for _,p in ipairs(particles) do
  84.         tfm.exec.displayParticle(p, dx, dy, vx, vy, ax, ay, nil)
  85.     end
  86. end
  87.  
  88. function drawParam1(arg)
  89.     local x,y,a,b,c,d,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6],arg[7]
  90.     local dx,dy,j,k=0,0,3,3
  91.     for t=0,10,0.1 do
  92.         dx=x+(math.cos(a*t)-math.pow(math.cos(b*t),j))*20
  93.         dy=y+(math.sin(c*t)-math.pow(math.sin(d*t),k))*20
  94.         velocityEffect(x,y,dx,dy,particles)
  95.     end
  96. end
  97.  
  98. function drawParam2(arg)
  99.     local x,y,k,a,m,particles=arg[1],arg[2],arg[3],arg[4],arg[5],arg[6]
  100.     local b=a/k
  101.     local dx,dy=0,0
  102.     for t=0,math.pi*4,math.pi/36 do -- step math.pi/18 is every 10 degrees
  103.         dx=x+((a-b)*math.cos(t)+b*math.cos(t*((a/b)-1)))*m
  104.         dy=y+((a-b)*math.sin(t)-b*math.sin(t*((a/b)-1)))*m
  105.         velocityEffect(x,y,dx,dy,particles)
  106.     end
  107. end
  108.  
  109. function roseCurves(arg)
  110.     local x,y,a,n,particles=arg[1],arg[2],arg[3],arg[4],arg[5]
  111.     local dx,dy=0,0
  112.     local intervalTraced = math.pi
  113.     if a % 2 == 0 then
  114.         intervalTraced = math.pi*2
  115.     end
  116.     for t=0,math.pi*4,math.pi/36 do
  117.         --doing sin
  118.         dx=x+a*(math.sin(n*t))*(math.cos(t))
  119.         dy=y+a*(math.sin(n*t))*(math.sin(t))
  120.         velocityEffect(x,y,dx,dy,particles)
  121.     end
  122. end
  123.  
  124. function defaultEffect(id,p,x,y,rand)
  125.     local minDist = 1
  126.     local outerBorder = 20
  127.     local maxDist = 30
  128.     local totalParticles = 75
  129.     for i = 1, totalParticles do
  130.         if rand then
  131.             id = p[math.random(#p)]
  132.         end
  133.         local dist = math.min(math.random(minDist, maxDist), outerBorder)
  134.         local angle = math.random(0, 360)
  135.         local r = math.rad(angle)
  136.         local dx = math.cos(r)
  137.         local dy = math.sin(r)
  138.         local vx = dist * dx / 10
  139.         local vy = dist * dy / 10
  140.         local ax = -vx / dist / 15
  141.         local ay = (-vy / dist / 15) + 0.05
  142.         tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
  143.     end
  144. end
  145.  
  146. function textEffect(id,p,x,y,rand,txt,spread)
  147.     if txt == drawing then
  148.         ASCII_TABLE[string.byte('d')] = txt
  149.         txt = 'd'
  150.     end
  151.     local half = math.floor(#txt / 2)
  152.     local velocitySlowDown = #txt * 6
  153.     local mod2 = #txt % 2
  154.     local widthLetter = 48 -- predefined resolution width of letter (see ASCII_TABLE)
  155.     local shiftX = (1 - mod2) * (widthLetter / 2) -- if #txt is even, we have to shift it half a letter to the right to center it
  156.     local marginBetweenLetters = 5 -- margin between each letter
  157.     -- say if #txt is 4, then loop from -2 to 1
  158.     -- if #txt is 3, then loop from -1 to 1
  159.     for i = -half, half - (1 - mod2) do
  160.         local charIndex = i + half + 1
  161.         local c = txt:sub(charIndex,charIndex)
  162.         local asciiValue = string.byte(c)
  163.         for _,v in pairs(ASCII_TABLE[asciiValue] or ASCII_TABLE[0]) do
  164.             if rand then
  165.                 id = p[math.random(#p)]
  166.             end
  167.             local dx = shiftX + (i * (widthLetter + marginBetweenLetters)) + v[1]
  168.             local dy = v[2]
  169.             local dist = math.sqrt(dy^2 + dx^2) * spread
  170.             local angle = math.atan2(dy, dx)
  171.             local vx = dist * math.cos(angle) / velocitySlowDown
  172.             local vy = dist * math.sin(angle) / velocitySlowDown
  173.             local ax = -vx / dist / 15
  174.             local ay = (-vy / dist / 15) + 0.05 -- +0.05 for gravity
  175.             for j = 1, 3 do
  176.                 tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
  177.             end
  178.         end
  179.     end
  180. end
  181.  
  182. function defaultEffect(id,p,x,y,rand)
  183.     local minDist = 1
  184.     local outerBorder = 20
  185.     local maxDist = 30
  186.     local totalParticles = 75
  187.     for i = 1, totalParticles do
  188.         if rand then
  189.             id = p[math.random(#p)]
  190.         end
  191.         local dist = math.min(math.random(minDist, maxDist), outerBorder)
  192.         local angle = math.random(0, 360)
  193.         local r = math.rad(angle)
  194.         local dx = math.cos(r)
  195.         local dy = math.sin(r)
  196.         local vx = dist * dx / 10
  197.         local vy = dist * dy / 10
  198.         local ax = -vx / dist / 15
  199.         local ay = (-vy / dist / 15) + 0.05
  200.         tfm.exec.displayParticle(id, x + dx, y + dy, vx, vy, ax, ay, nil)
  201.     end
  202. end
  203.  
  204. function firework(id, initX, initY, vx, vy, ax, ay, magnitude, length, explosion)
  205.     local params = nil
  206.     local xMultiplier = 3
  207.     if explosion == nil then
  208.         xMultiplier = 5
  209.     end
  210.     -- Launch firework
  211.     for i = magnitude, 1, -1 do
  212.         local timeT = xMultiplier * (-i / magnitude)
  213.         local velX = timeT * ax + vx
  214.         local velY = timeT * ay + vy
  215.         local x = initX + (velX + vx) / 2 * timeT
  216.         local y = initY + (velY + vy) / 2 * timeT
  217.         if params == nil then
  218.             params = {x, y, velX, velY, ax, ay, id} -- we use these to calculate our explosion position
  219.         end
  220.         for j = 1, magnitude - i do
  221.             tfm.exec.displayParticle(id, x, y, velX, velY, ax, ay, nil)
  222.         end
  223.     end
  224.     if explosion ~= nil then
  225.         --system.newTimer(function(timerId, expl, params)
  226.             -- local tx = expl[3] / (math.pi * 10) -- guesstimation
  227.             local t = explosion[3] / (math.pi * 10)
  228.             local dx = params[3] * t + 0.5 * params[5] * t^2 -- change in x = vxi*changeintime+0.5*ax*t^2
  229.             local x = params[1] + dx
  230.             local dy = params[4] * t + 0.5 * params[6] * t^2 -- change in y = vyi*changeintime+0.5*ay*t^2
  231.             local y = params[2] + dy
  232.  
  233.             local f = explosion[1]
  234.             local particles = explosion[2]
  235.             f(params[7], particles, x, y)
  236.         --  system.removeTimer(timerId)
  237.         --end, math.max(explosion[3], 1000), false, explosion, params)
  238.     end
  239. end
  240.  
  241. function selectAndFire(x, y, setI)
  242.     local vx = 0
  243.     if setI == nil then
  244.         vx = math.random(-3, 3)
  245.         -- calculate a random set based on probabilities
  246.         local total = 0
  247.         for _,s in ipairs(fireworkSets) do
  248.             total = total + s[3]
  249.         end
  250.         local r = math.random(0, total - 1)
  251.         total = 0
  252.         for i,s in ipairs(fireworkSets) do
  253.             total = total + s[3]
  254.             if total > r then
  255.                 setI = i
  256.                 break
  257.             end
  258.         end
  259.     end
  260.     local fireworkSet = fireworkSets[setI] or {GLITTERS, }
  261.     if fireworkSet ~= nil then
  262.         local id = fireworkSet[1]
  263.         if type(id) == 'table' then
  264.             id = id[math.random(#id)]  
  265.         end
  266.         firework(id, x, y, vx, -20, 0, math.random(8, 9) / 10, 5, 30, explosionData[fireworkSet[2]])
  267.     end
  268. end
  269.  
  270. function addHistoryAction(n, ...)
  271.     local p = players[n]
  272.     if p ~= nil then
  273.         p.history[#p.history + 1] = arg
  274.     end
  275. end
  276.  
  277. function undoHistoryAction(n)
  278.     local hist = players[n].history
  279.     if #hist > 0 then
  280.         local action = table.remove(players[n].history, #hist)
  281.         for _,v in ipairs(action) do
  282.             if type(v) == 'number' then
  283.                 -- drawing[v] = nil
  284.                 table.remove(drawing, v)
  285.             else
  286.                 for i = #v, 1, -1 do
  287.                     table.remove(drawing, v[i])
  288.                 end
  289.             end
  290.         end
  291.     end
  292. end
  293.  
  294. function eventKeyboard(n,key,down)
  295.     if drawers[n] then
  296.         if key == 17 then -- ctrl
  297.             players[n].ctrl = down
  298.         elseif key == 8 then -- backspace
  299.             undoHistoryAction(n)
  300.         elseif key == 32 then -- space
  301.             -- print the drawing as lua table
  302.             local str = ''
  303.             for i,v in ipairs(drawing) do
  304.                 str = string.format('%s{%d,%d}', str, v[1], v[2])
  305.                 if i < #drawing then
  306.                     str = str .. ','
  307.                 end
  308.             end
  309.             tfm.exec.chatMessage(string.format('{%s}', str), n)
  310.         elseif key == 46 then -- del
  311.             drawing = {}
  312.         elseif key == 77 then -- M
  313.             -- mirror the current drawing
  314.             local toAdd = {}
  315.             if players[n].ctrl then
  316.                 -- along x axis
  317.                 for _,v in ipairs(drawing) do
  318.                     toAdd[#toAdd + 1] = {v[1], -v[2]}
  319.                 end
  320.             else
  321.                 -- along y axis
  322.                 for _,v in ipairs(drawing) do
  323.                     toAdd[#toAdd + 1] = {-v[1], v[2]}
  324.                 end
  325.             end
  326.             local indices = {}
  327.             for _,v in ipairs(toAdd) do
  328.                 local index = #drawing + 1
  329.                 drawing[index] = v
  330.                 indices[#indices + 1] = index
  331.             end
  332.             addHistoryAction(n, indices)
  333.         end
  334.     end
  335. end
  336.  
  337. function eventLoop(a,b)
  338.     for _,v in ipairs(drawing) do
  339.         local dx = v[1] * mult
  340.         local dy = v[2] * mult
  341.         tfm.exec.displayParticle(0, 400 + dx, 200 + dy, 0, 0, 0, 0, nil)
  342.     end
  343. end
  344.  
  345. function eventNewPlayer(n)
  346.     players[n] = {history = {}, ctrl = false}
  347.     system.bindMouse(n, true)
  348.     tfm.exec.bindKeyboard(n, 17, true, true) -- ctrl down
  349.     tfm.exec.bindKeyboard(n, 17, false, true) -- ctrl up
  350.     tfm.exec.bindKeyboard(n, 8, true, true) -- backspace
  351.     tfm.exec.bindKeyboard(n, 32, true, true) -- space
  352.     tfm.exec.bindKeyboard(n, 46, true, true) -- del
  353.     tfm.exec.bindKeyboard(n, 77, true, true) -- M
  354. end
  355.  
  356. function eventPlayerLeft(n)
  357.     players[n] = nil
  358. end
  359.  
  360. function eventChatCommand(n,m)
  361.     local args = split(m, "%s")
  362.     local text = table.remove(args, 1)
  363.  
  364.     if drawers[n] and text == "add" then
  365.         if #args > 0 then
  366.             drawers[tostring(args[1])] = true
  367.         end
  368.     end
  369. end
  370.  
  371. function main()
  372.     for n in pairs(tfm.get.room.playerList) do
  373.         eventNewPlayer(n)
  374.     end
  375.     tfm.exec.disableAutoTimeLeft(true)
  376.     tfm.exec.disableAutoNewGame(true)
  377.     tfm.exec.disableAllShamanSkills(true)
  378.     tfm.exec.disableAfkDeath(true)
  379. --  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>')
  380.     tfm.exec.newGame('@5110612')
  381. end
  382.  
  383. function split(input, sep)
  384.     local res = {}
  385.     for part in string.gmatch(input, "[^" .. sep .. "]+") do
  386.         table.insert(res, part)
  387.     end
  388.     return res
  389. end
  390.  
  391. main()
Advertisement
Add Comment
Please, Sign In to add comment