Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------This is an Official script from Duelist--------------------------
- ---{-------------------- -------------------}---
- ---{-------------------- / \ -------------------}---
- ---{-------------------- II -------------------}---
- ---{-------------------- II -------------------}---
- ---{-------------------- II -------------------}---
- ---{-------------------- A========A -------------------}---
- ---{-------------------- II -------------------}---
- ---{-------------------- II -------------------}---
- ---{-------------------- W -------------------}---
- -------------------------------------------------------------------------------------------------------------
- -- @author Quenty
- -- Stick this guy in the StarterGui...
- local Players = game:GetService("Players")
- --Players.LocalPlayer.CameraMode = "Classic"
- --Players.LocalPlayer.CameraMode = "LockFirstPerson"
- -- You can use this to make it fall a lot...
- local Configuration = {
- SnowModelName = "ThatSnowRenderModel";
- SnowColor = Vector3.new(1, 1, 1);
- SmallestFlakeSize = 8;-- Divided by 100
- LargestFlakeSize = 15;
- MaxMoveX = 5; -- Divided by 100
- MinMoveX = -5;
- MaxMoveY = 1;
- MinMoveY = -12;
- MaxMoveZ = 5;
- MinMoveZ = -5;
- CyclesPerLifeMax = 4;
- CyclesPerLifeMin = 2;
- CycleLife = 20;
- MaxTransparency = 0.3;
- RangeX = 8;
- RangeY = 4;
- RangeZ = 8;
- -- QUICK EDITING STUFF HERE
- SnowAmountFactor = 3; -- Snowflakes made every frame. Double this, double lag, more snowflakes!
- }
- local function GetSnowModel()
- local Model = workspace:FindFirstChild(Configuration.SnowModelName)
- if not Model then
- Model = Instance.new("Camera", workspace)
- Model.Name = Configuration.SnowModelName
- Model.Archivable = false;
- end
- return Model
- end
- local function GetSnowflakeMovement()
- return Vector3.new(
- math.random(Configuration.MinMoveX, Configuration.MaxMoveX)/100,
- math.random(Configuration.MinMoveY, Configuration.MaxMoveY)/100,
- math.random(Configuration.MinMoveZ, Configuration.MaxMoveZ)/100
- )
- end
- local function GetRandomSnowflakePosition(LastValidPlace) --, CoordinateFrame)
- --[[return CFrame.new(LastValidPlace + Vector3.new(
- math.random(-Configuration.RangeX, Configuration.RangeX),
- math.random(-3, Configuration.RangeY),
- math.random(-Configuration.RangeZ, Configuration.RangeZ)
- ) + Players.LocalPlayer.Character.Torso.CFrame.lookVector * 2)--]]
- return CFrame.new() + LastValidPlace:pointToWorldSpace(Vector3.new(
- math.random(-Configuration.RangeX, Configuration.RangeX),
- math.random(-3, Configuration.RangeY),
- math.random(-Configuration.RangeZ*2, 0)))
- end
- local SnowflakeQueue = {}
- local function UpdateQueue()
- local HalfLife = Configuration.CycleLife;
- local MaxTransparency = Configuration.MaxTransparency
- --for Index, SnowFlake in pairs(SnowflakeQueue) do
- local Index = 1
- while Index <= #SnowflakeQueue do
- local SnowFlake = SnowflakeQueue[Index]
- local CycleTick = SnowFlake.CycleTick
- local Flake = SnowFlake.Flake
- if SnowFlake.Mode == 2 then
- SnowFlake.CyclesLeft = SnowFlake.CyclesLeft - 1
- if SnowFlake.CyclesLeft <= 0 then
- SnowFlake.Flake:Destroy()
- table.remove(SnowflakeQueue, Index)
- else
- SnowFlake.CycleTick = Configuration.CycleLife
- SnowFlake.Mode = 0
- Index = Index + 1
- end
- elseif SnowFlake.Mode == 0 then
- Flake.Transparency = (CycleTick/HalfLife)* MaxTransparency + (MaxTransparency)
- Flake.CFrame = Flake.CFrame + SnowFlake.MoveRate
- SnowFlake.CycleTick = CycleTick - 1
- if SnowFlake.CycleTick <= 0 then
- SnowFlake.Mode = 1
- end
- Index = Index + 1
- elseif SnowFlake.Mode == 1 then
- Flake.Transparency = (CycleTick/HalfLife)*MaxTransparency + (MaxTransparency)
- Flake.CFrame = Flake.CFrame + SnowFlake.MoveRate
- SnowFlake.CycleTick = CycleTick + 1
- if SnowFlake.CycleTick >= HalfLife then
- SnowFlake.Mode = 2
- end
- Index = Index + 1
- end
- end
- end
- local function MakeSnowFlake(Parent, InitialCFrame)
- local FlakeSize = math.random(Configuration.SmallestFlakeSize, Configuration.LargestFlakeSize)/100
- local Flake = Instance.new("Part", Parent)
- Flake.Anchored = true;
- Flake.CanCollide = false;
- Flake.FormFactor = "Custom";
- Flake.Size = Vector3.new(1, 1, 1)
- Flake.Name = "SnowFlake";
- Flake.BottomSurface = "Smooth";
- Flake.CFrame = InitialCFrame
- Flake.Transparency = 1;
- local Mesh = Instance.new("SpecialMesh", Flake)
- Mesh.MeshType = "FileMesh"
- Mesh.MeshId = "http://www.roblox.com/asset/?id=1185246"
- Mesh.TextureId = "http://www.roblox.com/asset/?id=1361097"
- Mesh.VertexColor = Configuration.SnowColor;
- Mesh.Scale = Vector3.new(FlakeSize, FlakeSize, FlakeSize)
- local SnowFlake = {}
- SnowFlake.Flake = Flake;
- SnowFlake.CycleTick = Configuration.CycleLife
- SnowFlake.CyclesLeft = math.random(Configuration.CyclesPerLifeMin, Configuration.CyclesPerLifeMax)
- SnowFlake.MoveRate = GetSnowflakeMovement()
- SnowFlake.Mode = 0
- table.insert(SnowflakeQueue, SnowFlake)
- end
- local function CheckPlayer(Player)
- --- Makes sure a player has all necessary components.
- -- @return Boolean If the player has all the right components
- return Player and Player:IsA("Player") and Player:IsDescendantOf(Players)
- end
- local function CheckCharacter(Player)
- -- Makes sure a character has all the right "parts"
- if CheckPlayer(Player) then
- local Character = Player.Character;
- if Character then
- return Character.Parent
- and Character:FindFirstChild("Humanoid")
- and Character:FindFirstChild("HumanoidRootPart")
- and Character:FindFirstChild("Torso")
- and Character:FindFirstChild("Head")
- and Character.Humanoid:IsA("Humanoid")
- and Character.Head:IsA("BasePart")
- and Character.Torso:IsA("BasePart")
- and true
- end
- else
- warn("[CheckCharacter] - Character Check failed!")
- end
- return nil
- end
- local FindPartOnRayWithIgnoreList = workspace.FindPartOnRayWithIgnoreList
- local function AdvanceRaycast(RayTrace, IgnoreList, TransparencyThreshold, IgnoreCanCollideFalse, TerrainCellsAreCubes, MaximumCastCount, CustomCondition)
- -- @param TransparencyThreshold The transparency a part can be for it to be counted. For example, if TransparencyThreshold is 0.25, and a part is 0.24 transparency then it will be counted as solid, otherwise if it
- -- is 0.26 then it will be counted as transparent.
- -- If you don't want to hit transparent parts, then you can set it to -math.huge.
- -- TransparencyThreshold should not be above 1, probably.
- -- @param [CustomCondition] A function that can be defined to create a custom condition (such as making sure a character is hit)
- -- CustomCondition(HitObject, Position)
- -- @return boolean If true, then it will automatically abort the cycle and return.
- assert(type(MaximumCastCount) == "number", "MaximumCastCount is not a number")
- assert(type(TransparencyThreshold) == "number", "TransparencyThreshold must be a number")
- --print(TransparencyThreshold)
- local ContinueCasting = true;
- local CastCount = 0
- local function CastAttempt(NewRayTrace)
- -- print("Cast attempt " .. CastCount)
- if CastCount >= MaximumCastCount then
- return
- else
- CastCount = CastCount + 1
- end
- local Object, Position = FindPartOnRayWithIgnoreList(workspace, NewRayTrace, IgnoreList, TerrainCellsAreCubes)
- if Object and Position then
- if CustomCondition and CustomCondition(Object, Position) then
- -- print("Custom override")
- return Object, Position
- elseif IgnoreCanCollideFalse and Object.CanCollide == false then
- IgnoreList[#IgnoreList+1] = Object
- --print("Hit something cancollide false", Object:GetFullName())
- return CastAttempt(NewRayTrace)
- elseif TransparencyThreshold and Object.Transparency >= TransparencyThreshold then
- IgnoreList[#IgnoreList+1] = Object
- --print("Hit something transparent false", Object:GetFullName())
- return CastAttempt(NewRayTrace)
- else
- return Object, Position
- end
- else
- --print("Just didn't hit anything")
- return
- end
- end
- local DirectionUnit = RayTrace.Direction.unit
- local Magnitude = RayTrace.Direction.magnitude
- local CastedMagnitude = 0
- --game:GetService("Debris"):AddItem(
- -- lib.DrawRay(RayTrace, BrickColor.new("Bright orange"))
- --, 2)
- while CastedMagnitude < Magnitude do
- local ToCastMagnitude = Magnitude - CastedMagnitude
- if ToCastMagnitude > 999.5 then
- ToCastMagnitude = 999
- end
- local WaysAlongPath = RayTrace.Origin + (DirectionUnit * CastedMagnitude)
- local NewRayTrace = Ray.new(WaysAlongPath, DirectionUnit * ToCastMagnitude)
- local Object, Position = CastAttempt(NewRayTrace)
- -- game:GetService("Debris"):AddItem(
- -- lib.DrawRay(NewRayTrace, BrickColor.new("Bright green"))
- --, 2)
- if Object then
- return Object, Position
- end
- CastedMagnitude = CastedMagnitude + ToCastMagnitude
- if CastCount >= MaximumCastCount then
- print("[AdvanceRaycast] - Reached maximum cast count @ " .. CastCount .. "; MaximumCastCount = " .. MaximumCastCount)
- return nil
- end
- end
- end
- local SnowModel = GetSnowModel()
- SnowModel:ClearAllChildren()
- local LocalPlayer = Players.LocalPlayer
- --[[
- local function SetupCharacter(Character)
- local IgnoreList = {}
- local LastValidPlace = nil --Players.LocalPlayer.Character.Torso.Position
- while not CheckCharacter(LocalPlayer) and Character == LocalPlayer.Character do
- wait()
- end
- while CheckCharacter(LocalPlayer) and Character == LocalPlayer.Character do
- --if Character:FindFirstChild("Torso") then
- local NewRay = Ray.new(Torso.Position + Vector3.new(0, 3, 0), Vector3.new(0, 100, 0))
- local Hit, Position = AdvanceRaycast(NewRay, IgnoreList, 0.001, true, true, 5)
- if not Hit then
- LastValidPlace = Torso.Position
- --else
- --print("Inside")
- end
- if LastValidPlace then
- MakeSnowFlake(SnowModel, GetRandomSnowflakePosition(LastValidPlace))
- end
- --end
- UpdateQueue()
- wait()
- end
- end
- if LocalPlayer.Character then
- SetupCharacter(LocalPlayer.Character)
- end
- LocalPlayer.CharacterAdded:connect(SetupCharacter)--]]
- local LastValidPlace
- local IgnoreList = {SnowModel, LocalPlayer.Character}
- local LastClean = tick()
- local function CleanIgnoreList()
- if LastClean + 5 <= tick() then
- IgnoreList = {SnowModel, LocalPlayer.Character}
- LastClean = tick()
- end
- end
- local function DrawRay(Ray, Color, Parent)
- --- Draw's a ray out (for debugging)
- -- Credit to Cirrus for initial code.
- Parent = Parent or workspace
- local NewPart = Instance.new("Part", Parent)
- NewPart.FormFactor = "Custom"
- NewPart.Size = Vector3.new(0.2, Ray.Direction.magnitude, 0.2)
- local Center = Ray.Origin + Ray.Direction/2
- -- lib.DrawPoint(Ray.Origin).Name = "origin"
- -- lib.DrawPoint(Center).Name = "Center"
- -- lib.DrawPoint(Ray.Origin + Ray.Direction).Name = "Destination"
- NewPart.CFrame = CFrame.new(Center, Ray.Origin + Ray.Direction) * CFrame.Angles(math.pi/2, 0, 0) --* GetCFramePitch(math.pi/2)
- NewPart.Anchored = true
- NewPart.CanCollide = false
- NewPart.Transparency = 0.5
- NewPart.BrickColor = Color or BrickColor.new("Bright red")
- NewPart.Name = "DrawnRay"
- Instance.new("SpecialMesh", NewPart)
- return NewPart
- end
- while true do
- local Camera = workspace.CurrentCamera
- if Camera then
- -- Check to make sure we're next extending through a roof or something...
- local ExtensionRay = Ray.new(Camera.CoordinateFrame.p,
- Camera.CoordinateFrame:vectorToWorldSpace(Vector3.new(0, 0, -Configuration.RangeZ))
- )
- local Hit, Position = AdvanceRaycast(ExtensionRay, IgnoreList, 0.001, true, true, 5)
- if not Hit then
- -- Extend by mid range.
- local NewRay = Ray.new((Camera.CoordinateFrame * CFrame.new(0, 0, -Configuration.RangeZ)).p, Vector3.new(0, 100, 0))
- local Hit, Position = AdvanceRaycast(NewRay, IgnoreList, 0.001, true, true, 5)
- if not Hit then
- LastValidPlace = Camera.CoordinateFrame
- end
- end
- if LastValidPlace then
- for Index = 1, Configuration.SnowAmountFactor do
- MakeSnowFlake(SnowModel, GetRandomSnowflakePosition(LastValidPlace, Camera.CoordinateFrame))
- end
- end
- end
- UpdateQueue()
- CleanIgnoreList()
- wait(0.03)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement