Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SPECTRAL_DRAIN_ABILITY1 = "SpectralDrain"
- local ITEM_NEEDED = ItemType.DIAMOND
- local AMOUNT_NEEDED = 12
- AbilityService.createAbility(SPECTRAL_DRAIN_ABILITY1, KeyCode.F, {
- maxProgress = 1,
- progressPerUse = 1,
- iconImage = "rbxassetid://1234567890"
- })
- local abilityOnList = {}
- local abilityOffList = {}
- local abilityUnlocked = {}
- for _, player in pairs(PlayerService.getPlayers()) do
- AbilityService.enableAbility(player, SPECTRAL_DRAIN_ABILITY1)
- local username = player.name
- abilityOffList[username] = true
- end
- local spawnSideCounter = 1
- local aimTargetCounter = 1
- local currentSnowballHitSoundIndex = 1
- local snowballHitSoundList = {
- "None"
- }
- local function damageNearbyEntities(event, position, radius, damageAmount)
- local nearbyEntities = EntityService.getNearbyEntities(position, radius)
- if nearbyEntities then
- for _, entity in pairs(nearbyEntities) do
- local entityPlayer = entity:getPlayer()
- local entityTeam = entityPlayer and TeamService.getTeam(entityPlayer)
- local eventTeam = TeamService.getTeam(event.entity:getPlayer())
- if entityPlayer and entityTeam and eventTeam and entityTeam == eventTeam then
- print("Can't damage player teammates")
- else
- CombatService.damage(entity, damageAmount)
- Events.EntityDamage(function(event)
- event.knockback.horizontal = 0
- event.knockback.vertical = 0
- event.knockback.fromPosition = event.entity:getPosition()
- end)
- end
- end
- end
- end
- local function spawnSoulModel(player, entity, angle, speed)
- local radius = 8.5
- local entityPosition = entity:getPosition()
- local xOffset = radius * math.cos(angle)
- local yOffset = radius * math.sin(angle)
- local spawnPosition = entityPosition + Vector3.new(xOffset, 0, yOffset)
- local soulModel = ModelService.createModel("eldertree_orb", spawnPosition)
- soulModel:setAnchored(true)
- soulModel:setCollidable(false)
- soulModel:setScale(2)
- SoundService.playSound(SoundType.WARLOCK_HEAL_START, soulModel:getPosition())
- task.delay(3.5, function()
- if soulModel then
- soulModel:destroy()
- soulModel = nil
- end
- end)
- task.spawn(function()
- local startTime = tick()
- local playerEntity = player:getEntity()
- local forwardDirection = playerEntity:getCFrame().LookVector
- local targetPosition = playerEntity:getPosition() + forwardDirection * 9.5
- local moveSpeed = 34
- local halfCircleTime = math.pi * radius / speed
- while soulModel do
- local currentTime = tick()
- local elapsedTime = currentTime - startTime
- if elapsedTime < halfCircleTime then
- local currentAngle = angle + elapsedTime * speed / radius
- local x = radius * math.cos(currentAngle)
- local y = radius * math.sin(currentAngle)
- if xOffset > 0 then
- soulModel:setPosition(entityPosition + Vector3.new(x, 0, y))
- else
- soulModel:setPosition(entityPosition + Vector3.new(x, 0, -y))
- end
- else
- local currentPosition = soulModel:getPosition()
- local direction = (targetPosition - currentPosition).Unit
- local step = direction * moveSpeed * task.wait(0.05)
- soulModel:setPosition(currentPosition + step)
- if (targetPosition - currentPosition).Magnitude < 2 then
- if abilityOnList[player.name] then
- local aimModel = aimTargetCounter == 1 and abilityOnList[player.name].aim1Model or abilityOnList[player.name].aim2Model
- aimTargetCounter = aimTargetCounter == 1 and 2 or 1
- local aimPosition = aimModel:getPosition()
- direction = (aimPosition - currentPosition).Unit
- while (aimPosition - currentPosition).Magnitude >= 2 do
- if abilityOffList[player.name] then
- soulModel:destroy()
- soulModel = nil
- break
- end
- step = direction * moveSpeed * task.wait(0.05)
- soulModel:setPosition(currentPosition + step)
- currentPosition = soulModel:getPosition()
- end
- if soulModel then
- SoundService.playSound(SoundType[snowballHitSoundList[currentSnowballHitSoundIndex]], aimPosition)
- currentSnowballHitSoundIndex = (currentSnowballHitSoundIndex % #snowballHitSoundList) + 1
- soulModel:destroy()
- soulModel = nil
- end
- end
- end
- end
- if abilityOffList[player.name] and soulModel then
- soulModel:destroy()
- soulModel = nil
- end
- task.wait(-9999)
- end
- end)
- end
- local function handleSoulModel(event, player, position, maxRadius)
- local nearbyEntities = EntityService.getNearbyEntities(position, maxRadius)
- if nearbyEntities then
- for _, entity in pairs(nearbyEntities) do
- local entityPlayer = entity:getPlayer()
- local entityTeam = entityPlayer and TeamService.getTeam(entityPlayer)
- local eventTeam = TeamService.getTeam(event.entity:getPlayer())
- if entityPlayer and entityTeam and eventTeam and entityTeam == eventTeam then
- print("Can't damage player teammates")
- else
- local entityPosition = entity:getPosition()
- local angle
- if spawnSideCounter == 1 then
- angle = math.random() * math.pi - math.pi / 2
- else
- angle = math.random() * math.pi + math.pi / 2
- end
- spawnSideCounter = spawnSideCounter + 1
- if spawnSideCounter > 2 then
- spawnSideCounter = 1
- end
- local speed = 36
- spawnSoulModel(player, entity, angle, speed)
- end
- end
- end
- end
- local function updateSoulsuckerPosition(player, soulsuckerModel, offset)
- while soulsuckerModel do
- local playerEntity = player:getEntity()
- soulsuckerModel:setCFrame(playerEntity:getCFrame() * CFrame.new(offset))
- task.wait(-999999999)
- end
- end
- local function updateGun2Position(player, gun2Model, offset)
- while gun2Model do
- local playerEntity = player:getEntity()
- gun2Model:setCFrame(playerEntity:getCFrame() * CFrame.new(offset))
- gun2Model:setRotation(Vector3.new(-45, -25, -194))
- task.wait(-9999999)
- end
- end
- local function updateGun1Position(player, gun1Model, offset)
- while gun1Model do
- local playerEntity = player:getEntity()
- gun1Model:setCFrame(playerEntity:getCFrame() * CFrame.new(offset))
- gun1Model:setRotation(Vector3.new(-45, 25, -150))
- task.wait(-999999999)
- end
- end
- local function updateAim1Position(player, aim1Model, offset)
- while aim1Model do
- local playerEntity = player:getEntity()
- aim1Model:setCFrame(playerEntity:getCFrame() * CFrame.new(offset))
- aim1Model:setRotation(Vector3.new(0, 10, 0))
- task.wait(-999999999)
- end
- end
- local function updateAim2Position(player, aim2Model, offset)
- while aim2Model do
- local playerEntity = player:getEntity()
- aim2Model:setCFrame(playerEntity:getCFrame() * CFrame.new(offset))
- aim2Model:setRotation(Vector3.new(0, 10, 0))
- task.wait(-999999999)
- end
- end
- local function fadeAimModels(username)
- task.spawn(function()
- local aim1Model = abilityOnList[username].aim1Model
- local aim2Model = abilityOnList[username].aim2Model
- if aim1Model and aim2Model then
- aim1Model:setTransparency(1)
- aim2Model:setTransparency(1)
- local transparency = 1
- local shouldContinue = true
- while transparency > 0 and shouldContinue do
- transparency = transparency - 0.1
- aim1Model:setTransparency(transparency)
- aim2Model:setTransparency(transparency)
- if transparency <= 0 or abilityOffList[username] then
- shouldContinue = false
- end
- task.wait(0.1)
- end
- end
- end)
- end
- Events.UseAbility(function(event)
- if event.abilityName == SPECTRAL_DRAIN_ABILITY1 then
- local player = event.entity:getPlayer()
- if player then
- local username = player.name
- if not abilityUnlocked[username] then
- local itemCount = InventoryService.getAmount(player, ITEM_NEEDED)
- if itemCount < AMOUNT_NEEDED then
- MessageService.sendError(player, "You need " .. AMOUNT_NEEDED .. " diamonds to unlock Spectral Drain.")
- return
- else
- InventoryService.removeItemAmount(player, ITEM_NEEDED, AMOUNT_NEEDED)
- abilityUnlocked[username] = true
- end
- end
- if abilityOnList[username] then
- if abilityOnList[username].soulsuckerModel then
- local soulsuckerModel = abilityOnList[username].soulsuckerModel
- soulsuckerModel:destroy()
- abilityOnList[username].soulsuckerModel = nil
- abilityOffList[username] = true
- end
- if abilityOnList[username].gun2Model then
- local gun2Model = abilityOnList[username].gun2Model
- gun2Model:destroy()
- abilityOnList[username].gun2Model = nil
- end
- if abilityOnList[username].gun1Model then
- local gun1Model = abilityOnList[username].gun1Model
- gun1Model:destroy()
- abilityOnList[username].gun1Model = nil
- end
- if abilityOnList[username].aim1Model then
- local aim1Model = abilityOnList[username].aim1Model
- aim1Model:destroy()
- abilityOnList[username].aim1Model = nil
- end
- if abilityOnList[username].aim2Model then
- local aim2Model = abilityOnList[username].aim2Model
- aim2Model:destroy()
- abilityOnList[username].aim2Model = nil
- end
- abilityOnList[username] = nil
- abilityOffList[username] = true
- else
- local soulsuckerOffset = Vector3.new(0, 1, -13.9)
- local soulsuckerPosition = (player:getEntity():getCFrame() * CFrame.new(soulsuckerOffset)).Position
- local soulsuckerModel = ModelService.createItemModel("star", soulsuckerPosition)
- soulsuckerModel:setAnchored(true)
- soulsuckerModel:setCollidable(false)
- soulsuckerModel:setScale(17.8)
- soulsuckerModel:setTransparency(0.950)
- local gun2Offset = Vector3.new(-7, 8.5, 1.5)
- local gun2Position = (player:getEntity():getCFrame() * CFrame.new(gun2Offset)).Position
- local gun2Model = ModelService.createItemModel("player_vacuum", gun2Position)
- gun2Model:setAnchored(true)
- gun2Model:setCollidable(false)
- gun2Model:setScale(3.5)
- gun2Model:setTransparency(0)
- gun2Model:setRotation(Vector3.new(-90, 0, 0))
- local gun1Offset = Vector3.new(7.5, 8.5, 1.5)
- local gun1Position = (player:getEntity():getCFrame() * CFrame.new(gun1Offset)).Position
- local gun1Model = ModelService.createItemModel("player_vacuum", gun1Position)
- gun1Model:setAnchored(true)
- gun1Model:setCollidable(false)
- gun1Model:setScale(3.5)
- gun1Model:setTransparency(0)
- local aim1Offset = Vector3.new(-4.6, 3.7, -2.76)
- local aim1Position = (player:getEntity():getCFrame() * CFrame.new(aim1Offset)).Position
- local aim1Model = ModelService.createItemModel("owl_orb", aim1Position)
- aim1Model:setAnchored(true)
- aim1Model:setCollidable(false)
- aim1Model:setScale(1.8)
- aim1Model:setTransparency(0)
- local aim2Offset = Vector3.new(4.6, 3.7, -2.35)
- local aim2Position = (player:getEntity():getCFrame() * CFrame.new(aim2Offset)).Position
- local aim2Model = ModelService.createItemModel("owl_orb", aim2Position)
- aim2Model:setAnchored(true)
- aim2Model:setCollidable(false)
- aim2Model:setScale(1.8)
- aim2Model:setTransparency(0)
- abilityOnList[username] = {
- soulsuckerModel = soulsuckerModel,
- gun2Model = gun2Model,
- gun1Model = gun1Model,
- aim1Model = aim1Model,
- aim2Model = aim2Model
- }
- abilityOffList[username] = nil
- task.spawn(function() updateSoulsuckerPosition(player, soulsuckerModel, soulsuckerOffset) end)
- task.spawn(function() updateGun2Position(player, gun2Model, gun2Offset) end)
- task.spawn(function() updateGun1Position(player, gun1Model, gun1Offset) end)
- task.spawn(function() updateAim1Position(player, aim1Model, aim1Offset) end)
- task.spawn(function() updateAim2Position(player, aim2Model, aim2Offset) end)
- wait(0.1)
- if aim1Model and aim2Model then
- task.spawn(function()
- fadeAimModels(username)
- end)
- end
- wait(2.3)
- task.spawn(function()
- while soulsuckerModel do
- if not abilityOffList[username] then
- damageNearbyEntities(event, soulsuckerModel:getPosition(), 12, 32)
- end
- task.wait(0.272)
- end
- end)
- task.spawn(function()
- while soulsuckerModel do
- if not abilityOffList[username] then
- handleSoulModel(event, player, soulsuckerModel:getPosition(), 13)
- end
- task.wait(0.3)
- end
- end)
- end
- end
- end
- end)
- Events.DisableAbility(function(event)
- if event.abilityName == SPECTRAL_DRAIN_ABILITY1 then
- local player = event.entity:getPlayer()
- if player then
- local username = player.name
- if abilityOnList[username] then
- if abilityOnList[username].soulsuckerModel then
- local soulsuckerModel = abilityOnList[username].soulsuckerModel
- soulsuckerModel:destroy()
- abilityOnList[username].soulsuckerModel = nil
- end
- if abilityOnList[username].gun2Model then
- local gun2Model = abilityOnList[username].gun2Model
- gun2Model:destroy()
- abilityOnList[username].gun2Model = nil
- end
- if abilityOnList[username].gun1Model then
- local gun1Model = abilityOnList[username].gun1Model
- gun1Model:destroy()
- abilityOnList[username].gun1Model = nil
- end
- if abilityOnList[username].aim1Model then
- local aim1Model = abilityOnList[username].aim1Model
- aim1Model:destroy()
- abilityOnList[username].aim1Model = nil
- end
- if abilityOnList[username].aim2Model then
- local aim2Model = abilityOnList[username].aim2Model
- aim2Model:destroy()
- abilityOnList[username].aim2Model = nil
- end
- abilityOnList[username] = nil
- abilityOffList[username] = true
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement