Advertisement
LuaWeaver

RainbowStaff

May 19th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.94 KB | None | 0 0
  1. --this uses really old code of mine
  2. --don't judge
  3.  
  4. oc=oc or function(f) return f end
  5.  
  6. --SETUP VARIABLES
  7.  
  8. local plr=game.Players.LocalPlayer
  9. local char=plr.Character
  10. local mouse=plr:GetMouse()
  11. Instance.new("BlockMesh",char.HumanoidRootPart).Scale=Vector3.new(0,0,0)
  12.  
  13. local mouseDown=false
  14.  
  15. mouse.Button1Down:connect(oc(function()
  16.     mouseDown=true
  17. end))
  18. mouse.Button1Up:connect(oc(function()
  19.     mouseDown=false
  20. end))
  21.  
  22. --START WELD/ANIMATION CODE
  23.  
  24. local function getRelative(v1,v2)
  25.     return v1*(v2-(v2.p*2)):inverse()*CFrame.new():inverse()
  26. end
  27.  
  28. weld={
  29.     prep=function(armstr)
  30.         local n=armstr=="Left" and -1 or 1
  31.         local arm=char[armstr.." Arm"]
  32.         local torso=char.Torso
  33.         local startcf=torso.CFrame
  34.         torso.CFrame=CFrame.new()
  35.         local shoulder=torso[armstr.." Shoulder"]
  36.         local newp=Instance.new("Part",char)
  37.         newp.FormFactor="Custom"
  38.         newp.Size=Vector3.new(1,1,1)
  39.         newp.Transparency=1
  40.         newp.Name=armstr.."Part"
  41.         Instance.new("BlockMesh",newp).Scale=Vector3.new(0,0,0)
  42.         local weld=Instance.new("Weld",torso)
  43.         weld.C0=CFrame.new(1.5*n,0.5,0)
  44.         Instance.new("CFrameValue",weld).Value=CFrame.new(1.5*n,0.499,0)
  45.         weld.Part0=torso
  46.         weld.Part1=newp
  47.         local weld2=Instance.new("Weld",arm)
  48.         weld2.C0=CFrame.new(0,0.5,0)
  49.         weld2.Part0=arm
  50.         weld2.Part1=newp
  51.         _G[armstr.."SH"]=shoulder
  52.         _G[armstr.."W"]=weld
  53.         torso.CFrame=startcf
  54.         shoulder:remove()
  55.         return weld
  56.     end,
  57.  
  58.     rotate=function(arm,x,y,z)
  59.         arm.C0=CFrame.new(arm.C0.p)*CFrame.Angles(x,y,z)
  60.     end,
  61.  
  62.     position=function(arm,x,y,z)
  63.         arm.C0=(arm.Value.Value+Vector3.new(x,y,z))*(arm.C0-arm.C0.p)
  64.     end,
  65.  
  66.     rotateA=function(arm,x,y,z) --rotateAppend
  67.         arm.C0=arm.C0*CFrame.Angles(x,y,z)
  68.     end,
  69.  
  70.     positionA=function(arm,x,y,z) --positionAppend
  71.         arm.C0=arm.C0+Vector3.new(x,y,z)
  72.     end,
  73.  
  74.     remove=function(armstr)
  75.         char[armstr.."Part"]:remove()
  76.         local torso=char.Torso
  77.         _G[armstr.."W"]:remove()
  78.         _G[armstr.."SH"].Parent=torso
  79.     end,
  80.  
  81.     gWeld=function(p0,p1,c0) --generalWeld
  82.         p1.CFrame=getRelative(p0.CFrame,c0)
  83.         local w=Instance.new("Weld",p0)
  84.         w.Part0=p0
  85.         w.Part1=p1
  86.         w.C0=c0
  87.         return w
  88.     end
  89. }
  90.  
  91. --START BLOCKY EFFECT THINGY CODE
  92.  
  93. local blockFx={}
  94.  
  95. do
  96.     local function randAng()
  97.         local deg=math.pi/180
  98.         return CFrame.Angles(math.random(-deg*18000,deg*18000)/100,math.random(-deg*18000,deg*18000)/100,math.random(-deg*18000,deg*18000)/100)
  99.     end
  100.  
  101.     function blockFx.create(num,size,prop)
  102.         local realSize=Instance.new("Part")
  103.         realSize.FormFactor="Custom"
  104.         realSize.Size=Vector3.new(size,size,size)
  105.         realSize.Name="Real"
  106.  
  107.         local vel=Instance.new("BodyForce",realSize)
  108.         vel.force=Vector3.new(0,196.2*(size^3+(num-1)),0)
  109.  
  110.         for i,v in pairs(prop) do
  111.             realSize[i]=(type(v)=="function" and func(v) or v)
  112.         end
  113.         local model=Instance.new("Model")
  114.         realSize.Parent=model
  115.         local mass=realSize:GetMass()
  116.         for i=1,num-1 do
  117.             local p=Instance.new("Part")
  118.             p.CanCollide=false
  119.             p.FormFactor="Custom"
  120.             p.Size=Vector3.new(1,1,1)
  121.             mass=mass+p:GetMass()
  122.             p.Parent=model
  123.             weld.gWeld(realSize,p,CFrame.new())
  124.             Instance.new("BlockMesh",p).Scale=Vector3.new(size,size,size) -- Better performance.
  125.         end
  126.         print(mass,size^3+(num-1))
  127.  
  128.         local tab={}
  129.  
  130.         tab.onTouch=function() end
  131.  
  132.         tab.spinning=false
  133.         function tab:startSpin()
  134.             self.spinning=true
  135.             coroutine.resume(self.spinCoroutine)
  136.         end
  137.         function tab:stopSpin()
  138.             self.spinning=false
  139.         end
  140.         tab.spinCoroutine=coroutine.create(function()
  141.             while wait() do
  142.                 if not tab.spinning then
  143.                     coroutine.yield()
  144.                 end
  145.                 tab:updateSpin()
  146.             end
  147.         end)
  148.  
  149.         function tab:children()
  150.             return model:children()
  151.         end
  152.  
  153.         function tab:updateSpin()
  154.             --self.Real.CFrame=self.Real.CFrame*randAng()
  155.             for i,v in pairs(self.Real:children()) do
  156.                 if v:IsA("Weld") then -- Never too safe.
  157.                     v.C1=v.C1*randAng()
  158.                 end
  159.             end
  160.         end
  161.  
  162.         function tab:reprop(k,v)
  163.             for _,p in pairs(self:children()) do
  164.                 if p:IsA("BasePart") then
  165.                     p[k]=v
  166.                 end
  167.             end
  168.         end
  169.  
  170.         function tab:move(cf)
  171.             self:reprop("CFrame",cf)
  172.             self:updateSpin()
  173.         end
  174.  
  175.         function tab:addVelocity(vector)
  176.             local mass=size^3+(num-1)
  177.             vel.force=vel.force+(vector*self:getMass())
  178.         end
  179.  
  180.         function tab:remove()
  181.             model:remove()
  182.         end
  183.  
  184.         function tab:getMass()
  185.             return size^3+(num-1)
  186.         end
  187.  
  188.         model.Real.Touched:connect(oc(function(...)
  189.             if tab.onTouch then
  190.                 oc(tab.onTouch(...))
  191.             end
  192.         end))
  193.  
  194.         return setmetatable(tab,{__index=model,__newindex=model})
  195.     end
  196. end
  197.  
  198. --GP FUNCTIONS
  199.  
  200. function add(t,...)
  201.     for _,v in pairs({...}) do
  202.         game:service("Debris"):AddItem(v,t)
  203.     end
  204. end
  205.  
  206. local staffBody=Instance.new("Part")
  207. staffBody.Name="Staff"
  208. staffBody.FormFactor="Custom"
  209. staffBody.Size=Vector3.new(0.2,0.2,5)
  210. staffBody.Parent=char
  211. staffBody.CFrame=CFrame.new(0,15,0)
  212. staffBody.CanCollide=false
  213. weld.gWeld(char["Right Arm"],staffBody,CFrame.new(0,-1,1))
  214. Instance.new("BlockMesh",staffTip)
  215.  
  216. local staffTip=Instance.new("Part")
  217. staffTip.Anchored=false
  218. staffTip.Name="StaffTip"
  219. staffTip.FormFactor="Custom"
  220. staffTip.Size=Vector3.new(0.4,0.4,0.4)
  221. staffTip.Parent=char
  222. staffTip.CFrame=CFrame.new(0,30,0)
  223. staffTip.CanCollide=false
  224. Instance.new("BlockMesh",staffTip)
  225. local tipWeld=weld.gWeld(staffBody,staffTip,CFrame.new(0,0,-3))
  226. local tipSparkles=Instance.new("Sparkles",staffTip)
  227.  
  228. coroutine.resume(coroutine.create(function()
  229.     while true do
  230.         char.HumanoidRootPart.Transparency=1
  231.         tipWeld.C0=tipWeld.C0*CFrame.Angles(0,0,math.pi*wait(1/60))
  232.         tipSparkles.SparkleColor=BrickColor.random().Color
  233.         if char:findFirstChild("RightPart") then
  234.             --char["RightPart"].Transparency=1
  235.         end
  236.     end
  237. end))
  238.  
  239. local armWeld
  240.  
  241. local function shiftPos(v)
  242.     if v==1 then
  243.         armWeld=weld.prep("Right")
  244.         weld.rotate(armWeld,0,0,0)
  245.         for i=0,math.pi/2,math.pi/22.25 do
  246.             weld.rotate(armWeld,i,0,0)
  247.             wait(1/60)
  248.         end
  249.         weld.rotate(armWeld,math.pi/2,0,0)
  250.     elseif v==0 then
  251.         for i=0,math.pi/2,math.pi/22.25 do
  252.             weld.rotate(armWeld,math.pi/2-i,0,0)
  253.             wait(1/60)
  254.         end
  255.         weld.rotate(armWeld,0,0,0)
  256.         weld.remove("Right")
  257.     end
  258. end
  259.  
  260. local function playSound(id)
  261.     local s=Instance.new("Sound",workspace)
  262.     s.SoundId="http://www.roblox.com/asset/?id="..id
  263.     s.Volume=1
  264.     s:Play()
  265. end
  266.  
  267. local function remSparklesFromChar(cha)
  268.     local function r(o)
  269.         for i,v in pairs(o:children()) do
  270.             if v:IsA("Sparkles") and v~=tipSparkles then
  271.                 v:Destroy()
  272.             end
  273.             r(v)
  274.         end
  275.     end
  276.     r(cha)
  277. end
  278.  
  279. local function sparkleTeleport(cha)
  280.     for t=0,1,0.05 do
  281.         for i,v in pairs(cha:children()) do
  282.             if v:IsA("Hat") then
  283.                 for _i,_v in pairs(v:children()) do
  284.                     if _v:IsA("BasePart") then
  285.                         _v.Transparency=t
  286.                         Instance.new("Sparkles",_v).SparkleColor=BrickColor.random().Color
  287.                     end
  288.                 end
  289.             elseif v:IsA("BasePart") and v~=staffBody and v~=staffTip then
  290.                 v.Transparency=t
  291.                 Instance.new("Sparkles",v).SparkleColor=BrickColor.random().Color
  292.             elseif v:IsA("BasePart") and v~=cha.HumanoidRootPart then
  293.                 v.Transparency=t
  294.             end
  295.         end
  296.         wait()
  297.     end
  298.     return function(point)
  299.         cha.Torso.CFrame=CFrame.new(point)*(cha.Torso.CFrame-cha.Torso.CFrame.p)+Vector3.new(0,2,0)
  300.         for t=0,1,0.05 do
  301.             for i,v in pairs(cha:children()) do
  302.                 if v:IsA("Hat") then
  303.                     for _i,_v in pairs(v:children()) do
  304.                         if _v:IsA("BasePart") then
  305.                             _v.Transparency=0.95-t
  306.                             _v.Sparkles:remove()
  307.                         end
  308.                     end
  309.                 elseif v:IsA("BasePart") and v~=staffBody and v~=staffTip and v~=char.HumanoidRootPart then
  310.                     v.Transparency=0.95-t
  311.                     v.Sparkles:remove()
  312.                 elseif v:IsA("BasePart") and v~=cha.HumanoidRootPart then
  313.                     v.Transparency=0.95-t
  314.                 end
  315.             end
  316.             wait()
  317.         end
  318.         remSparklesFromChar(cha)
  319.     end
  320. end
  321.  
  322. local spelldata={z={}}
  323.  
  324. local nondebouncedListeners={
  325.     z=function()
  326.         if spelldata.z.targetHuman and spelldata.z.targetHuman.Parent and spelldata.z.targetHuman.Parent:findFirstChild("Torso") then
  327.             local targ=spelldata.z.targetHuman.Parent
  328.             remSparklesFromChar(targ)
  329.             local p1=char.Torso.CFrame.p
  330.             local p2=targ.Torso.CFrame.p
  331.             wait(.1)
  332.             coroutine.resume(coroutine.create(function()
  333.                 local f=sparkleTeleport(char)
  334.                 char.Torso.CFrame=CFrame.new(p2)
  335.                 f(p2)
  336.             end))
  337.             coroutine.resume(coroutine.create(function()
  338.                 local f=sparkleTeleport(targ)
  339.                 targ.Torso.CFrame=CFrame.new(p1)
  340.                 f(p1)
  341.             end))
  342.  
  343.             spelldata.z.targetHuman=nil
  344.         elseif mouse.Target and mouse.Target.Parent:findFirstChild("Humanoid") and mouse.Target.Parent:findFirstChild("Torso") then
  345.             spelldata.z.targetHuman=mouse.Target.Parent.Humanoid
  346.             for i=1,15 do
  347.                 Instance.new("Sparkles",mouse.Target.Parent.Torso).SparkleColor=BrickColor.random().Color
  348.             end
  349.             mouse.Target.Parent.Humanoid.Died:connect(function()
  350.                 spelldata.z.targetHuman=nil
  351.             end)
  352.         end
  353.     end
  354. }
  355.  
  356. local spells={
  357.     q=function()
  358.         for i=1,5 do
  359.             weld.rotateA(armWeld,math.pi/90,0,0)
  360.             wait(1/60)
  361.         end
  362.  
  363.         local cOff=CFrame.new(0,0,-0.8)
  364.         local function getDesired()
  365.             return getRelative(staffTip.CFrame,cOff)
  366.         end
  367.  
  368.         local mod=blockFx.create(5,0.95,{})
  369.         local mWeld=weld.gWeld(staffTip,mod.Real,cOff)
  370.         mod.Parent=char
  371.         mod:startSpin()
  372.         mod:reprop("CanCollide",false)
  373.         mod:reprop("Transparency",0.95)
  374.         for i,v in pairs(mod:children()) do
  375.             v.BrickColor=BrickColor.random()
  376.             for _=1,10 do
  377.                 Instance.new("Sparkles",v).SparkleColor=BrickColor.random().Color
  378.             end
  379.         end
  380.  
  381.         mouse.Button1Down:wait()
  382.  
  383.         playSound(132890538)
  384.  
  385.         for i=1,5 do
  386.             weld.rotateA(armWeld,math.pi/90,0,0)
  387.             wait(1/60)
  388.         end
  389.  
  390.         local done=false
  391.         local force=(mouse.Hit.p-getDesired().p).unit*360
  392.  
  393.         mWeld:Destroy()
  394.         mod:move(getDesired())
  395.  
  396.         mod:addVelocity(force)
  397.  
  398.         local function rem()
  399.             local x=Instance.new("Explosion")
  400.             x.BlastPressure=0
  401.             x.BlastRadius=8
  402.             x.Position=mod.Real.Position
  403.             local hitHums={}
  404.             x.Hit:connect(function(p,d)
  405.                 if p.Parent:findFirstChild("Humanoid") and not hitHums[p.Parent:findFirstChild("Humanoid")] then
  406.                     hitHums[p.Parent.Humanoid]=true
  407.                     p.Parent.Humanoid:TakeDamage(100-(d*20)>70 and 70 or (100-d*20<10 and 10 or 100-d*20))
  408.                 end
  409.             end)
  410.             x.Parent=workspace
  411.             mod:remove()
  412.             mod:stopSpin()
  413.         end
  414.  
  415.         mod.onTouch=function(p)
  416.             if p.Parent~=char and p.Parent.Parent~=char then
  417.                 rem()
  418.                 done=true
  419.             end
  420.         end
  421.  
  422.         coroutine.resume(coroutine.create(function()
  423.             local timer=0
  424.             repeat mod:reprop("Velocity",force) timer=timer+wait() until done or timer>4
  425.             rem()
  426.         end))
  427.  
  428.         wait(0.5)
  429.  
  430.         for i=1,10 do
  431.             weld.rotateA(armWeld,-math.pi/90,0,0)
  432.             wait(1/60)
  433.         end
  434.     end,
  435.     e=function()
  436.         local time=0.4
  437.         local start=tick()
  438.         coroutine.resume(coroutine.create(function() while true do
  439.             local p=(tick()-start)/time
  440.             p=math.min(1,p)
  441.             staffTip.Mesh.Scale=Vector3.new(p*0.5+1,p*0.5+1,p*0.5+1)
  442.             wait(1/60)
  443.             if p==1 then
  444.                 break
  445.             end
  446.         end end))
  447.  
  448.         for i=1,5 do
  449.             weld.rotateA(armWeld,math.pi/90,0,0)
  450.             wait(1/60)
  451.         end
  452.  
  453.         wait(.1)
  454.  
  455.         local done
  456.  
  457.         mouse.KeyDown:connect(function(k)
  458.             if k=="e" then
  459.                 done=true
  460.             end
  461.         end)
  462.  
  463.         local drawPart=Instance.new("Part")
  464.         drawPart.FormFactor="Custom"
  465.         drawPart.Anchored=true
  466.         drawPart.CanCollide=false
  467.         local sparklePart=Instance.new("Part")
  468.         sparklePart.Transparency=1
  469.         sparklePart.Anchored=true
  470.         sparklePart.CanCollide=false
  471.         for i=1,10 do
  472.             Instance.new("Sparkles",sparklePart).SparkleColor=BrickColor.random().Color
  473.         end
  474.  
  475.         repeat
  476.             wait(1/60)
  477.             if mouseDown then
  478.                 local downPoint=mouse.Hit.p
  479.                 drawPart.Size=Vector3.new(0.2,0.2,(staffTip.Position-downPoint).magnitude)
  480.                 drawPart.CFrame=CFrame.new((staffTip.Position+downPoint)/2,downPoint)
  481.                 sparklePart.CFrame=CFrame.new(downPoint)
  482.                 local _sparklePart=sparklePart:clone()
  483.                 _sparklePart.CFrame=CFrame.new(downPoint)
  484.                 _sparklePart.Parent=char
  485.                 add(2,_sparklePart)
  486.                 drawPart.Parent=char
  487.  
  488.                 if mouse.Target and mouse.Target.Parent:findFirstChild("Humanoid") then
  489.                     mouse.Target.Parent.Humanoid:TakeDamage(1.5)
  490.                 end
  491.             else
  492.                 sparklePart.Parent=nil
  493.                 drawPart.Parent=nil
  494.             end
  495.         until done
  496.        
  497.         local start=tick()
  498.         coroutine.resume(coroutine.create(function() while true do
  499.             local p=(tick()-start)/time
  500.             p=math.min(1,p)
  501.             staffTip.Mesh.Scale=Vector3.new(1.5-p*0.5,1.5-p*0.5,1.5-p*0.5)
  502.             wait(1/60) 
  503.             if p==1 then   
  504.                 break
  505.             end
  506.         end end))
  507.  
  508.         for i=1,5 do
  509.             weld.rotateA(armWeld,-math.pi/90,0,0)
  510.             wait(1/60)
  511.         end
  512.     end,
  513.     r=function()
  514.         coroutine.resume(coroutine.create(function()
  515.             for i=1,5 do
  516.                 weld.rotateA(armWeld,math.pi/90,0,0)
  517.                 wait(1/60)
  518.             end
  519.         end))
  520.         local finish=sparkleTeleport(char)
  521.         wait(.75)
  522.         mouse.Button1Down:wait()
  523.         finish(mouse.Hit.p)
  524.         for i=1,5 do
  525.             weld.rotateA(armWeld,-math.pi/90,0,0)
  526.             wait(1/60)
  527.         end
  528.     end
  529. }
  530.  
  531. mouse.KeyDown:connect(oc(function(k)
  532.     if nondebouncedListeners[k] and out==1 then
  533.         nondebouncedListeners[k]()
  534.     elseif spells[k] and not db and out==1 then
  535.         db=true
  536.         spells[k]()
  537.         db=false
  538.     elseif k=="z" and not db then
  539.         db=true
  540.         shiftPos(out==1 and 0 or 1)
  541.         out=out==1 and 0 or 1
  542.         db=false
  543.     end
  544. end))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement