Files
wnsrc/lua/simfphys_weapons/conscript_apc.lua
lifestorm 9c918c46e5 Upload
2024-08-04 23:12:27 +03:00

179 lines
4.9 KiB
Lua

--[[
| This file was obtained through the combined efforts
| of Madbluntz & Plymouth Antiquarian Society.
|
| Credits: lifestorm, Gregory Wayne Rossel JR.,
| Maloy, DrPepper10 @ RIP, Atle!
|
| Visit for more: https://plymouth.thetwilightzone.ru/
--]]
local function mg_fire(ply,vehicle,shootOrigin,shootDirection)
vehicle:EmitSound("apc_fire")
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.attackingent = vehicle
projectile.Damage = 100
projectile.Force = 50
projectile.Size = 3
projectile.BlastRadius = 50
projectile.BlastDamage = 50
projectile.DeflectAng = 40
projectile.BlastEffect = "simfphys_tankweapon_explosion_micro"
simfphys.FirePhysProjectile( projectile )
end
function simfphys.weapon:ValidClasses()
local classes = {
"sim_fphys_conscriptapc_armed"
}
return classes
end
function simfphys.weapon:Initialize( vehicle )
local data = {}
data.Attachment = "muzzle_left"
data.Direction = Vector(1,0,0)
data.Attach_Start_Left = "muzzle_right"
data.Attach_Start_Right = "muzzle_left"
data.Type = 3
vehicle.MaxMag = 30
vehicle:SetNWString( "WeaponMode", tostring( vehicle.MaxMag ) )
simfphys.RegisterCrosshair( vehicle:GetDriverSeat(), data )
simfphys.RegisterCamera( vehicle:GetDriverSeat(), Vector(13,45,50), Vector(13,45,50), true )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
for i = 2, table.Count( vehicle.pSeat ) do
simfphys.RegisterCamera( vehicle.pSeat[ i ], Vector(0,0,60), Vector(0,0,60) )
end
end
function simfphys.weapon:AimWeapon( ply, vehicle, pod )
local Aimang = pod:WorldToLocalAngles( ply:EyeAngles() )
local AimRate = 100
local Angles = vehicle:WorldToLocalAngles( Aimang ) - Angle(0,90,0)
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw and math.ApproachAngle( vehicle.sm_pp_yaw, Angles.y, AimRate * FrameTime() ) or 0
vehicle.sm_pp_pitch = vehicle.sm_pp_pitch and math.ApproachAngle( vehicle.sm_pp_pitch, Angles.p, AimRate * FrameTime() ) or 0
local TargetAng = Angle(vehicle.sm_pp_pitch,vehicle.sm_pp_yaw,0)
TargetAng:Normalize()
vehicle:SetPoseParameter("turret_yaw", TargetAng.y )
vehicle:SetPoseParameter("turret_pitch", -TargetAng.p )
end
function simfphys.weapon:Think( vehicle )
local pod = vehicle:GetDriverSeat()
if not IsValid( pod ) then return end
local ply = pod:GetDriver()
local curtime = CurTime()
if not IsValid( ply ) then
if vehicle.wpn then
vehicle.wpn:Stop()
vehicle.wpn = nil
end
return
end
self:AimWeapon( ply, vehicle, pod )
local fire = ply:KeyDown( IN_ATTACK )
local reload = ply:KeyDown( IN_RELOAD )
if fire then
self:PrimaryAttack( vehicle, ply, shootOrigin )
end
if reload then
self:ReloadPrimary( vehicle )
end
end
function simfphys.weapon:ReloadPrimary( vehicle )
if not IsValid( vehicle ) then return end
if vehicle.CurMag == vehicle.MaxMag then return end
vehicle.CurMag = vehicle.MaxMag
vehicle:EmitSound("simulated_vehicles/weapons/apc_reload.wav")
self:SetNextPrimaryFire( vehicle, CurTime() + 2 )
vehicle:SetNWString( "WeaponMode", tostring( vehicle.CurMag ) )
vehicle:SetIsCruiseModeOn( false )
end
function simfphys.weapon:TakePrimaryAmmo( vehicle )
vehicle.CurMag = isnumber( vehicle.CurMag ) and vehicle.CurMag - 1 or vehicle.MaxMag
vehicle:SetNWString( "WeaponMode", tostring( vehicle.CurMag ) )
end
function simfphys.weapon:CanPrimaryAttack( vehicle )
vehicle.CurMag = isnumber( vehicle.CurMag ) and vehicle.CurMag or vehicle.MaxMag
if vehicle.CurMag <= 0 then
self:ReloadPrimary( vehicle )
return false
end
vehicle.NextShoot = vehicle.NextShoot or 0
return vehicle.NextShoot < CurTime()
end
function simfphys.weapon:SetNextPrimaryFire( vehicle, time )
vehicle.NextShoot = time
end
function simfphys.weapon:PrimaryAttack( vehicle, ply )
if not self:CanPrimaryAttack( vehicle ) then return end
vehicle.wOldPos = vehicle.wOldPos or vehicle:GetPos()
local deltapos = vehicle:GetPos() - vehicle.wOldPos
vehicle.wOldPos = vehicle:GetPos()
if vehicle.swapMuzzle then
vehicle.swapMuzzle = false
else
vehicle.swapMuzzle = true
end
local AttachmentID = vehicle.swapMuzzle and vehicle:LookupAttachment( "muzzle_right" ) or vehicle:LookupAttachment( "muzzle_left" )
local Attachment = vehicle:GetAttachment( AttachmentID )
local shootOrigin = Attachment.Pos + deltapos * engine.TickInterval()
local shootDirection = Attachment.Ang:Forward()
local effectdata = EffectData()
effectdata:SetOrigin( shootOrigin )
effectdata:SetAngles( Attachment.Ang )
effectdata:SetEntity( vehicle )
effectdata:SetAttachment( AttachmentID )
effectdata:SetScale( 4 )
util.Effect( "CS_MuzzleFlash", effectdata, true, true )
mg_fire( ply, vehicle, shootOrigin, shootDirection )
self:TakePrimaryAmmo( vehicle )
self:SetNextPrimaryFire( vehicle, CurTime() + 0.2 )
end