This commit is contained in:
lifestorm
2024-08-05 18:40:29 +03:00
parent c4d91bf369
commit 324f19217d
8040 changed files with 1853423 additions and 21 deletions

View File

@@ -0,0 +1,190 @@
--[[
| 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 AirboatFire(ply,vehicle,shootOrigin,Attachment,damage)
local bullet = {}
bullet.Src = shootOrigin
bullet.Dir = Attachment.Ang:Forward()
bullet.Spread = Vector(0.04,0.04,0.04)
bullet.TracerName = "lvs_ar2_tracer"
bullet.Force = damage
bullet.HullSize = 1
bullet.Damage = damage
bullet.Velocity = 12000
bullet.Attacker = ply
bullet.Callback = function(att, tr, dmginfo)
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos + tr.HitNormal )
effectdata:SetNormal( tr.HitNormal * 2 )
effectdata:SetRadius( 10 )
util.Effect( "cball_bounce", effectdata, true, true )
end
vehicle:LVSFireBullet( bullet )
end
function simfphys.weapon:ValidClasses()
local classes = {
"sim_fphys_jeep_armed2",
"sim_fphys_v8elite_armed2"
}
return classes
end
function simfphys.weapon:Initialize( vehicle )
--vehicle:SetBodygroup(1,1)
local ID = vehicle:LookupAttachment( "gun_ref" )
local attachmentdata = vehicle:GetAttachment( ID )
local prop = ents.Create( "gmod_sent_vehicle_fphysics_attachment" )
prop:SetModel( "models/airboatgun.mdl" )
prop:SetPos( attachmentdata.Pos )
prop:SetAngles( attachmentdata.Ang )
prop:SetModelScale( 0.5 )
prop:Spawn()
prop:Activate()
prop:SetNotSolid( true )
prop:SetParent( vehicle, ID )
prop.DoNotDuplicate = true
simfphys.RegisterCrosshair( vehicle:GetDriverSeat() )
simfphys.SetOwner( vehicle.EntityOwner, prop )
end
function simfphys.weapon:AimWeapon( ply, vehicle, pod )
local Aimang = ply:EyeAngles()
local AimRate = 250
local Angles = angle_zero
if ply:lvsMouseAim() then
local ang = vehicle:GetAngles()
ang.y = pod:GetAngles().y + 90
local Forward = ang:Right()
local View = pod:WorldToLocalAngles( Aimang )
local Pitch = (vehicle:AngleBetweenNormal( View:Up(), ang:Forward() ) - 90)
local Yaw = (vehicle:AngleBetweenNormal( View:Forward(), ang:Right() ) - 90)
Angles = Angle(-Pitch,Yaw,0)
else
Angles = vehicle:WorldToLocalAngles( Aimang ) - Angle(0,90,0)
Angles:Normalize()
end
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("vehicle_weapon_yaw", -TargetAng.y )
vehicle:SetPoseParameter("vehicle_weapon_pitch", -TargetAng.p )
return Aimang
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
local ID = vehicle:LookupAttachment( "muzzle" )
local Attachment = vehicle:GetAttachment( ID )
self:AimWeapon( ply, vehicle, pod )
vehicle.wOldPos = vehicle.wOldPos or Vector(0,0,0)
local deltapos = vehicle:GetPos() - vehicle.wOldPos
vehicle.wOldPos = vehicle:GetPos()
local shootOrigin = Attachment.Pos + deltapos * engine.TickInterval()
vehicle.charge = vehicle.charge or 100
local fire = ply:KeyDown( IN_ATTACK ) and vehicle.charge > 0
if fire then
self:PrimaryAttack( vehicle, ply, shootOrigin, Attachment, ID )
else
vehicle.charge = math.min(vehicle.charge + 0.3,100)
end
vehicle.OldFire = vehicle.OldFire or false
if vehicle.OldFire ~= fire then
vehicle.OldFire = fire
if fire then
vehicle.wpn = CreateSound( vehicle, "weapons/airboat/airboat_gun_loop2.wav" )
vehicle.wpn:Play()
vehicle:CallOnRemove( "stopmesounds", function( vehicle )
if vehicle.wpn then
vehicle.wpn:Stop()
end
end)
else
if vehicle.wpn then
vehicle.wpn:Stop()
vehicle.wpn = nil
end
vehicle:EmitSound("weapons/airboat/airboat_gun_lastshot"..math.random(1,2)..".wav")
end
end
end
function simfphys.weapon:CanPrimaryAttack( vehicle )
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, shootOrigin, Attachment, ID )
if not self:CanPrimaryAttack( vehicle ) then return end
local effectdata = EffectData()
effectdata:SetOrigin( shootOrigin )
effectdata:SetAngles( Attachment.Ang )
effectdata:SetEntity( vehicle )
effectdata:SetAttachment( ID )
effectdata:SetScale( 1 )
util.Effect( "AirboatMuzzleFlash", effectdata, true, true )
AirboatFire(ply,vehicle,shootOrigin,Attachment,(vehicle.charge / 5))
vehicle.charge = vehicle.charge - 0.5
if vehicle.charge <= 0 then
if vehicle.charge > -1 then
vehicle:EmitSound("weapons/airboat/airboat_gun_energy"..math.Round(math.random(1,2),0)..".wav")
end
vehicle.charge = -50
end
self:SetNextPrimaryFire( vehicle, CurTime() + 0.05 )
end

View File

@@ -0,0 +1,182 @@
--[[
| 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 cAPCFire(ply,vehicle,shootOrigin,Attachment,damage,ID)
local effectdata = EffectData()
effectdata:SetOrigin( shootOrigin )
effectdata:SetAngles( Attachment.Ang )
effectdata:SetEntity( vehicle )
effectdata:SetAttachment( ID )
effectdata:SetScale( 1 )
util.Effect( "AirboatMuzzleFlash", effectdata, true, true )
local bullet = {}
bullet.Src = shootOrigin
bullet.Dir = Attachment.Ang:Forward()
bullet.Spread = Vector(0.015,0.015,0.015)
bullet.TracerName = "lvs_ar2_tracer"
bullet.Force = damage
bullet.HullSize = 6
bullet.Damage = damage
bullet.Velocity = 12000
bullet.Attacker = ply
bullet.Callback = function(att, tr, dmginfo)
local effectdata = EffectData()
effectdata:SetOrigin( tr.HitPos + tr.HitNormal )
effectdata:SetNormal( tr.HitNormal * 2 )
effectdata:SetRadius( 10 )
util.Effect( "cball_bounce", effectdata, true, true )
end
vehicle:LVSFireBullet( bullet )
end
function simfphys.weapon:ValidClasses()
local classes = {
"sim_fphys_combineapc_armed"
}
return classes
end
function simfphys.weapon:Initialize( vehicle )
local pod = vehicle:GetDriverSeat()
simfphys.RegisterCrosshair( pod )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
for i = 1, table.Count( vehicle.pSeat ) do
simfphys.RegisterCamera( vehicle.pSeat[ i ], Vector(0,30,60), Vector(0,-20,60) )
end
end
function simfphys.weapon:AimWeapon( ply, vehicle, pod )
local Aimang = ply:EyeAngles()
local AimRate = 250
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("vehicle_weapon_yaw", TargetAng.y )
vehicle:SetPoseParameter("vehicle_weapon_pitch", TargetAng.p )
return Aimang
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
local ID = vehicle:LookupAttachment( "muzzle" )
local Attachment = vehicle:GetAttachment( ID )
local Aimang = self:AimWeapon( ply, vehicle, pod )
local tr = util.TraceLine( {
start = Attachment.Pos,
endpos = Attachment.Pos + Aimang:Forward() * 10000,
filter = {vehicle}
} )
local Aimpos = tr.HitPos
vehicle.wOldPos = vehicle.wOldPos or Vector(0,0,0)
local deltapos = vehicle:GetPos() - vehicle.wOldPos
vehicle.wOldPos = vehicle:GetPos()
local shootOrigin = Attachment.Pos + deltapos * engine.TickInterval()
vehicle.charge = vehicle.charge or 100
local fire = ply:KeyDown( IN_ATTACK ) and vehicle.charge > 0
local alt_fire = ply:KeyDown( IN_ATTACK2 )
if not fire then
vehicle.charge = math.min(vehicle.charge + 0.4,100)
end
vehicle.NextSecondaryShoot = vehicle.NextSecondaryShoot or 0
if alt_fire ~= vehicle.afire_pressed then
vehicle.afire_pressed = alt_fire
if alt_fire then
if vehicle.NextSecondaryShoot < curtime then
if not IsValid(vehicle.missle) then
vehicle:EmitSound("PropAPC.FireCannon")
local attch = vehicle:GetAttachment( vehicle:LookupAttachment( "cannon_muzzle" ) )
vehicle.missle = ents.Create( "rpg_missile" ) -- need to make my own projectile entity at some point
vehicle.missle:SetPos( attch.Pos )
vehicle.missle:SetAngles( attch.Ang - Angle(15,0,0) )
vehicle.missle:SetOwner( vehicle )
vehicle.missle:SetSaveValue( "m_flDamage", 250 )
vehicle.missle:Spawn()
vehicle.missle:Activate()
vehicle.missle.DirVector = vehicle.missle:GetAngles():Forward()
vehicle.NextSecondaryShoot = curtime + 2
vehicle.UnlockMissle = curtime + 0.5
end
end
end
end
if IsValid( vehicle.missle ) then
if vehicle.UnlockMissle < curtime then
local targetdir = Aimpos - vehicle.missle:GetPos()
targetdir:Normalize()
vehicle.missle.DirVector = vehicle.missle.DirVector + (targetdir - vehicle.missle.DirVector) * 0.1
local vel = -vehicle.missle:GetVelocity() + vehicle.missle.DirVector * 1500 + vehicle:GetVelocity()
vehicle.missle:SetVelocity( vel )
vehicle.missle:SetAngles( vehicle.missle.DirVector:Angle() )
end
end
vehicle.NextShoot = vehicle.NextShoot or 0
if vehicle.NextShoot < curtime then
if fire then
cAPCFire(ply,vehicle,shootOrigin,Attachment,25,ID)
vehicle:EmitSound("Weapon_AR2.Single")
vehicle.charge = vehicle.charge - 2.5
if vehicle.charge <= 0 then
if vehicle.charge >= -6 then
vehicle:EmitSound("weapons/airboat/airboat_gun_energy"..math.Round(math.random(1,2),0)..".wav")
end
vehicle.charge = -25
end
vehicle.NextShoot = curtime + 0.12
end
end
end

View File

@@ -0,0 +1,178 @@
--[[
| 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

View File

@@ -0,0 +1,359 @@
--[[
| 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 hmgfire(ply,vehicle,shootOrigin,shootDirection)
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.Tracer = 1
projectile.Spread = Vector(0.015,0.015,0.015)
projectile.HullSize = 5
projectile.attackingent = vehicle
projectile.Damage = 30
projectile.Force = 12
simfphys.FireHitScan( projectile )
end
local function minigunfire(ply,vehicle,shootOrigin,shootDirection)
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.Tracer = 1
projectile.Spread = Vector(0.015,0.015,0.015)
projectile.HullSize = 5
projectile.attackingent = vehicle
projectile.Damage = 40
projectile.Force = 12
simfphys.FireHitScan( projectile )
end
function simfphys.weapon:ValidClasses()
local classes = {
"sim_fphys_ratmobile",
"sim_fphys_hedgehog",
"sim_fphys_chaos126p"
}
return classes
end
function simfphys.weapon:Initialize( vehicle )
local class = vehicle:GetSpawn_List()
vehicle.neg = class == "sim_fphys_ratmobile" and 1 or -1
local data = {}
data.Attachment = "machinegun_ref"
data.Direction = Vector(1,0,0)
data.Attach_Start_Left = "machinegun_barell_right"
data.Attach_Start_Right = "machinegun_barell_left"
simfphys.RegisterCrosshair( vehicle:GetDriverSeat(), data )
vehicle:SetNWString( "WeaponMode", "Machine Gun Turret" )
end
function simfphys.weapon:Think( vehicle )
vehicle.VehicleData["steerangle"] = 45
local curtime = CurTime()
local DriverSeat = vehicle:GetDriverSeat()
if not IsValid( DriverSeat ) then return end
local ply = DriverSeat:GetDriver()
if not IsValid(ply) then
if vehicle.wpn then
vehicle.wpn:Stop()
vehicle.wpn = nil
end
if vehicle.wpn2 then
vehicle.wpn2:Stop()
vehicle.wpn2 = nil
end
return
end
vehicle.wOldPos = vehicle.wOldPos or vehicle:GetPos()
local deltapos = vehicle:GetPos() - vehicle.wOldPos
vehicle.wOldPos = vehicle:GetPos()
local ID = vehicle:LookupAttachment( "machinegun_ref" )
local Attachment = vehicle:GetAttachment( ID )
local Angles = angle_zero
if ply:lvsMouseAim() then
local TargetAngle = ply:EyeAngles()
local ang = vehicle:GetAngles()
ang.y = DriverSeat:GetAngles().y + 90
local Forward = ang:Right()
local View = DriverSeat:WorldToLocalAngles( TargetAngle )
local Pitch = (vehicle:AngleBetweenNormal( View:Up(), ang:Forward() ) - 90)
local Yaw = (vehicle:AngleBetweenNormal( View:Forward(), ang:Right() ) - 90)
Angles = Angle(-Pitch,Yaw,0)
else
Angles = vehicle:WorldToLocalAngles( ply:EyeAngles() )
Angles:Normalize()
end
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw and (vehicle.sm_pp_yaw + (Angles.y - vehicle.sm_pp_yaw) * 0.2) or 0
vehicle.sm_pp_pitch = vehicle.sm_pp_pitch and (vehicle.sm_pp_pitch + (Angles.p - vehicle.sm_pp_pitch) * 0.2) or 0
vehicle:SetPoseParameter("vehicle_weapon_yaw", vehicle.sm_pp_yaw )
vehicle:SetPoseParameter("vehicle_weapon_pitch", -vehicle.sm_pp_pitch )
local tr = util.TraceLine( {
start = Attachment.Pos,
endpos = Attachment.Pos + Attachment.Ang:Forward() * 50000,
filter = {vehicle}
} )
local Aimpos = tr.HitPos
local AttachmentID_Left = vehicle:LookupAttachment( "machinegun_barell_left" )
local AttachmentID_Right = vehicle:LookupAttachment( "machinegun_barell_right" )
local Attachment_Left = vehicle:GetAttachment( AttachmentID_Left )
local Attachment_Right = vehicle:GetAttachment( AttachmentID_Right )
local pos1 = Attachment_Left.Pos
local pos2 = Attachment_Right.Pos
local Aimang = (Aimpos - (pos1 + pos2) * 0.5):Angle()
local Angles = vehicle:WorldToLocalAngles( Aimang )
Angles:Normalize()
vehicle:SetPoseParameter("vehicle_minigun_yaw", Angles.y )
vehicle:SetPoseParameter("vehicle_minigun_pitch", Angles.p * vehicle.neg )
local keyattack = ply:KeyDown( IN_ATTACK ) and not vehicle.lockweapons and (vehicle:GetNWInt( "CurWPNAmmo", -1 ) > 0)
local alt_fire = ply:KeyDown( IN_ATTACK2 )
local reload = ply:KeyDown( IN_RELOAD )
vehicle.FireMode = vehicle.FireMode or 0
vehicle.missle_ammo = vehicle.missle_ammo or 6
vehicle.mg_ammo = vehicle.mg_ammo or 1500
vehicle.rac_ammo = vehicle.rac_ammo or 300
if vehicle.FireMode == 0 then
vehicle:SetNWInt( "CurWPNAmmo", vehicle.mg_ammo )
elseif vehicle.FireMode == 1 then
vehicle:SetNWInt( "CurWPNAmmo", vehicle.rac_ammo )
else
vehicle:SetNWInt( "CurWPNAmmo", vehicle.missle_ammo )
end
if reload and (vehicle.missle_ammo ~= 6 or vehicle.mg_ammo ~= 1500 or vehicle.rac_ammo ~= 300) then
vehicle:EmitSound("simulated_vehicles/weapons/apc_reload.wav")
vehicle.missle_ammo = 6
vehicle.mg_ammo = 1500
vehicle.rac_ammo = 300
vehicle.lockweapons = true
vehicle:SetIsCruiseModeOn( false )
timer.Simple( 3, function()
if not IsValid( vehicle ) then return end
vehicle.lockweapons = false
vehicle:SetIsCruiseModeOn( false )
vehicle:EmitSound("simulated_vehicles/weapons/leopard_ready.wav")
end)
end
if alt_fire ~= vehicle.afire_pressed then
vehicle.afire_pressed = alt_fire
if alt_fire then
vehicle.FireMode = vehicle.FireMode + 1
if vehicle.FireMode >= 3 then
vehicle.FireMode = 0
end
if vehicle.FireMode == 0 then
vehicle:EmitSound("weapons/smg1/switch_burst.wav")
vehicle:SetNWString( "WeaponMode", "Machine Gun Turret" )
elseif vehicle.FireMode == 1 then
vehicle:EmitSound("weapons/357/357_spin1.wav")
vehicle:SetNWString( "WeaponMode", "Minigun" )
else
vehicle:EmitSound("weapons/shotgun/shotgun_cock.wav")
vehicle:SetNWString( "WeaponMode", "Missiles" )
end
end
end
local fire = vehicle.FireMode == 0 and keyattack
local fire2 = vehicle.FireMode == 1 and keyattack
local fire3 = vehicle.FireMode == 2 and keyattack
vehicle.smoothaltfire = vehicle.smoothaltfire and (vehicle.smoothaltfire + ((fire2 and 20 or 0) - vehicle.smoothaltfire) * 0.1) or 0
vehicle.minigunspin = vehicle.minigunspin and (vehicle.minigunspin + vehicle.smoothaltfire) or 0
vehicle:SetPoseParameter("vehicle_minigun_spin", vehicle.minigunspin )
vehicle.NextShoot = vehicle.NextShoot or 0
if fire then
if vehicle.NextShoot < curtime then
vehicle.mg_ammo = vehicle.mg_ammo - 1
if vehicle.swapMuzzle then
vehicle.swapMuzzle = false
else
vehicle.swapMuzzle = true
end
local offset = deltapos * engine.TickInterval()
local AttachmentID = vehicle.swapMuzzle and AttachmentID_Left or AttachmentID_Right
local Attachment = vehicle:GetAttachment( AttachmentID )
local shootOrigin = Attachment.Pos + offset
local shootDirection = Attachment.Ang:Forward()
hmgfire( ply, vehicle, shootOrigin, Attachment.Ang:Forward() )
vehicle.NextShoot = curtime + 0.08
end
end
if fire2 then
if vehicle.NextShoot < curtime then
vehicle.rac_ammo = vehicle.rac_ammo - 1
local offset = deltapos * engine.TickInterval()
local muzzle_1 = vehicle:LookupAttachment( "minigun_barell_right" )
local muzzle_2 = vehicle:LookupAttachment( "minigun_barell_left" )
local muzzles = {muzzle_1,muzzle_2}
for k, v in pairs( muzzles ) do
local AttachmentID = v
local Attachment = vehicle:GetAttachment( AttachmentID )
local shootOrigin = Attachment.Pos + offset
local shootDirection = Attachment.Ang:Forward()
minigunfire( ply, vehicle, shootOrigin, shootDirection )
end
vehicle.NextShoot = curtime + 0.03
end
end
vehicle.OldFire = vehicle.OldFire or false
vehicle.OldFire2 = vehicle.OldFire2 or false
vehicle.OldFire3 = vehicle.OldFire3 or false
if vehicle.OldFire ~= fire then
vehicle.OldFire = fire
if fire then
vehicle.wpn = CreateSound( vehicle, "simulated_vehicles/weapons/diprip/machinegun_loop.wav" )
vehicle.wpn:Play()
vehicle:CallOnRemove( "stop_fire1_sounds", function( vehicle )
if vehicle.wpn then
vehicle.wpn:Stop()
end
end)
else
if vehicle.wpn then
vehicle.wpn:Stop()
vehicle.wpn = nil
end
end
end
if vehicle.OldFire2 ~= fire2 then
vehicle.OldFire2 = fire2
if fire2 then
vehicle.wpn2 = CreateSound( vehicle, "simulated_vehicles/weapons/diprip/minigun_loop.wav" )
vehicle.wpn2:Play()
vehicle:CallOnRemove( "stop_fire2_sounds", function( vehicle )
if vehicle.wpn2 then
vehicle.wpn2:Stop()
end
end)
else
if vehicle.wpn2 then
vehicle.wpn2:Stop()
vehicle.wpn2 = nil
end
end
end
if vehicle.OldFire3 ~= fire3 then
vehicle.OldFire3 = fire3
if fire3 then
if vehicle.NextShoot < curtime then
if not IsValid(vehicle.missle) then
vehicle:EmitSound("simulated_vehicles/weapons/diprip/rocket.wav")
vehicle.missle_ammo = vehicle.missle_ammo - 1
if vehicle.swapMuzzle then
vehicle.swapMuzzle = false
else
vehicle.swapMuzzle = true
end
local attach = vehicle.swapMuzzle and vehicle:GetAttachment( vehicle:LookupAttachment( "rocket_barell_right" ) ) or vehicle:GetAttachment( vehicle:LookupAttachment( "rocket_barell_left" ) )
vehicle.missle = ents.Create( "rpg_missile" )
vehicle.missle:SetPos( attach.Pos + attach.Ang:Up() * 25 )
vehicle.missle:SetAngles( attach.Ang - Angle(10,0,0) )
vehicle.missle:SetOwner( vehicle )
vehicle.missle:SetSaveValue( "m_flDamage", 120 )
vehicle.missle:Spawn()
vehicle.missle:Activate()
vehicle.missle.DirVector = vehicle.missle:GetAngles():Forward()
vehicle.NextShoot = curtime + 0.5
vehicle.UnlockMissle = curtime + 0.5
end
end
end
end
if IsValid(vehicle.missle) then
if vehicle.UnlockMissle < curtime then
local targetdir = Aimpos - vehicle.missle:GetPos()
targetdir:Normalize()
vehicle.missle.DirVector = vehicle.missle.DirVector + (targetdir - vehicle.missle.DirVector) * 0.1
local vel = -vehicle.missle:GetVelocity() + vehicle.missle.DirVector * 2500 + vehicle:GetVelocity()
vehicle.missle:SetVelocity( vel )
vehicle.missle:SetAngles( vehicle.missle.DirVector:Angle() )
end
end
end

View File

@@ -0,0 +1,540 @@
--[[
| 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 leopard_susdata = {}
for i = 1,7 do
leopard_susdata[i] = {
attachment = "sus_left_attach_"..i,
poseparameter = "suspension_left_"..i,
}
local ir = i + 7
leopard_susdata[ir] = {
attachment = "sus_right_attach_"..i,
poseparameter = "suspension_right_"..i,
}
end
local function hmg_fire(ply,vehicle,shootOrigin,shootDirection)
vehicle:EmitSound("leopard_fire_mg")
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.Tracer = 1
projectile.HullSize = 6
projectile.attackingent = vehicle
projectile.Spread = Vector(0.01,0.01,0.01)
projectile.Damage = 25
projectile.Force = 12
simfphys.FireHitScan( projectile )
end
local function mg_fire(ply,vehicle,shootOrigin,shootDirection)
vehicle:EmitSound("tiger_fire_mg_new")
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.Tracer = 1
projectile.HullSize = 5
projectile.attackingent = vehicle
projectile.Spread = Vector(0.008,0.008,0.008)
projectile.Damage = 20
projectile.Force = 12
simfphys.FireHitScan( projectile )
end
local function cannon_fire(ply,vehicle,shootOrigin,shootDirection)
vehicle:EmitSound("leopard_fire")
vehicle:EmitSound("sherman_reload")
timer.Simple( 4, function()
if IsValid( vehicle ) then
vehicle:EmitSound("simulated_vehicles/weapons/leopard_ready.wav")
end
end)
local effectdata = EffectData()
effectdata:SetEntity( vehicle )
util.Effect( "simfphys_leopard_muzzle", effectdata )
vehicle:GetPhysicsObject():ApplyForceOffset( -shootDirection * 500000, shootOrigin )
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.attackingent = vehicle
projectile.Damage = 3500
projectile.Force = 8000
projectile.Size = 15
projectile.DeflectAng = 20
projectile.BlastRadius = 300
projectile.BlastDamage = 1000
projectile.BlastEffect = "simfphys_tankweapon_explosion"
simfphys.FirePhysProjectile( projectile )
end
function simfphys.weapon:ValidClasses()
return { "sim_fphys_tank3" }
end
function simfphys.weapon:Initialize( vehicle )
vehicle:SetNWBool( "SpecialCam_Loader", true )
vehicle:SetNWFloat( "SpecialCam_LoaderTime", 4.5 )
simfphys.RegisterCrosshair( vehicle:GetDriverSeat(), { Attachment = "cannon_muzzle", Type = 4 } )
simfphys.RegisterCamera( vehicle:GetDriverSeat(), Vector(-30,-20,-12), Vector(-25,50,110), true, "cannon_mg_muzzle" )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
simfphys.RegisterCrosshair( vehicle.pSeat[1] , { Attachment = "mg_muzzle", Type = 5 } )
simfphys.RegisterCamera( vehicle.pSeat[1], Vector(-80,-15,0), Vector(0,0,60), true, "mg_muzzle" )
simfphys.RegisterCamera( vehicle.pSeat[2], Vector(0,0,25), Vector(0,0,25), false )
simfphys.RegisterCamera( vehicle.pSeat[3], Vector(0,0,25), Vector(0,0,25), false )
timer.Simple( 1, function()
if not IsValid( vehicle ) then return end
if not vehicle.VehicleData["filter"] then print("[simfphys Armed Vehicle Pack] ERROR:TRACE FILTER IS INVALID. PLEASE UPDATE SIMFPHYS BASE") return end
vehicle.WheelOnGround = function( ent )
ent.FrontWheelPowered = ent:GetPowerDistribution() ~= 1
ent.RearWheelPowered = ent:GetPowerDistribution() ~= -1
for i = 1, table.Count( ent.Wheels ) do
local Wheel = ent.Wheels[i]
if IsValid( Wheel ) then
local dmgMul = Wheel:GetDamaged() and 0.5 or 1
local surfacemul = simfphys.TractionData[Wheel:GetSurfaceMaterial():lower()]
ent.VehicleData[ "SurfaceMul_" .. i ] = (surfacemul and math.max(surfacemul,0.001) or 1) * dmgMul
local WheelPos = ent:LogicWheelPos( i )
local WheelRadius = WheelPos.IsFrontWheel and ent.FrontWheelRadius or ent.RearWheelRadius
local startpos = Wheel:GetPos()
local dir = -ent.Up
local len = WheelRadius + math.Clamp(-ent.Vel.z / 50,2.5,6)
local HullSize = Vector(WheelRadius,WheelRadius,0)
local tr = util.TraceHull( {
start = startpos,
endpos = startpos + dir * len,
maxs = HullSize,
mins = -HullSize,
filter = ent.VehicleData["filter"]
} )
local onground = self:IsOnGround( vehicle ) and 1 or 0
Wheel:SetOnGround( onground )
ent.VehicleData[ "onGround_" .. i ] = onground
if tr.Hit then
Wheel:SetSpeed( Wheel.FX )
Wheel:SetSkidSound( Wheel.skid )
Wheel:SetSurfaceMaterial( util.GetSurfacePropName( tr.SurfaceProps ) )
end
end
end
local FrontOnGround = math.max(ent.VehicleData[ "onGround_1" ],ent.VehicleData[ "onGround_2" ])
local RearOnGround = math.max(ent.VehicleData[ "onGround_3" ],ent.VehicleData[ "onGround_4" ])
ent.DriveWheelsOnGround = math.max(ent.FrontWheelPowered and FrontOnGround or 0,ent.RearWheelPowered and RearOnGround or 0)
end
end)
end
function simfphys.weapon:GetForwardSpeed( vehicle )
return vehicle.ForwardSpeed
end
function simfphys.weapon:IsOnGround( vehicle )
return (vehicle.susOnGround == true)
end
function simfphys.weapon:AimMachinegun( ply, vehicle, pod )
if not IsValid( pod ) then return end
local Aimang = pod:WorldToLocalAngles( ply:EyeAngles() )
local AimRate = 250
local Angles = vehicle:WorldToLocalAngles( Aimang )
vehicle.sm_ppmg_yaw = vehicle.sm_ppmg_yaw and math.ApproachAngle( vehicle.sm_ppmg_yaw, Angles.y, AimRate * FrameTime() ) or 90
vehicle.sm_ppmg_pitch = vehicle.sm_ppmg_pitch and math.ApproachAngle( vehicle.sm_ppmg_pitch, Angles.p, AimRate * FrameTime() ) or 0
local TargetAng = Angle(vehicle.sm_ppmg_pitch,vehicle.sm_ppmg_yaw,0)
TargetAng:Normalize()
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw or 90
vehicle:SetPoseParameter("mg_aim_yaw", TargetAng.y - vehicle.sm_pp_yaw )
vehicle:SetPoseParameter("mg_aim_pitch", -TargetAng.p )
end
function simfphys.weapon:AimCannon( ply, vehicle, pod, Attachment )
if not IsValid( pod ) then return end
local Aimang = pod:WorldToLocalAngles( ply:EyeAngles() )
Aimang:Normalize()
local AimRate = 60
local Angles = vehicle:WorldToLocalAngles( Aimang )
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw and math.ApproachAngle( vehicle.sm_pp_yaw, Angles.y, AimRate * FrameTime() ) or 90
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("cannon_aim_yaw", TargetAng.y - 90 )
local pclamp = math.Clamp( (math.cos( math.rad(TargetAng.y + 90) ) - 0.7) * 6,0,1) ^ 2 * 15
vehicle:SetPoseParameter("cannon_aim_pitch", math.Clamp(-TargetAng.p,-15 + pclamp,20) )
end
function simfphys.weapon:ControlTurret( vehicle, deltapos )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
local pod = vehicle:GetDriverSeat()
if not IsValid( pod ) then return end
local ply = pod:GetDriver()
if not IsValid( ply ) then return end
local safemode = ply:KeyDown( IN_WALK )
if vehicle.ButtonSafeMode ~= safemode then
vehicle.ButtonSafeMode = safemode
if safemode then
vehicle:SetNWBool( "TurretSafeMode", not vehicle:GetNWBool( "TurretSafeMode", true ) )
if vehicle:GetNWBool( "TurretSafeMode" ) then
vehicle:EmitSound( "vehicles/tank_turret_stop1.wav")
else
vehicle:EmitSound( "vehicles/tank_readyfire1.wav")
end
end
end
if vehicle:GetNWBool( "TurretSafeMode", true ) then return end
local ID = vehicle:LookupAttachment( "cannon_muzzle" )
local Attachment = vehicle:GetAttachment( ID )
self:AimCannon( ply, vehicle, pod, Attachment )
local DeltaP = deltapos * engine.TickInterval()
local fire = ply:KeyDown( IN_ATTACK )
local fire2 = ply:KeyDown( IN_ATTACK2 )
if fire then
self:PrimaryAttack( vehicle, ply, Attachment.Pos + DeltaP, Attachment )
end
local Rate = FrameTime() / 5
vehicle.smTmpHMG = vehicle.smTmpHMG and vehicle.smTmpHMG + math.Clamp((fire2 and 1 or 0) - vehicle.smTmpHMG,-Rate * 6,Rate) or 0
if fire2 then
self:SecondaryAttack( vehicle, ply, DeltaP, Attachment.Pos, Attachment.Ang )
end
end
function simfphys.weapon:ControlMachinegun( vehicle, deltapos )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
local pod = vehicle.pSeat[1]
if not IsValid( pod ) then return end
local ply = pod:GetDriver()
if not IsValid( ply ) then return end
self:AimMachinegun( ply, vehicle, pod )
local ID = vehicle:LookupAttachment( "mg_muzzle" )
local Attachment = vehicle:GetAttachment( ID )
local shootOrigin = Attachment.Pos + deltapos * engine.TickInterval()
local fire = ply:KeyDown( IN_ATTACK )
local Rate = FrameTime() / 5
vehicle.smTmpMG = vehicle.smTmpMG and vehicle.smTmpMG + math.Clamp((fire and 1 or 0) - vehicle.smTmpMG,-Rate * 6,Rate) or 0
if fire then
self:Attack( vehicle, ply, shootOrigin, Attachment, ID )
end
end
function simfphys.weapon:Attack( vehicle, ply, shootOrigin, Attachment, ID )
if not self:CanAttack( vehicle ) then return end
local shootDirection = Attachment.Ang:Forward()
hmg_fire( ply, vehicle, shootOrigin, shootDirection )
self:SetNextFire( vehicle, CurTime() + 0.1 + (vehicle.smTmpMG ^ 5) * 0.05 )
end
function simfphys.weapon:CanAttack( vehicle )
vehicle.NextShoot3 = vehicle.NextShoot3 or 0
return vehicle.NextShoot3 < CurTime()
end
function simfphys.weapon:SetNextFire( vehicle, time )
vehicle.NextShoot3 = time
end
function simfphys.weapon:PrimaryAttack( vehicle, ply, shootOrigin, Attachment )
if not self:CanPrimaryAttack( vehicle ) then return end
local shootDirection = Attachment.Ang:Forward()
vehicle:PlayAnimation( "fire" )
cannon_fire( ply, vehicle, shootOrigin + shootDirection * 80, shootDirection )
self:SetNextPrimaryFire( vehicle, CurTime() + 4.5 )
end
function simfphys.weapon:CanPrimaryAttack( vehicle )
vehicle.NextShoot = vehicle.NextShoot or 0
return vehicle.NextShoot < CurTime()
end
function simfphys.weapon:SetNextPrimaryFire( vehicle, time )
vehicle.NextShoot = time
vehicle:SetNWFloat( "SpecialCam_LoaderNext", time )
end
function simfphys.weapon:SecondaryAttack( vehicle, ply, deltapos, cPos, cAng )
if not self:CanSecondaryAttack( vehicle ) then return end
local ID = vehicle:LookupAttachment( "cannon_mg_muzzle" )
local Attachment = vehicle:GetAttachment( ID )
local trace = util.TraceLine( {
start = cPos,
endpos = cPos + cAng:Forward() * 50000,
filter = vehicle.VehicleData["filter"]
} )
mg_fire( ply, vehicle, Attachment.Pos, (trace.HitPos - Attachment.Pos):GetNormalized() )
self:SetNextSecondaryFire( vehicle, CurTime() + 0.07 + (vehicle.smTmpHMG ^ 5) * 0.08 )
end
function simfphys.weapon:CanSecondaryAttack( vehicle )
vehicle.NextShoot2 = vehicle.NextShoot2 or 0
return vehicle.NextShoot2 < CurTime()
end
function simfphys.weapon:SetNextSecondaryFire( vehicle, time )
vehicle.NextShoot2 = time
end
function simfphys.weapon:ModPhysics( vehicle, wheelslocked )
if wheelslocked and self:IsOnGround( vehicle ) then
local phys = vehicle:GetPhysicsObject()
phys:ApplyForceCenter( -vehicle:GetVelocity() * phys:GetMass() * 0.04 )
end
end
function simfphys.weapon:ControlTrackSounds( vehicle, wheelslocked )
local speed = math.abs( self:GetForwardSpeed( vehicle ) )
local fastenuf = speed > 20 and not wheelslocked and self:IsOnGround( vehicle )
if fastenuf ~= vehicle.fastenuf then
vehicle.fastenuf = fastenuf
if fastenuf then
vehicle.track_snd = CreateSound( vehicle, "simulated_vehicles/leopard/tracks.wav" )
vehicle.track_snd:PlayEx(0,0)
vehicle:CallOnRemove( "stopmesounds", function( vehicle )
if vehicle.track_snd then
vehicle.track_snd:Stop()
end
end)
else
if vehicle.track_snd then
vehicle.track_snd:Stop()
vehicle.track_snd = nil
end
end
end
if vehicle.track_snd then
vehicle.track_snd:ChangePitch( math.Clamp(70 + speed / 40,0,150) )
vehicle.track_snd:ChangeVolume( math.min( math.max(speed - 20,0) / 200,1) )
end
end
function simfphys.weapon:ControlPassengerSeats( vehicle )
if not vehicle.pSeat then return end
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw and vehicle.sm_pp_yaw or 90
vehicle.sm_pp_pitch = vehicle.sm_pp_pitch and vehicle.sm_pp_pitch or 0
do
local Commander = vehicle.pSeat[2]
if IsValid( Commander ) then
local ply = Commander:GetDriver()
local Toggle = false
if IsValid( ply ) then
Toggle = ply:KeyDown( IN_JUMP )
end
if Toggle ~= vehicle.OldToggleC then
vehicle.OldToggleC = Toggle
if Toggle then
vehicle.tg_c_z = not vehicle.tg_c_z
if vehicle.tg_c_z then
vehicle:EmitSound( "vehicles/atv_ammo_open.wav" )
simfphys.RegisterCamera( Commander, Vector(0,0,0), Vector(0,0,0), false )
else
vehicle:EmitSound( "vehicles/atv_ammo_close.wav" )
simfphys.RegisterCamera( Commander, Vector(0,0,25), Vector(0,0,25), false )
end
end
end
local X = math.sin( math.rad( -vehicle.sm_pp_yaw - 25 ) ) * 27
local Y = math.cos( math.rad( -vehicle.sm_pp_yaw - 25 ) ) * 27
Commander:SetLocalPos( Vector(X,Y,50 + (vehicle.tg_c_z and 25 or 0)) )
Commander:SetLocalAngles( Angle(0,vehicle.sm_pp_yaw - 90,0) )
end
end
do
local Loader = vehicle.pSeat[3]
if IsValid( Loader ) then
local ply = Loader:GetDriver()
local Toggle = false
if IsValid( ply ) then
Toggle = ply:KeyDown( IN_JUMP )
end
if Toggle ~= vehicle.OldToggleL then
vehicle.OldToggleL = Toggle
if Toggle then
vehicle.tg_l_z = not vehicle.tg_l_z
if vehicle.tg_l_z then
vehicle:EmitSound( "vehicles/atv_ammo_open.wav" )
simfphys.RegisterCamera( Loader, Vector(0,0,0), Vector(0,0,0), false )
else
vehicle:EmitSound( "vehicles/atv_ammo_close.wav" )
simfphys.RegisterCamera( Loader, Vector(0,0,25), Vector(0,0,25), false )
end
end
end
local X = math.sin( math.rad( -vehicle.sm_pp_yaw - 160 ) ) * 27
local Y = math.cos( math.rad( -vehicle.sm_pp_yaw - 160 ) ) * 27
Loader:SetLocalPos( Vector(X,Y,50 + (vehicle.tg_l_z and 25 or 0)) )
Loader:SetLocalAngles( Angle(0,vehicle.sm_pp_yaw - 90,0) )
end
end
end
function simfphys.weapon:Think( vehicle )
if not IsValid( vehicle ) or not vehicle:IsInitialized() then return end
vehicle.wOldPos = vehicle.wOldPos or Vector(0,0,0)
local deltapos = vehicle:GetPos() - vehicle.wOldPos
vehicle.wOldPos = vehicle:GetPos()
local handbrake = vehicle:GetHandBrakeEnabled()
self:ControlPassengerSeats( vehicle )
self:UpdateSuspension( vehicle )
self:DoWheelSpin( vehicle )
self:ControlTurret( vehicle, deltapos )
self:ControlMachinegun( vehicle, deltapos )
self:ControlTrackSounds( vehicle, handbrake )
self:ModPhysics( vehicle, handbrake )
end
function simfphys.weapon:UpdateSuspension( vehicle )
if not vehicle.filterEntities then
vehicle.filterEntities = player.GetAll()
table.insert(vehicle.filterEntities, vehicle)
for i, wheel in pairs( ents.FindByClass( "gmod_sent_vehicle_fphysics_wheel" ) ) do
table.insert(vehicle.filterEntities, wheel)
end
end
vehicle.oldDist = istable( vehicle.oldDist ) and vehicle.oldDist or {}
vehicle.susOnGround = false
local Up = vehicle:GetUp()
for i, v in pairs( leopard_susdata ) do
local pos = vehicle:GetAttachment( vehicle:LookupAttachment( leopard_susdata[i].attachment ) ).Pos + Up * 10
local trace = util.TraceHull( {
start = pos,
endpos = pos + Up * - 100,
maxs = Vector(10,10,0),
mins = -Vector(10,10,0),
filter = vehicle.filterEntities,
} )
local Dist = (pos - trace.HitPos):Length() - 38
if trace.Hit then
vehicle.susOnGround = true
end
vehicle.oldDist[i] = vehicle.oldDist[i] and (vehicle.oldDist[i] + math.Clamp(Dist - vehicle.oldDist[i],-5,1)) or 0
vehicle:SetPoseParameter(leopard_susdata[i].poseparameter, vehicle.oldDist[i] )
end
end
function simfphys.weapon:DoWheelSpin( vehicle )
local spin_r = (vehicle.VehicleData[ "spin_4" ] + vehicle.VehicleData[ "spin_6" ]) * 1.75
local spin_l = (vehicle.VehicleData[ "spin_3" ] + vehicle.VehicleData[ "spin_5" ]) * 1.75
net.Start( "simfphys_update_tracks", true )
net.WriteEntity( vehicle )
net.WriteFloat( spin_r )
net.WriteFloat( spin_l )
net.Broadcast()
vehicle:SetPoseParameter("spin_wheels_right", spin_r)
vehicle:SetPoseParameter("spin_wheels_left", spin_l )
end

View File

@@ -0,0 +1,541 @@
--[[
| 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 t90ms_susdata = {}
for i = 1,6 do
t90ms_susdata[i] = {
attachment = "sus_left_attach_"..i,
poseparameter = "suspension_left_"..i,
}
local ir = i + 6
t90ms_susdata[ir] = {
attachment = "sus_right_attach_"..i,
poseparameter = "suspension_right_"..i,
}
end
local function hmg_fire(ply,vehicle,shootOrigin,shootDirection)
vehicle:EmitSound("leopard_fire_mg")
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.Tracer = 1
projectile.HullSize = 6
projectile.attackingent = vehicle
projectile.Spread = Vector(0.01,0.01,0.01)
projectile.Damage = 25
projectile.Force = 12
simfphys.FireHitScan( projectile )
end
local function mg_fire(ply,vehicle,shootOrigin,shootDirection)
vehicle:EmitSound("tiger_fire_mg_new")
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.Tracer = 1
projectile.HullSize = 5
projectile.attackingent = vehicle
projectile.Spread = Vector(0.008,0.008,0.008)
projectile.Damage = 20
projectile.Force = 12
simfphys.FireHitScan( projectile )
end
local function cannon_fire(ply,vehicle,shootOrigin,shootDirection)
vehicle:EmitSound("t90ms_fire")
vehicle:EmitSound("t90ms_reload")
timer.Simple( 4, function()
if IsValid( vehicle ) then
vehicle:EmitSound("simulated_vehicles/weapons/leopard_ready.wav")
end
end)
local effectdata = EffectData()
effectdata:SetEntity( vehicle )
util.Effect( "simfphys_leopard_muzzle", effectdata )
vehicle:GetPhysicsObject():ApplyForceOffset( -shootDirection * 500000, shootOrigin )
local projectile = {}
projectile.filter = vehicle.VehicleData["filter"]
projectile.shootOrigin = shootOrigin
projectile.shootDirection = shootDirection
projectile.attacker = ply
projectile.attackingent = vehicle
projectile.Damage = 3500
projectile.Force = 8000
projectile.Size = 15
projectile.DeflectAng = 20
projectile.BlastRadius = 300
projectile.BlastDamage = 1000
projectile.BlastEffect = "simfphys_tankweapon_explosion"
simfphys.FirePhysProjectile( projectile )
end
function simfphys.weapon:ValidClasses()
return { "sim_fphys_tank4" }
end
function simfphys.weapon:Initialize( vehicle )
vehicle:SetNWBool( "SpecialCam_Loader", true )
vehicle:SetNWFloat( "SpecialCam_LoaderTime", 4.5 )
simfphys.RegisterCrosshair( vehicle:GetDriverSeat(), { Attachment = "cannon_muzzle", Type = 4 } )
simfphys.RegisterCamera( vehicle:GetDriverSeat(), Vector(0,-35,2), Vector(0,50,110), true, "cannon_mg_muzzle" )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
simfphys.RegisterCrosshair( vehicle.pSeat[1] , { Attachment = "mg_muzzle", Type = 5 } )
simfphys.RegisterCamera( vehicle.pSeat[1], Vector(-60,25,0), Vector(0,50,60), true, "mg_muzzle" )
simfphys.RegisterCamera( vehicle.pSeat[2], Vector(0,0,25), Vector(0,0,25), false )
simfphys.RegisterCamera( vehicle.pSeat[3], Vector(0,0,25), Vector(0,0,25), false )
timer.Simple( 1, function()
if not IsValid( vehicle ) then return end
if not vehicle.VehicleData["filter"] then print("[simfphys Armed Vehicle Pack] ERROR:TRACE FILTER IS INVALID. PLEASE UPDATE SIMFPHYS BASE") return end
vehicle.WheelOnGround = function( ent )
ent.FrontWheelPowered = ent:GetPowerDistribution() ~= 1
ent.RearWheelPowered = ent:GetPowerDistribution() ~= -1
for i = 1, table.Count( ent.Wheels ) do
local Wheel = ent.Wheels[i]
if IsValid( Wheel ) then
local dmgMul = Wheel:GetDamaged() and 0.5 or 1
local surfacemul = simfphys.TractionData[Wheel:GetSurfaceMaterial():lower()]
ent.VehicleData[ "SurfaceMul_" .. i ] = (surfacemul and math.max(surfacemul,0.001) or 1) * dmgMul
local WheelPos = ent:LogicWheelPos( i )
local WheelRadius = WheelPos.IsFrontWheel and ent.FrontWheelRadius or ent.RearWheelRadius
local startpos = Wheel:GetPos()
local dir = -ent.Up
local len = WheelRadius + math.Clamp(-ent.Vel.z / 50,2.5,6)
local HullSize = Vector(WheelRadius,WheelRadius,0)
local tr = util.TraceHull( {
start = startpos,
endpos = startpos + dir * len,
maxs = HullSize,
mins = -HullSize,
filter = ent.VehicleData["filter"]
} )
local onground = self:IsOnGround( vehicle ) and 1 or 0
Wheel:SetOnGround( onground )
ent.VehicleData[ "onGround_" .. i ] = onground
if tr.Hit then
Wheel:SetSpeed( Wheel.FX )
Wheel:SetSkidSound( Wheel.skid )
Wheel:SetSurfaceMaterial( util.GetSurfacePropName( tr.SurfaceProps ) )
end
end
end
local FrontOnGround = math.max(ent.VehicleData[ "onGround_1" ],ent.VehicleData[ "onGround_2" ])
local RearOnGround = math.max(ent.VehicleData[ "onGround_3" ],ent.VehicleData[ "onGround_4" ])
ent.DriveWheelsOnGround = math.max(ent.FrontWheelPowered and FrontOnGround or 0,ent.RearWheelPowered and RearOnGround or 0)
end
end)
end
function simfphys.weapon:GetForwardSpeed( vehicle )
return vehicle.ForwardSpeed
end
function simfphys.weapon:IsOnGround( vehicle )
return (vehicle.susOnGround == true)
end
function simfphys.weapon:AimMachinegun( ply, vehicle, pod )
if not IsValid( pod ) then return end
local Aimang = pod:WorldToLocalAngles( ply:EyeAngles() )
local AimRate = 250
local Angles = vehicle:WorldToLocalAngles( Aimang )
vehicle.sm_ppmg_yaw = vehicle.sm_ppmg_yaw and math.ApproachAngle( vehicle.sm_ppmg_yaw, Angles.y, AimRate * FrameTime() ) or 180
vehicle.sm_ppmg_pitch = vehicle.sm_ppmg_pitch and math.ApproachAngle( vehicle.sm_ppmg_pitch, Angles.p, AimRate * FrameTime() ) or 0
local TargetAng = Angle(vehicle.sm_ppmg_pitch,vehicle.sm_ppmg_yaw,0)
TargetAng:Normalize()
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw or 180
vehicle:SetPoseParameter("mg_aim_yaw", TargetAng.y - vehicle.sm_pp_yaw )
vehicle:SetPoseParameter("mg_aim_pitch", -TargetAng.p )
end
function simfphys.weapon:AimCannon( ply, vehicle, pod, Attachment )
if not IsValid( pod ) then return end
local Aimang = pod:WorldToLocalAngles( ply:EyeAngles() )
Aimang:Normalize()
local AimRate = 60
local Angles = vehicle:WorldToLocalAngles( Aimang )
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw and math.ApproachAngle( vehicle.sm_pp_yaw, Angles.y, AimRate * FrameTime() ) or 180
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("cannon_aim_yaw", TargetAng.y - 180 )
local pclamp = math.Clamp( (math.cos( math.rad(TargetAng.y) ) - 0.7) * 6,0,1) ^ 2 * 15
vehicle:SetPoseParameter("cannon_aim_pitch", math.Clamp(-TargetAng.p,-15 + pclamp,20) )
end
function simfphys.weapon:ControlTurret( vehicle, deltapos )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
local pod = vehicle:GetDriverSeat()
if not IsValid( pod ) then return end
local ply = pod:GetDriver()
if not IsValid( ply ) then return end
local safemode = ply:KeyDown( IN_WALK )
if vehicle.ButtonSafeMode ~= safemode then
vehicle.ButtonSafeMode = safemode
if safemode then
vehicle:SetNWBool( "TurretSafeMode", not vehicle:GetNWBool( "TurretSafeMode", true ) )
if vehicle:GetNWBool( "TurretSafeMode" ) then
vehicle:EmitSound( "vehicles/tank_turret_stop1.wav")
else
vehicle:EmitSound( "vehicles/tank_readyfire1.wav")
end
end
end
if vehicle:GetNWBool( "TurretSafeMode", true ) then return end
local ID = vehicle:LookupAttachment( "cannon_muzzle" )
local Attachment = vehicle:GetAttachment( ID )
self:AimCannon( ply, vehicle, pod, Attachment )
local DeltaP = deltapos * engine.TickInterval()
local fire = ply:KeyDown( IN_ATTACK )
local fire2 = ply:KeyDown( IN_ATTACK2 )
if fire then
self:PrimaryAttack( vehicle, ply, Attachment.Pos + DeltaP, Attachment )
end
local Rate = FrameTime() / 5
vehicle.smTmpHMG = vehicle.smTmpHMG and vehicle.smTmpHMG + math.Clamp((fire2 and 1 or 0) - vehicle.smTmpHMG,-Rate * 6,Rate) or 0
if fire2 then
self:SecondaryAttack( vehicle, ply, DeltaP, Attachment.Pos, Attachment.Ang )
end
end
function simfphys.weapon:ControlMachinegun( vehicle, deltapos )
if not istable( vehicle.PassengerSeats ) or not istable( vehicle.pSeat ) then return end
local pod = vehicle.pSeat[1]
if not IsValid( pod ) then return end
local ply = pod:GetDriver()
if not IsValid( ply ) then return end
self:AimMachinegun( ply, vehicle, pod )
local ID = vehicle:LookupAttachment( "mg_muzzle" )
local Attachment = vehicle:GetAttachment( ID )
local shootOrigin = Attachment.Pos + deltapos * engine.TickInterval()
local fire = ply:KeyDown( IN_ATTACK )
local Rate = FrameTime() / 5
vehicle.smTmpMG = vehicle.smTmpMG and vehicle.smTmpMG + math.Clamp((fire and 1 or 0) - vehicle.smTmpMG,-Rate * 6,Rate) or 0
if fire then
self:Attack( vehicle, ply, shootOrigin, Attachment, ID )
end
end
function simfphys.weapon:Attack( vehicle, ply, shootOrigin, Attachment, ID )
if not self:CanAttack( vehicle ) then return end
local shootDirection = Attachment.Ang:Forward()
hmg_fire( ply, vehicle, shootOrigin, shootDirection )
self:SetNextFire( vehicle, CurTime() + 0.1 + (vehicle.smTmpMG ^ 5) * 0.05 )
end
function simfphys.weapon:CanAttack( vehicle )
vehicle.NextShoot3 = vehicle.NextShoot3 or 0
return vehicle.NextShoot3 < CurTime()
end
function simfphys.weapon:SetNextFire( vehicle, time )
vehicle.NextShoot3 = time
end
function simfphys.weapon:PrimaryAttack( vehicle, ply, shootOrigin, Attachment )
if not self:CanPrimaryAttack( vehicle ) then return end
local shootDirection = Attachment.Ang:Forward()
vehicle:PlayAnimation( "fire" )
cannon_fire( ply, vehicle, shootOrigin + shootDirection * 80, shootDirection )
self:SetNextPrimaryFire( vehicle, CurTime() + 4.5 )
end
function simfphys.weapon:CanPrimaryAttack( vehicle )
vehicle.NextShoot = vehicle.NextShoot or 0
return vehicle.NextShoot < CurTime()
end
function simfphys.weapon:SetNextPrimaryFire( vehicle, time )
vehicle.NextShoot = time
vehicle:SetNWFloat( "SpecialCam_LoaderNext", time )
end
function simfphys.weapon:SecondaryAttack( vehicle, ply, deltapos, cPos, cAng )
if not self:CanSecondaryAttack( vehicle ) then return end
local ID = vehicle:LookupAttachment( "cannon_mg_muzzle" )
local Attachment = vehicle:GetAttachment( ID )
local trace = util.TraceLine( {
start = cPos,
endpos = cPos + cAng:Forward() * 50000,
filter = vehicle.VehicleData["filter"]
} )
mg_fire( ply, vehicle, Attachment.Pos, (trace.HitPos - Attachment.Pos):GetNormalized() )
self:SetNextSecondaryFire( vehicle, CurTime() + 0.07 + (vehicle.smTmpHMG ^ 5) * 0.08 )
end
function simfphys.weapon:CanSecondaryAttack( vehicle )
vehicle.NextShoot2 = vehicle.NextShoot2 or 0
return vehicle.NextShoot2 < CurTime()
end
function simfphys.weapon:SetNextSecondaryFire( vehicle, time )
vehicle.NextShoot2 = time
end
function simfphys.weapon:ModPhysics( vehicle, wheelslocked )
if wheelslocked and self:IsOnGround( vehicle ) then
local phys = vehicle:GetPhysicsObject()
phys:ApplyForceCenter( -vehicle:GetVelocity() * phys:GetMass() * 0.04 )
end
end
function simfphys.weapon:ControlTrackSounds( vehicle, wheelslocked )
local speed = math.abs( self:GetForwardSpeed( vehicle ) )
local fastenuf = speed > 20 and not wheelslocked and self:IsOnGround( vehicle )
if fastenuf ~= vehicle.fastenuf then
vehicle.fastenuf = fastenuf
if fastenuf then
vehicle.track_snd = CreateSound( vehicle, "simulated_vehicles/sherman/tracks.wav" )
vehicle.track_snd:PlayEx(0,0)
vehicle:CallOnRemove( "stopmesounds", function( vehicle )
if vehicle.track_snd then
vehicle.track_snd:Stop()
end
end)
else
if vehicle.track_snd then
vehicle.track_snd:Stop()
vehicle.track_snd = nil
end
end
end
if vehicle.track_snd then
vehicle.track_snd:ChangePitch( math.Clamp(60 + speed / 40,0,150) )
vehicle.track_snd:ChangeVolume( math.min( math.max(speed - 20,0) / 200,1) )
end
end
function simfphys.weapon:ControlPassengerSeats( vehicle )
if not vehicle.pSeat then return end
vehicle.sm_pp_yaw = vehicle.sm_pp_yaw and vehicle.sm_pp_yaw or 180
vehicle.sm_pp_pitch = vehicle.sm_pp_pitch and vehicle.sm_pp_pitch or 0
do
local Commander = vehicle.pSeat[2]
if IsValid( Commander ) then
local ply = Commander:GetDriver()
local Toggle = false
if IsValid( ply ) then
Toggle = ply:KeyDown( IN_JUMP )
end
if Toggle ~= vehicle.OldToggleC then
vehicle.OldToggleC = Toggle
if Toggle then
vehicle.tg_c_z = not vehicle.tg_c_z
if vehicle.tg_c_z then
vehicle:EmitSound( "vehicles/atv_ammo_open.wav" )
simfphys.RegisterCamera( Commander, Vector(0,0,0), Vector(0,0,0), false )
else
vehicle:EmitSound( "vehicles/atv_ammo_close.wav" )
simfphys.RegisterCamera( Commander, Vector(0,0,25), Vector(0,0,25), false )
end
end
end
local X = math.sin( math.rad( -vehicle.sm_pp_yaw - 40 ) ) * 27
local Y = math.cos( math.rad( -vehicle.sm_pp_yaw - 40 ) ) * 27
Commander:SetLocalPos( Vector(X + 2.9121,Y,20 + (vehicle.tg_c_z and 25 or 0)) )
Commander:SetLocalAngles( Angle(0,vehicle.sm_pp_yaw - 90,0) )
end
end
do
local Loader = vehicle.pSeat[3]
if IsValid( Loader ) then
local ply = Loader:GetDriver()
local Toggle = false
if IsValid( ply ) then
Toggle = ply:KeyDown( IN_JUMP )
end
if Toggle ~= vehicle.OldToggleL then
vehicle.OldToggleL = Toggle
if Toggle then
vehicle.tg_l_z = not vehicle.tg_l_z
if vehicle.tg_l_z then
vehicle:EmitSound( "vehicles/atv_ammo_open.wav" )
simfphys.RegisterCamera( Loader, Vector(0,0,0), Vector(0,0,0), false )
else
vehicle:EmitSound( "vehicles/atv_ammo_close.wav" )
simfphys.RegisterCamera( Loader, Vector(0,0,25), Vector(0,0,25), false )
end
end
end
local X = math.sin( math.rad( -vehicle.sm_pp_yaw - 165 ) ) * 30
local Y = math.cos( math.rad( -vehicle.sm_pp_yaw - 165 ) ) * 30
Loader:SetLocalPos( Vector(X + 2.9121,Y,24 + (vehicle.tg_l_z and 25 or 0)) )
Loader:SetLocalAngles( Angle(0,vehicle.sm_pp_yaw - 90,0) )
end
end
end
function simfphys.weapon:Think( vehicle )
if not IsValid( vehicle ) or not vehicle:IsInitialized() then return end
vehicle.wOldPos = vehicle.wOldPos or Vector(0,0,0)
local deltapos = vehicle:GetPos() - vehicle.wOldPos
vehicle.wOldPos = vehicle:GetPos()
local handbrake = vehicle:GetHandBrakeEnabled()
self:ControlPassengerSeats( vehicle )
self:UpdateSuspension( vehicle )
self:DoWheelSpin( vehicle )
self:ControlTurret( vehicle, deltapos )
self:ControlMachinegun( vehicle, deltapos )
self:ControlTrackSounds( vehicle, handbrake )
self:ModPhysics( vehicle, handbrake )
end
function simfphys.weapon:UpdateSuspension( vehicle )
if not vehicle.filterEntities then
vehicle.filterEntities = player.GetAll()
table.insert(vehicle.filterEntities, vehicle)
for i, wheel in pairs( ents.FindByClass( "gmod_sent_vehicle_fphysics_wheel" ) ) do
table.insert(vehicle.filterEntities, wheel)
end
end
vehicle.oldDist = istable( vehicle.oldDist ) and vehicle.oldDist or {}
vehicle.susOnGround = false
local Up = vehicle:GetUp()
for i, v in pairs( t90ms_susdata ) do
local pos = vehicle:GetAttachment( vehicle:LookupAttachment( t90ms_susdata[i].attachment ) ).Pos + Up * 10
local trace = util.TraceHull( {
start = pos,
endpos = pos + Up * - 100,
maxs = Vector(10,10,0),
mins = -Vector(10,10,0),
filter = vehicle.filterEntities,
} )
local Dist = (pos - trace.HitPos):Length() - 53
if trace.Hit then
vehicle.susOnGround = true
end
vehicle.oldDist[i] = vehicle.oldDist[i] and (vehicle.oldDist[i] + math.Clamp(Dist - vehicle.oldDist[i],-5,1)) or 0
vehicle:SetPoseParameter(t90ms_susdata[i].poseparameter, vehicle.oldDist[i] )
end
end
function simfphys.weapon:DoWheelSpin( vehicle )
local spin_r = (vehicle.VehicleData[ "spin_4" ] + vehicle.VehicleData[ "spin_6" ]) * 1.25
local spin_l = (vehicle.VehicleData[ "spin_3" ] + vehicle.VehicleData[ "spin_5" ]) * 1.25
net.Start( "simfphys_update_tracks", true )
net.WriteEntity( vehicle )
net.WriteFloat( spin_r )
net.WriteFloat( spin_l )
net.Broadcast()
vehicle:SetPoseParameter("spin_wheels_right", spin_r)
vehicle:SetPoseParameter("spin_wheels_left", spin_l )
end

View File

@@ -0,0 +1,177 @@
--[[
| 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 GaussFire(ply,vehicle,shootOrigin,Attachment,damage)
vehicle:EmitSound("taucannon_fire")
local bullet = {}
bullet.Num = 1
bullet.Src = shootOrigin
bullet.Dir = Attachment.Ang:Forward()
bullet.Spread = Vector(0.01,0.01,0)
bullet.Tracer = 1
bullet.TracerName = "simfphys_gausstracer"
bullet.Force = damage
bullet.Damage = damage * 1.5
bullet.HullSize = 1
bullet.DisableOverride = true
bullet.Callback = function(att, tr, dmginfo)
local effect = ents.Create("env_spark")
effect:SetKeyValue("targetname", "target")
effect:SetPos( tr.HitPos + tr.HitNormal * 2 )
effect:SetAngles( tr.HitNormal:Angle() )
effect:Spawn()
effect:SetKeyValue("spawnflags","128")
effect:SetKeyValue("Magnitude",5)
effect:SetKeyValue("TrailLength",3)
effect:Fire( "SparkOnce" )
effect:Fire("kill","",0.21)
util.Decal("fadingscorch", tr.HitPos - tr.HitNormal, tr.HitPos + tr.HitNormal)
end
bullet.Attacker = ply
vehicle:FireBullets( bullet )
vehicle:GetPhysicsObject():ApplyForceOffset( -Attachment.Ang:Forward() * damage * 100, shootOrigin )
end
function simfphys.weapon:ValidClasses()
local classes = {
"sim_fphys_jeep_armed",
"sim_fphys_v8elite_armed"
}
return classes
end
function simfphys.weapon:Initialize( vehicle )
vehicle:SetBodygroup(1,1)
local pod = vehicle:GetDriverSeat()
simfphys.RegisterCrosshair( pod )
end
function simfphys.weapon:AimWeapon( ply, vehicle, pod )
local Aimang = ply:EyeAngles()
local AimRate = 250
local Angles = angle_zero
if ply:lvsMouseAim() then
local ang = vehicle:GetAngles()
ang.y = pod:GetAngles().y + 90
local Forward = ang:Right()
local View = pod:WorldToLocalAngles( Aimang )
local Pitch = (vehicle:AngleBetweenNormal( View:Up(), ang:Forward() ) - 90)
local Yaw = (vehicle:AngleBetweenNormal( View:Forward(), ang:Right() ) - 90)
Angles = Angle(-Pitch,Yaw,0)
else
Angles = vehicle:WorldToLocalAngles( Aimang ) - Angle(0,90,0)
Angles:Normalize()
end
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("vehicle_weapon_yaw", -TargetAng.y )
vehicle:SetPoseParameter("vehicle_weapon_pitch", -TargetAng.p )
return Aimang
end
function simfphys.weapon:Think( vehicle )
local pod = vehicle:GetDriverSeat()
if not IsValid( pod ) then return end
local ply = pod:GetDriver()
local curtime = CurTime()
local fire = false
local alt_fire = false
if IsValid( ply ) then
self:AimWeapon( ply, vehicle, pod )
fire = ply:KeyDown( IN_ATTACK )
alt_fire = ply:KeyDown( IN_ATTACK2 ) and self:CanPrimaryAttack( vehicle )
else
ply = NULL
end
local ID = vehicle:LookupAttachment( "muzzle" )
local Attachment = vehicle:GetAttachment( ID )
vehicle.wOldPos = vehicle.wOldPos or Vector(0,0,0)
local deltapos = vehicle:GetPos() - vehicle.wOldPos
vehicle.wOldPos = vehicle:GetPos()
local shootOrigin = Attachment.Pos + deltapos * engine.TickInterval()
vehicle.afire_pressed = vehicle.afire_pressed or false
vehicle.gausscharge = vehicle.gausscharge and (vehicle.gausscharge + math.Clamp((alt_fire and 200 or 0) - vehicle.gausscharge,0, FrameTime() * 100)) or 0
if vehicle.wpn_chr then
vehicle.wpn_chr:ChangePitch(100 + vehicle.gausscharge * 0.75)
vehicle.gaus_pp_spin = vehicle.gaus_pp_spin and (vehicle.gaus_pp_spin + vehicle.gausscharge / 4) or 0
vehicle:SetPoseParameter("gun_spin", vehicle.gaus_pp_spin)
end
if fire and not alt_fire then
self:PrimaryAttack( vehicle, ply, shootOrigin, Attachment )
end
if alt_fire ~= vehicle.afire_pressed then
vehicle.afire_pressed = alt_fire
if alt_fire then
vehicle.wpn_chr = CreateSound( vehicle, "weapons/gauss/chargeloop.wav" )
vehicle.wpn_chr:Play()
vehicle:CallOnRemove( "stopmesounds", function( vehicle )
if vehicle.wpn_chr then
vehicle.wpn_chr:Stop()
end
end)
else
vehicle.wpn_chr:Stop()
vehicle.wpn_chr = nil
GaussFire(ply,vehicle,shootOrigin,Attachment,250 + vehicle.gausscharge * 3)
vehicle.gausscharge = 0
self:SetNextPrimaryFire( vehicle, CurTime() + 1 )
end
end
end
function simfphys.weapon:CanPrimaryAttack( vehicle )
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, shootOrigin, Attachment )
if not self:CanPrimaryAttack( vehicle ) then return end
GaussFire(ply,vehicle,shootOrigin,Attachment,12)
self:SetNextPrimaryFire( vehicle, CurTime() + 0.2 )
end