Tool = Instance.new("Tool")
Tool.Name = 'Subspace Tripmine'
Tool.CanBeDropped = true
Tool.RequiresHandle = true
Part0 = Instance.new("Part")
SpecialMesh1 = Instance.new("SpecialMesh")
Part0.Name = "Handle"
Part0.Parent = Tool
Part0.CFrame = CFrame.new(7, 1.39097822, 3, 1, -5.50079088e-19, 5.6767685e-24, 5.50079088e-19, 1, -5.50079088e-19, -5.6767685e-24, 5.50079088e-19, 1)
Part0.Position = Vector3.new(7, 1.390978217124939, 3)
Part0.Color = Color3.new(1, 0, 0.74902)
Part0.Velocity = Vector3.new(-2.0073717184513294e-18, -0.009398775175213814, 2.100645224708268e-18)
Part0.Size = Vector3.new(2, 2, 2)
Part0.BottomSurface = Enum.SurfaceType.Smooth
Part0.BrickColor = BrickColor.new("Hot pink")
Part0.RotVelocity = Vector3.new(2.05534653961818e-18, 8.374077637867082e-21, 2.05534653961818e-18)
Part0.TopSurface = Enum.SurfaceType.Smooth
Part0.brickColor = BrickColor.new("Hot pink")
SpecialMesh1.Parent = Part0
SpecialMesh1.MeshId = "http://www.roblox.com/asset/?id=11954776"
SpecialMesh1.Scale = Vector3.new(0.699999988079071, 0.699999988079071, 0.699999988079071)
SpecialMesh1.TextureId = "http://www.roblox.com/asset/?id=11954766"
SpecialMesh1.MeshType = Enum.MeshType.FileMesh
wait = task.wait
function runmine(Mine)
local DunDun = Instance.new("Sound")
DunDun.SoundId = "http://www.roblox.com/asset/?id=11984254"
DunDun.Parent = Mine
local SubspaceExplosion = Instance.new("Sound")
SubspaceExplosion.SoundId = "http://www.roblox.com/asset/?id=11984351"
SubspaceExplosion.Parent = Mine
local Calibrate = Instance.new("Sound")
Calibrate.SoundId = "http://www.roblox.com/asset/?id=11956590"
Calibrate.Looped = true
Calibrate.Parent = Mine
Calibrate:Play()
local calibration_time = 2 -- needs to be still/untouched for this long before calibrating
local cur_time = 0
local max_life = 120 -- these things last for 2 minutes on their own, once activated
local calibrated = false
local looping = true
local connection = nil
local function activateMine()
for i=0,1,-.1 do
Mine.Transparency = i
wait(.05)
end
calibrated = true
Calibrate:Stop()
end
local function pulse()
DunDun:Play()
for i=.9,.5,-.1 do
Mine.Transparency = i
wait(.05)
end
for i=.5,1,.1 do
Mine.Transparency = i
wait(.05)
end
end
local function tagHumanoid(humanoid, creator)
if creator ~= nil then
local new_tag = creator:clone()
new_tag.Parent = humanoid
end
end
local function untagHumanoid(humanoid)
if humanoid ~= nil then
local tag = humanoid:FindFirstChild("creator")
if tag ~= nil then
tag.Parent = nil
end
end
end
local function onPlayerBlownUp(part, distance, creator)
if part:IsA("BasePart") and not part:IsA("SpawnLocation") and (part:GetMass() < 300) then
part.BrickColor = BrickColor.new(1032)
local s = Instance.new("Sparkles")
s.Parent = part
game.Debris:AddItem(s, 5)
end
if creator ~= nil and part.Name == "Head" then
local humanoid = part.Parent.Humanoid
tagHumanoid(humanoid, creator)
end
end
local function explode()
connection:Disconnect()
for i=1,0,-.2 do
Mine.Transparency = i
wait(.05)
end
SubspaceExplosion:Play()
local e = Instance.new("Explosion")
e.BlastRadius = 16
e.BlastPressure = 1000000
e.Position = Mine.Position
e.Parent = Mine
local creator = Mine:FindFirstChild("creator")
e.Hit:connect(function(part, distance) onPlayerBlownUp(part, distance, creator) end)
for i=0,1,.2 do
Mine.Transparency = i
wait(.05)
end
wait(4)
Mine:Remove()
end
local function update()
if (calibrated == false) then
if (Mine.Velocity.magnitude > .1) then
cur_time = 0
end
if (cur_time > calibration_time) then
activateMine()
end
else
-- calibrated mine
if (math.random(1,20) == 2) then
pulse()
end
if (cur_time > max_life) then pulse() Mine:Remove() end
end
end
local function OnTouch(part)
if (calibrated == false) then
cur_time = 0
else
explode()
end
end
connection = Mine.Touched:connect(OnTouch)
while Mine and Mine.Parent do
update()
local e,g = wait(.5)
cur_time = cur_time + e
end
end
function plant(pos)
local vCharacter = Tool.Parent
local vPlayer = game.Players:playerFromCharacter(vCharacter)
local spawnPos = vCharacter.PrimaryPart.Position
local bomb = Tool.Handle:Clone()
bomb.CanCollide = true
bomb.Transparency = 0
bomb.Position = pos
bomb.Size = Vector3.new(2,2,2)
bomb.Name = "SubspaceTripmine"
bomb.Locked = true
local creator_tag = Instance.new("ObjectValue")
creator_tag.Value = vPlayer
creator_tag.Name = "creator"
creator_tag.Parent = bomb
bomb.Parent = game.Workspace
coroutine.wrap(function()
runmine(bomb)
end)()
end
Tool.Enabled = true
function onActivated()
if not Tool.Enabled then
return
end
Tool.Enabled = false
local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
print("Humanoid not found")
return
end
local targetPos = humanoid.TargetPoint
Tool.Handle.Transparency = 1
plant(Tool.Handle.Position)
--wait(3)
Tool.Handle.Transparency = 0
Tool.Enabled = true
end
local aid = 0
Tool.Activated:Connect(function()
aid += 1
local cid = aid
onActivated()
repeat
onActivated()
task.wait(1/20)
until cid ~= aid
end)
Tool.Deactivated:Connect(function()
aid += 1
end)
Tool.Unequipped:Connect(function()
aid += 1
end)
Tool.Parent = owner:FindFirstChildOfClass("Backpack")