Залив
This commit is contained in:
84
lua/entities/mg_warhead/cl_init.lua
Normal file
84
lua/entities/mg_warhead/cl_init.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
include("shared.lua")
|
||||
|
||||
ENT.AutomaticFrameAdvance = true
|
||||
|
||||
|
||||
local flair = Material("shadowdark/flairs/grenade_flair.vmt")
|
||||
ENT.OuterFlairColor = Color(236,153,17,255)
|
||||
ENT.InnerFlairColor = Color(255,255,255,255)
|
||||
|
||||
ENT.OuterFlairScale = 1
|
||||
ENT.InnerFlairScale = 0.3
|
||||
|
||||
function ENT:Draw(flags)
|
||||
self:DrawModel(flags)
|
||||
|
||||
if (self.m_SpawnPos != nil && self:GetPos():Distance(self.m_SpawnPos) > 64) then
|
||||
ParticleEffectAttach("rockettrail", PATTACH_ABSORIGIN_FOLLOW, self, 0)
|
||||
self.m_SpawnPos = nil
|
||||
end
|
||||
|
||||
local ang = LocalPlayer():EyeAngles()
|
||||
local angle = Angle( 0, LocalPlayer():EyeAngles()[2], 0 )
|
||||
|
||||
angle = Angle(LocalPlayer():EyeAngles()[1], angle.y, 0 )
|
||||
|
||||
angle:RotateAroundAxis( angle:Up(), -90 )
|
||||
angle:RotateAroundAxis( angle:Forward(), 90 )
|
||||
|
||||
cam.Start3D2D( self:GetPos() - self:GetForward() * -5, angle, 0.2 )
|
||||
|
||||
local OuterScale = 512 * self.OuterFlairScale
|
||||
local InnerScale = 512 * self.InnerFlairScale
|
||||
|
||||
surface.SetMaterial(flair)
|
||||
surface.SetDrawColor(self.OuterFlairColor)
|
||||
surface.DrawTexturedRect(-OuterScale/2, -OuterScale/2, OuterScale, OuterScale)
|
||||
|
||||
surface.SetDrawColor(self.InnerFlairColor)
|
||||
surface.DrawTexturedRect(-InnerScale/2, -InnerScale/2, InnerScale, InnerScale)
|
||||
cam.End3D2D()
|
||||
|
||||
end
|
||||
|
||||
function ENT:DrawTranslucent(flags)
|
||||
self:Draw(flags)
|
||||
end
|
||||
|
||||
function ENT:OnRemove()
|
||||
if (self:WaterLevel() <= 0) then
|
||||
self:EmitSound("^viper/shared/rocket_expl_env_0"..math.random(1, 3)..".wav", 150, 100, 1, CHAN_WEAPON) --snd scripts dont work lol!
|
||||
|
||||
local dlight = DynamicLight(self:EntIndex())
|
||||
if (dlight) then
|
||||
dlight.pos = self:GetPos()
|
||||
dlight.r = 255
|
||||
dlight.g = 75
|
||||
dlight.b = 0
|
||||
dlight.brightness = 5
|
||||
dlight.Decay = 2000
|
||||
dlight.Size = 1024
|
||||
dlight.DieTime = CurTime() + 5
|
||||
end
|
||||
end
|
||||
|
||||
self:StopParticles()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: Think
|
||||
Desc: Client Think - called every frame
|
||||
-----------------------------------------------------------]]
|
||||
function ENT:Think()
|
||||
if (self:WaterLevel() > 0) then
|
||||
self:EmitSound("viper/shared/melee/melee_world_fist_soft_plr_01.ogg", 75, 100, 0.001, CHAN_WEAPON)
|
||||
self:StopParticles()
|
||||
end
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: OnRestore
|
||||
Desc: Called immediately after a "load"
|
||||
-----------------------------------------------------------]]
|
||||
function ENT:OnRestore()
|
||||
end
|
||||
278
lua/entities/mg_warhead/init.lua
Normal file
278
lua/entities/mg_warhead/init.lua
Normal file
@@ -0,0 +1,278 @@
|
||||
AddCSLuaFile("cl_init.lua")
|
||||
AddCSLuaFile("shared.lua")
|
||||
|
||||
include("shared.lua")
|
||||
|
||||
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: KeyValue
|
||||
Desc: Called when a keyvalue is added to us
|
||||
-----------------------------------------------------------]]
|
||||
function ENT:KeyValue( key, value )
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: OnRestore
|
||||
Desc: The game has just been reloaded. This is usually the right place
|
||||
to call the GetNW* functions to restore the script's values.
|
||||
-----------------------------------------------------------]]
|
||||
function ENT:OnRestore()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: AcceptInput
|
||||
Desc: Accepts input, return true to override/accept input
|
||||
-----------------------------------------------------------]]
|
||||
function ENT:AcceptInput( name, activator, caller, data )
|
||||
return false
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: UpdateTransmitState
|
||||
Desc: Set the transmit state
|
||||
-----------------------------------------------------------]]
|
||||
function ENT:UpdateTransmitState()
|
||||
return TRANSMIT_ALWAYS
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: Think
|
||||
Desc: Entity's think function.
|
||||
-----------------------------------------------------------]]
|
||||
function ENT:Think()
|
||||
end
|
||||
|
||||
function ENT:PhysicsCollide(colData, collider)
|
||||
if (self.m_Water && self:GetVelocity():Length() < 250) then
|
||||
timer.Simple(0, function()
|
||||
self:Remove()
|
||||
end)
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
local bHasExploded = false
|
||||
|
||||
for i, e in pairs(ents.FindInSphere(self:GetPos(), 16)) do
|
||||
if (e:IsNPC()) then
|
||||
self:Explode({
|
||||
HitEntity = e,
|
||||
HitNormal = (e:NearestPoint(self:GetPos()) - self:GetPos()):GetNormalized(),
|
||||
HitPos = e:NearestPoint(self:GetPos())
|
||||
})
|
||||
|
||||
if (e:GetClass() == "npc_strider") then
|
||||
e:Fire("Explode")
|
||||
end
|
||||
|
||||
bHasExploded = true
|
||||
end
|
||||
end
|
||||
|
||||
if (!bHasExploded) then
|
||||
self:Explode(colData)
|
||||
end
|
||||
end
|
||||
|
||||
-- function ENT:PhysicsUpdate(phys)
|
||||
-- if (self:WaterLevel() > 0) then
|
||||
-- self.m_Water = true
|
||||
-- end
|
||||
|
||||
-- if (self.m_Water) then
|
||||
-- phys:EnableDrag(true)
|
||||
-- phys:EnableGravity(true)
|
||||
-- return
|
||||
-- end
|
||||
|
||||
-- self.m_Fuel = self.m_Fuel - 100 * FrameTime()
|
||||
-- self.m_Stability = self.m_Stability + 700 * FrameTime()
|
||||
|
||||
-- if (self.m_Propel && self.m_Fuel <= 0) then
|
||||
-- self.m_Propel = false
|
||||
-- phys:EnableDrag(true)
|
||||
-- phys:EnableGravity(true)
|
||||
-- end
|
||||
|
||||
-- if (self.m_Propel) then
|
||||
-- phys:AddVelocity(phys:GetAngles():Forward() * self.Projectile.Speed)
|
||||
-- self.m_gravity = self.m_gravity + (self.Projectile.Gravity)
|
||||
|
||||
-- phys:SetPos(self.LastPos + phys:GetAngles():Forward() * (self.Projectile.Speed * FrameTime()) - (Vector(0, 0, self.m_gravity) * FrameTime()))
|
||||
-- end
|
||||
|
||||
-- local vel = phys:GetVelocity()
|
||||
-- phys:SetAngles(vel:Angle() + Angle(self.Projectile.Gravity,math.Rand(self.m_Stability / -self.Projectile.Stability, self.m_Stability / self.Projectile.Stability),self.m_gravity))
|
||||
-- phys:SetVelocity(vel)
|
||||
|
||||
|
||||
|
||||
|
||||
-- if (self:WaterLevel() > 0) then
|
||||
-- self.m_Propel = false
|
||||
-- end
|
||||
|
||||
-- for i, e in pairs(ents.FindInSphere(phys:GetPos(), 16)) do
|
||||
-- if (e:IsNPC()) then
|
||||
-- self:Explode({
|
||||
-- HitEntity = e,
|
||||
-- HitNormal = (e:NearestPoint(phys:GetPos()) - phys:GetPos()):GetNormalized(),
|
||||
-- HitPos = e:NearestPoint(phys:GetPos())
|
||||
-- })
|
||||
|
||||
-- if (e:GetClass() == "npc_strider") then
|
||||
-- e:Fire("Explode")
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
function ENT:PhysicsUpdate(phys)
|
||||
|
||||
self.Target:SetPos(phys:GetPos())
|
||||
|
||||
self.m_Fuel = self.m_Fuel - 100 * FrameTime()
|
||||
self.m_Stability = self.m_Stability + 700 * FrameTime()
|
||||
|
||||
if (self.m_Propel && self.m_Fuel <= 0) then
|
||||
self.m_Propel = false
|
||||
phys:EnableDrag(true)
|
||||
phys:EnableGravity(true)
|
||||
phys:AddVelocity(phys:GetAngles():Forward() * self.Projectile.Speed)
|
||||
end
|
||||
|
||||
if (self.m_Propel) then
|
||||
|
||||
phys:SetPos(self.LastPos + phys:GetAngles():Forward() * (self.Projectile.Speed * FrameTime()) - (Vector(0, 0, self.m_gravity) * FrameTime()))
|
||||
|
||||
if (self.m_Tracking && self.TrackedEntity:IsValid()) then
|
||||
local dir = self.TrackedEntity:WorldSpaceCenter() - phys:GetPos()
|
||||
phys:SetAngles(LerpAngle(self.Projectile.TrackingFraction, phys:GetAngles(), dir:Angle()))
|
||||
elseif self.Projectile.Stability != 0 then
|
||||
phys:SetAngles(phys:GetAngles() + Angle(0,math.Rand(self.m_Stability / -self.Projectile.Stability, self.m_Stability / self.Projectile.Stability),0))
|
||||
end
|
||||
|
||||
else
|
||||
local vel = phys:GetVelocity()
|
||||
phys:SetAngles(vel:Angle() + Angle(self.Projectile.Gravity,math.Rand(self.m_Stability / -self.Projectile.Stability, self.m_Stability / self.Projectile.Stability),self.m_gravity))
|
||||
phys:SetVelocity(vel)
|
||||
end
|
||||
|
||||
if (!self.bCollided) then
|
||||
--Aim assist
|
||||
if (GetConVar("mgbase_debug_projectiles"):GetInt() > 0) then
|
||||
debugoverlay.Box(phys:GetPos(), -self.Maxs, self.Maxs, 0, Color(0, 200, 50, 10))
|
||||
end
|
||||
|
||||
local trData = {
|
||||
start = self.LastPos,
|
||||
endpos = phys:GetPos(),
|
||||
filter = {self:GetOwner(), self},
|
||||
mask = MASK_SHOT_PORTAL,
|
||||
collisiongroup = COLLISION_GROUP_NONE,
|
||||
mins = -self:OBBMaxs(),
|
||||
maxs = self:OBBMins()
|
||||
}
|
||||
|
||||
local tr = util.TraceHull(trData)
|
||||
|
||||
if (tr.Hit && (tr.Entity:IsPlayer() || tr.Entity:IsNPC())) then
|
||||
self:SetPos(tr.HitPos)
|
||||
self:Impact(tr,phys,true)
|
||||
self:ImpactDamage(tr.Entity)
|
||||
self:Explode(tr)
|
||||
return
|
||||
end
|
||||
|
||||
--Normal hitscan
|
||||
if (GetConVar("mgbase_debug_projectiles"):GetInt() > 0) then
|
||||
debugoverlay.Line(self.LastPos, phys:GetPos(), 1, Color(255, 0, 0, 1))
|
||||
end
|
||||
|
||||
tr = util.TraceLine(trData)
|
||||
|
||||
if (tr.Hit) then
|
||||
if tr.Entity:GetClass() == "func_breakable_surf" then
|
||||
--shatter glass windows and other weak surfaces
|
||||
util.BlastDamage(self, self, tr.HitPos, 1, 1)
|
||||
else
|
||||
self:SetPos(tr.HitPos)
|
||||
self:Impact(tr,phys,false)
|
||||
self:ImpactDamage(tr.Entity)
|
||||
self:Explode(tr)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.LastPos = phys:GetPos()
|
||||
end
|
||||
|
||||
function ENT:Explode(trData)
|
||||
|
||||
local phys = self:GetPhysicsObject()
|
||||
if (self:WaterLevel() <= 0) then
|
||||
if self.WeaponData.Explosive.BlastRadius >= 200 then
|
||||
ParticleEffect("Generic_explo_vhigh", phys:GetPos() + trData.HitNormal,Angle(0,0,0))
|
||||
else
|
||||
ParticleEffect("Generic_explo_high", phys:GetPos() + trData.HitNormal,Angle(0,0,0))
|
||||
end
|
||||
else
|
||||
local effectdata = EffectData()
|
||||
effectdata:SetOrigin(phys:GetPos())
|
||||
util.Effect("WaterSurfaceExplosion", effectdata)
|
||||
end
|
||||
|
||||
local dmgInfo = DamageInfo()
|
||||
dmgInfo:SetDamage(self.WeaponData.Bullet.Damage[1])
|
||||
dmgInfo:SetAttacker(IsValid(self:GetOwner()) && self:GetOwner() || self)
|
||||
dmgInfo:SetInflictor(self)
|
||||
dmgInfo:SetDamageType(self:GetDamageType())
|
||||
util.BlastDamageInfo(dmgInfo, phys:GetPos(), self.WeaponData.Explosive.BlastRadius)
|
||||
|
||||
util.ScreenShake(phys:GetPos(), 3500, 1111, 1, self.WeaponData.Explosive.BlastRadius * 4)
|
||||
|
||||
util.Decal("Scorch", trData.HitPos - trData.HitNormal, trData.HitPos + trData.HitNormal, self)
|
||||
|
||||
for i, e in pairs(ents.FindInSphere(self:GetPos(), 32)) do
|
||||
if (e:GetClass() == "npc_strider") then
|
||||
e:Fire("Explode")
|
||||
end
|
||||
end
|
||||
|
||||
self:Remove()
|
||||
end
|
||||
|
||||
function ENT:ImpactDamage(ent)
|
||||
-- local dmgInfo = DamageInfo()
|
||||
-- dmgInfo:SetDamage(self.WeaponData.Bullet.Damage[1] / self.WeaponData.Explosive.ImpactBlastRatio)
|
||||
-- dmgInfo:SetAttacker(IsValid(self:GetOwner()) && self:GetOwner() || self)
|
||||
-- dmgInfo:SetInflictor(self)
|
||||
-- dmgInfo:SetDamageType(self:GetDamageType())
|
||||
-- dmgInfo:SetDamagePosition(self:GetPos())
|
||||
-- ent:TakeDamageInfo(dmgInfo)
|
||||
end
|
||||
|
||||
function ENT:GetDamageType()
|
||||
return DMG_BLAST + DMG_AIRBOAT
|
||||
end
|
||||
|
||||
function ENT:Impact(tr, phys, bHull)
|
||||
if (IsValid(self.Weapon)) then
|
||||
self:FireBullets({
|
||||
Attacker = self:GetOwner(),
|
||||
Num = 1,
|
||||
Tracer = 0,
|
||||
Src = self.LastPos,
|
||||
Dir = (phys:GetPos() - self.LastPos):GetNormalized(),
|
||||
HullSize = bHull && 2 || 1,
|
||||
IgnoreEntity = self,
|
||||
Callback = function(attacker, tr, dmgInfo)
|
||||
dmgInfo:SetInflictor(self.Weapon)
|
||||
dmgInfo:SetDamageType(DMG_DIRECT + self:GetDamageType())
|
||||
self.Weapon:BulletCallback(attacker, tr, dmgInfo)
|
||||
end
|
||||
})
|
||||
end
|
||||
end
|
||||
62
lua/entities/mg_warhead/shared.lua
Normal file
62
lua/entities/mg_warhead/shared.lua
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
ENT.Base = "base_entity"
|
||||
ENT.Type = "anim"
|
||||
|
||||
ENT.Spawnable = false
|
||||
ENT.AdminOnly = false
|
||||
|
||||
ENT.ExplosionRadius = 430
|
||||
ENT.ExplosionDamage = 700
|
||||
|
||||
game.AddParticles("particles/explosion_fx_ins.pcf")
|
||||
game.AddParticles("particles/ins_rockettrail.pcf")
|
||||
PrecacheParticleSystem("ins_C4_explosion")
|
||||
PrecacheParticleSystem("ins_grenade_explosion")
|
||||
PrecacheParticleSystem("ins_m203_explosion")
|
||||
PrecacheParticleSystem("ins_rpg_explosion")
|
||||
PrecacheParticleSystem("rockettrail")
|
||||
PrecacheParticleSystem("Generic_explo_vhigh")
|
||||
|
||||
function ENT:SetupDataTables()
|
||||
end
|
||||
|
||||
--[[---------------------------------------------------------
|
||||
Name: Initialize
|
||||
Desc: First function called. Use to set up your entity
|
||||
-----------------------------------------------------------]]
|
||||
|
||||
function ENT:Initialize()
|
||||
self:SetModel("models/viper/mw/weapons/w_rpapa7_rocket.mdl")
|
||||
self:AddEFlags(EFL_FORCE_CHECK_TRANSMIT)
|
||||
self:SetCustomCollisionCheck(true)
|
||||
|
||||
if (SERVER) then
|
||||
self:PhysicsInit(SOLID_VPHYSICS)
|
||||
self:GetPhysicsObject():SetMaterial("metal")
|
||||
self:GetPhysicsObject():AddGameFlag(FVPHYSICS_NO_PLAYER_PICKUP)
|
||||
self:GetPhysicsObject():EnableDrag(false)
|
||||
self:GetPhysicsObject():EnableGravity(false)
|
||||
self:GetPhysicsObject():Wake()
|
||||
|
||||
self.Projectile = table.Copy(self.Weapon.Projectile)
|
||||
self.WeaponData = self.Weapon:GetTable()
|
||||
|
||||
self.m_Propel = true
|
||||
self.m_Fuel = self.Projectile.Fuel
|
||||
self.m_Stability = 0
|
||||
self.m_Water = false
|
||||
self.LastPos = self:GetOwner():EyePos()
|
||||
self.Target = ents.Create("info_target")
|
||||
self.Target:Spawn()
|
||||
|
||||
if self.WeaponData.TrackedEntity then
|
||||
self.m_Tracking = self.Projectile.Tracking
|
||||
self.TrackedEntity = self.WeaponData.TrackedEntity
|
||||
end
|
||||
end
|
||||
|
||||
if (CLIENT) then
|
||||
self.m_SpawnPos = self:GetPos()
|
||||
self:EmitSound("^viper/shared/move_rpapa7_proj_flame_cls.wav", SNDLVL_180db, 100, 1, CHAN_WEAPON)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user