Залив
This commit is contained in:
69
lua/entities/mg_bullet/cl_init.lua
Normal file
69
lua/entities/mg_bullet/cl_init.lua
Normal file
@@ -0,0 +1,69 @@
|
||||
include("shared.lua")
|
||||
|
||||
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
|
||||
ENT.bWhizz = false
|
||||
|
||||
local flareMaterial = Material("sprites/orangecore1_gmod")
|
||||
|
||||
function ENT:DrawTranslucent(flags)
|
||||
self:DestroyShadow()
|
||||
|
||||
if (self:GetVelocity():Length() <= 1) then
|
||||
return
|
||||
end
|
||||
|
||||
self:DrawLight()
|
||||
self:DrawTracer()
|
||||
self:DrawBullet()
|
||||
end
|
||||
|
||||
function ENT:DrawLight()
|
||||
local dlight = DynamicLight(self:EntIndex())
|
||||
if (dlight) then
|
||||
dlight.pos = self:GetPos()
|
||||
dlight.r = 255
|
||||
dlight.g = 155
|
||||
dlight.b = 0
|
||||
dlight.brightness = 2
|
||||
dlight.Decay = 500
|
||||
dlight.Size = 128
|
||||
dlight.DieTime = CurTime() + 0.1
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:DrawBullet()
|
||||
local angle = (self:GetPos() - EyePos()):Angle()
|
||||
angle:RotateAroundAxis(EyeAngles():Right(), 90)
|
||||
|
||||
local dist = math.min(self:GetPos():Distance(EyePos()), 300)
|
||||
|
||||
cam.Start3D2D(self:GetPos(), angle, dist * 0.0004)
|
||||
surface.SetDrawColor(255, 255, 255, 255)
|
||||
surface.SetMaterial(flareMaterial)
|
||||
surface.DrawTexturedRectRotated(0, 0, 32, 32, 0)
|
||||
cam.End3D2D()
|
||||
end
|
||||
|
||||
function ENT:DrawTracer()
|
||||
local angle = self:GetAngles()
|
||||
angle:RotateAroundAxis(self:GetAngles():Forward(), 90)
|
||||
|
||||
cam.Start3D2D(self:GetPos(), angle, 0.15)
|
||||
surface.SetDrawColor(255, 255, 255, 255)
|
||||
surface.SetMaterial(flareMaterial)
|
||||
surface.DrawTexturedRectUV(-512, -3, 512, 6, 0, 0, 0.5, 1)
|
||||
cam.End3D2D()
|
||||
end
|
||||
|
||||
function ENT:Think()
|
||||
if (!IsValid(GetViewEntity())) then
|
||||
return
|
||||
end
|
||||
|
||||
local bInRadius = EyePos():DistToSqr(self:GetPos()) < 128 * 128
|
||||
|
||||
if (bInRadius && !self.bWhizz && self:GetOwner() != GetViewEntity()) then
|
||||
GetViewEntity():EmitSound("Bullets.DefaultNearmiss")
|
||||
self.bWhizz = true
|
||||
end
|
||||
end
|
||||
112
lua/entities/mg_bullet/init.lua
Normal file
112
lua/entities/mg_bullet/init.lua
Normal file
@@ -0,0 +1,112 @@
|
||||
AddCSLuaFile("cl_init.lua")
|
||||
AddCSLuaFile("shared.lua")
|
||||
|
||||
include("shared.lua")
|
||||
|
||||
ENT.bCollided = false
|
||||
ENT.Projectile = {
|
||||
Class = "mg_bullet",
|
||||
Speed = 4000,
|
||||
Gravity = 1
|
||||
}
|
||||
ENT.Maxs = Vector(6, 6, 6)
|
||||
|
||||
function ENT:Initialize()
|
||||
self:SetModel("models/weapons/ar2_grenade.mdl")
|
||||
self:PhysicsInitBox(Vector(-1, -1, -1), Vector(1, 1, 1))
|
||||
self:GetPhysicsObject():Wake()
|
||||
self:GetPhysicsObject():SetMaterial("default_silent")
|
||||
self:GetPhysicsObject():AddGameFlag(FVPHYSICS_NO_PLAYER_PICKUP)
|
||||
self:GetPhysicsObject():AddGameFlag(FVPHYSICS_NO_IMPACT_DMG)
|
||||
self:GetPhysicsObject():AddGameFlag(FVPHYSICS_HEAVY_OBJECT)
|
||||
self:GetPhysicsObject():EnableMotion(true)
|
||||
self:GetPhysicsObject():EnableDrag(false)
|
||||
self:GetPhysicsObject():SetMass(1000)
|
||||
self:SetSolid(SOLID_VPHYSICS)
|
||||
self:SetCollisionGroup(COLLISION_GROUP_IN_VEHICLE) --doesn't collide with anything, no traces
|
||||
self:AddEFlags(EFL_NO_DAMAGE_FORCES)
|
||||
self:AddEFlags(EFL_DONTWALKON)
|
||||
self:AddEFlags(EFL_DONTBLOCKLOS)
|
||||
self:AddEFlags(EFL_NO_PHYSCANNON_INTERACTION)
|
||||
|
||||
self.Projectile = table.Copy(self.Weapon.Projectile)
|
||||
self:GetPhysicsObject():SetVelocityInstantaneous(self:GetAngles():Forward() * self.Projectile.Speed)
|
||||
self.LastPos = self:GetOwner():EyePos()
|
||||
end
|
||||
|
||||
function ENT:Think()
|
||||
if (self.bCollided && IsValid(self)) then
|
||||
self:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
function ENT:PhysicsUpdate(phys)
|
||||
phys:AddVelocity(Vector(0, 0, self.Projectile.Gravity))
|
||||
|
||||
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_PROJECTILE,
|
||||
mins = -self.Maxs,
|
||||
maxs = self.Maxs
|
||||
}
|
||||
|
||||
local tr = util.TraceHull(trData)
|
||||
if (tr.Hit && (tr.Entity:IsPlayer() || tr.Entity:IsNPC())) then
|
||||
self:Impact(tr, phys, true)
|
||||
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
|
||||
self:Impact(tr, phys, false)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
self.LastPos = phys:GetPos()
|
||||
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 && self.Maxs:Length() * 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
|
||||
|
||||
self:Kill()
|
||||
end
|
||||
|
||||
function ENT:Kill()
|
||||
self.bCollided = true
|
||||
self:SetNoDraw(true)
|
||||
self:GetPhysicsObject():EnableMotion(false)
|
||||
end
|
||||
|
||||
function ENT:GetDamageType()
|
||||
return DMG_BULLET
|
||||
end
|
||||
5
lua/entities/mg_bullet/shared.lua
Normal file
5
lua/entities/mg_bullet/shared.lua
Normal file
@@ -0,0 +1,5 @@
|
||||
ENT.Base = "base_entity"
|
||||
ENT.Type = "anim"
|
||||
|
||||
ENT.Spawnable = false
|
||||
ENT.AdminOnly = false
|
||||
Reference in New Issue
Block a user