Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---------------------------------------------------------------
- -- File: /mods/4DC_V0.82/lua/CustomAbilities/4D_DeflectorShield/DeflectorShield.lua
- -- 4DC Custom deflector shield using DMS
- -- Author: Resin Smoker
- -- Special Thanks: Domino
- -- Copyright © 2014 4DC_V0.82 All rights reserved.
- ---------------------------------------------------------------
- local Entity = import('/lua/sim/Entity.lua').Entity
- local utils = import('/lua/utilities.lua')
- local EffectTemplate = import('/lua/EffectTemplates.lua')
- local myDebug = false
- Deflector_Entity = Class(Entity) {
- OnCreate = function(self,spec)
- Entity.OnCreate(self,spec)
- if myDebug then
- WARN('DeflectorShield.lua, OnCreate')
- end
- if spec and spec.Owner then
- --> Set "self" parameters
- self.Army = self:GetArmy()
- self.Deflector_Spec = spec
- self.EffectsBag = {}
- self.FxStatus = false
- self.MeshScale = spec.MeshScale or 1
- self.Trash = TrashBag()
- --> Set owner
- self:SetOwner(spec.Owner)
- --> Set trash
- self.Owner.Trash:Add(self)
- --> Set the entities Mesh
- self:SetMesh(spec.DeflectorMesh)
- --> Set Deflector Size.
- self:SetDrawScale(self.MeshScale or 1.0)
- --> Attach to the Owner
- self:AttachBoneTo(-1, self.Owner, self.Deflector_Spec.OwnerAttachBone)
- --> Set the Deflector Offset Position
- self:SetOffset()
- --> Set the Deflector visable state
- if self.Deflector_Spec.StartOn == true then
- self:EnableDeflector()
- else
- self:DisableDeflector()
- end
- else
- self:Destroy()
- end
- end,
- OnCollisionCheck = function(self, other)
- if myDebug then
- WARN('DeflectorShield.lua, OnCollisionCheck')
- end
- if not self:BeenDestroyed() and other then
- if IsProjectile(other) and not other:BeenDestroyed() and not IsAlly(self:GetArmy(), other:GetArmy()) then
- self:ReflectProjectile(other)
- end
- end
- end,
- ReflectProjectile = function(self, other)
- if myDebug then
- WARN('DeflectorShield.lua, ReflectProjectile', x ,y ,z)
- end
- if not other:HasReflected() then
- other:SetReflected(other)
- end
- other.DamageData.DamageFriendly = true
- other.DamageData.DamageSelf = true
- local x, y, z = other:GetVelocity()
- -- WARN('***')
- -- WARN('Incomming Projectile speed', x ,y ,z)
- -- local relectMul = 1
- --
- -- if self.ReflectRandomVector then
- -- x = x + (relectMul * ((Random() * 2) - 1))
- -- y = z + (relectMul * ((Random() * 2) - 1))
- -- z = z + (relectMul * ((Random() * 2) - 1))
- -- end
- --
- -- --if myDebug then
- -- WARN('Reflected Projectile speed', x ,y ,z)
- -- WARN(' ***')
- -- --end
- other:SetVelocityAlign(true)
- other:TrackTarget(false)
- other:SetVelocity(-x,-y,-z)
- other:SetVelocity(12)
- other:SetLifetime(5)
- other:SetReflected(self)
- end,
- ##########################################################################################
- ## --Set Collision Shape
- ##########################################################################################
- SetShape = function(self, state)
- if self.Deflector_Spec.CollisionShape == 'Box' and state == true then
- self:SetCollisionShape('Box', self.Deflector_Spec.CollisionCenterX, self.Deflector_Spec.CollisionCenterY, self.Deflector_Spec.CollisionCenterZ, self.Deflector_Spec.CollisionSizeX, self.Deflector_Spec.CollisionSizeY, self.Deflector_Spec.CollisionSizeZ)
- elseif self.Deflector_Spec.CollisionShape == 'Sphere' and state == true then
- self:SetCollisionShape('Sphere', 0, 0, 0, self.Deflector_Spec.SizeSphere)
- else
- self:SetCollisionShape('None')
- end
- end,
- ##########################################################################################
- ## --Enable / Disable Deflector
- ##########################################################################################
- EnableDeflector = function(self)
- if myDebug then
- WARN('DeflectorShield.lua, EnableDeflector')
- end
- --> Play the shield activation sound
- if self.Deflector_Spec.Audio.ShieldOn then
- WARN('sounds')
- self.Owner:PlayUnitSound('ShieldOn')
- end
- -- Activate Econ
- if self.Deflector_Spec.Economy.MaintenanceConsumptionPerSecondEnergy > 0 then
- self.Owner:SetMaintenanceConsumptionActive()
- end
- --> Set Collision Shape
- self:SetShape(true)
- --> Set Deflector visability.
- self:SetVisable(true)
- --> Add beam from unit to deflector
- self:BeamFX(true)
- end,
- DisableDeflector = function(self)
- if myDebug then
- WARN('DeflectorShield.lua, DisableDeflector')
- end
- --> Play the shield de-activation sound
- if self.Deflector_Spec.Audio.ShieldOff then
- self.Owner:PlayUnitSound('ShieldOff')
- end
- -- De-activate Econ
- if self.Deflector_Spec.Economy.MaintenanceConsumptionPerSecondEnergy > 0 then
- self.Owner:SetMaintenanceConsumptionInactive()
- end
- --> Set Collision Shape
- self:SetShape(false)
- --> Set Deflector visability.
- self:SetVisable(false)
- --> Add beam from unit to deflector
- self:BeamFX(false)
- end,
- ##########################################################################################
- ## --Set/Get Owner
- ##########################################################################################
- SetOwner = function(self, Owner)
- if myDebug then
- WARN('DeflectorShield.lua, SetOwner')
- end
- if Owner then
- self.Owner = Owner
- if not Owner.Trash then
- Owner.Trash = TrashBag()
- end
- Owner.Trash:Add(self)
- else
- return
- end
- end,
- GetOwner = function(self)
- return self.Owner or nil
- end,
- ##########################################################################################
- ## --Set Initial Offset Position
- ##########################################################################################
- SetOffset = function(self)
- if myDebug then
- WARN('DeflectorShield.lua, SetOffset')
- end
- local xOff = self.Deflector_Spec.PositionOffsetX or 0
- local yOff = self.Deflector_Spec.PositionOffsetY or 0
- local zOff = self.Deflector_Spec.PositionOffsetZ or 0
- self:SetParentOffset(Vector(xOff, yOff, zOff))
- end,
- ##########################################################################################
- ## --Set Visable.
- ##########################################################################################
- SetVisable = function(self, state)
- if myDebug then
- WARN('DeflectorShield.lua, SetVisable ', state)
- end
- if state == true then
- self:SetVizToFocusPlayer('Always')
- self:SetVizToNeutrals('Always')
- self:SetVizToEnemies('Always')
- self:SetVizToAllies('Always')
- elseif state == false then
- self:SetVizToFocusPlayer('Never')
- self:SetVizToNeutrals('Never')
- self:SetVizToEnemies('Never')
- self:SetVizToAllies('Never')
- end
- end,
- ##########################################################################################
- ## --Beam Effects.
- ##########################################################################################
- BeamFX = function(self, state)
- if myDebug then
- WARN('DeflectorShield.lua, BeamFX ', state)
- end
- if state == true then
- for k, v in EffectTemplate.ReclaimBeams do
- local beamEffect = AttachBeamEntityToEntity(self, -1, self.Owner, self.Deflector_Spec.OwnerFXBone, self.Army, v ):ScaleEmitter(1)
- table.insert( self.EffectsBag, beamEffect)
- self.Trash:Add(beamEffect)
- end
- elseif state == false then
- if self.EffectsBag then
- for k, v in self.EffectsBag do
- v:Destroy()
- end
- self.EffectsBag = {}
- end
- end
- end,
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement