From 53ab4e75492f08900c08bdaf6632a67739c6f7be Mon Sep 17 00:00:00 2001 From: KemGus Date: Tue, 26 Sep 2023 00:31:12 +0300 Subject: [PATCH] rework init --- lua/acf/shared/guns/atrifle.lua | 2 +- lua/acf/shared/guns/autocannon.lua | 2 +- lua/acf/shared/guns/autoloader.lua | 2 +- lua/acf/shared/guns/cannon.lua | 13 +++- lua/acf/shared/guns/grenadelauncher.lua | 2 +- lua/acf/shared/guns/heavymachinegun.lua | 2 +- lua/acf/shared/guns/machinegun.lua | 2 +- lua/acf/shared/guns/mortar.lua | 2 +- lua/acf/shared/guns/semiauto.lua | 2 +- lua/acf/shared/guns/shortcannon.lua | 3 +- lua/acf/shared/guns/smokelauncher.lua | 2 +- lua/acf/shared/guns/smoothcannon.lua | 2 +- lua/entities/ace_crewseat_loader/init.lua | 46 ++++++++++++- lua/entities/acf_gun/init.lua | 82 ++++++++++++++++++----- 14 files changed, 133 insertions(+), 31 deletions(-) diff --git a/lua/acf/shared/guns/atrifle.lua b/lua/acf/shared/guns/atrifle.lua index a2e1356e..96dd2574 100644 --- a/lua/acf/shared/guns/atrifle.lua +++ b/lua/acf/shared/guns/atrifle.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("ATR", { muzzleflash = "30mm_muzzleflash_noscale", rofmod = 10, year = 1917, - sound = "acf_extra/tankfx/gnomefather/7mm1.wav", + sound = "ace_weapons/multi_sound/7_62mm_multi.mp3", } ) diff --git a/lua/acf/shared/guns/autocannon.lua b/lua/acf/shared/guns/autocannon.lua index f53245aa..dccb7112 100644 --- a/lua/acf/shared/guns/autocannon.lua +++ b/lua/acf/shared/guns/autocannon.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("AC", { muzzleflash = "30mm_muzzleflash_noscale", rofmod = 0.35, year = 1930, - sound = "weapons/acf_gun/ac_fire4.wav", + sound = "ace_weapons/multi_sound/30mm_multi.mp3", noloader = true, } ) diff --git a/lua/acf/shared/guns/autoloader.lua b/lua/acf/shared/guns/autoloader.lua index 158f345b..e080472a 100644 --- a/lua/acf/shared/guns/autoloader.lua +++ b/lua/acf/shared/guns/autoloader.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("AL", { muzzleflash = "120mm_muzzleflash_noscale", rofmod = 0.64, year = 1946, - sound = "weapons/acf_gun/autoloader.wav", + sound = "ace_weapons/multi_sound/100mm_multi.mp3", autosound = "acf_extra/tankfx/reload.wav", noloader = true, } ) diff --git a/lua/acf/shared/guns/cannon.lua b/lua/acf/shared/guns/cannon.lua index b0cf2d29..acf252d8 100644 --- a/lua/acf/shared/guns/cannon.lua +++ b/lua/acf/shared/guns/cannon.lua @@ -6,7 +6,8 @@ ACF_defineGunClass("C", { desc = ACFTranslation.GunClasses[4], muzzleflash = "120mm_muzzleflash_noscale", rofmod = 1.5, - sound = "weapons/acf_gun/cannon_new.wav", + maxrof = 19, -- maximum rounds per minute + sound = "ace_weapons/multi_sound/100mm_multi.mp3", } ) @@ -21,6 +22,7 @@ ACF_defineGun("37mmC", { --id weight = 95, year = 1919, rofmod = 1.4, + maxrof = 42, -- maximum rounds per minute round = { maxlength = 48, propweight = 1.125 @@ -36,6 +38,7 @@ ACF_defineGun("50mmC", { caliber = 5.0, weight = 380, year = 1935, + maxrof = 35, -- maximum rounds per minute round = { maxlength = 63, propweight = 2.1 @@ -51,6 +54,7 @@ ACF_defineGun("75mmC", { caliber = 7.5, weight = 660, year = 1942, + maxrof = 25, -- maximum rounds per minute round = { maxlength = 78, propweight = 3.8 @@ -59,13 +63,14 @@ ACF_defineGun("75mmC", { ACF_defineGun("85mmC", { name = "85mm Cannon", - desc = "You can stop asking, we've got it now.", + desc = "Slightly better than 75, however may introduce problems to tanks, whose armor could stop 75mm. T-34-85 gun.", model = "models/tankgun/tankgun_85mm.mdl", sound = "ace_weapons/multi_sound/75mm_multi.mp3", gunclass = "C", caliber = 8.5, weight = 1030, year = 1944, + maxrof = 23, -- maximum rounds per minute round = { maxlength = 85.5, propweight = 6.65 @@ -81,6 +86,7 @@ ACF_defineGun("100mmC", { caliber = 10.0, weight = 1400, year = 1944, + maxrof = 19, -- maximum rounds per minute round = { maxlength = 93, propweight = 9.5 @@ -96,6 +102,7 @@ ACF_defineGun("120mmC", { caliber = 12.0, weight = 2100, year = 1955, + maxrof = 12, -- maximum rounds per minute round = { maxlength = 110, propweight = 18 @@ -111,6 +118,7 @@ ACF_defineGun("140mmC", { caliber = 14.0, weight = 3900, year = 1990, + maxrof = 8.5, -- maximum rounds per minute round = { maxlength = 127, propweight = 28 @@ -126,6 +134,7 @@ ACF_defineGun("170mmC", { caliber = 17.0, weight = 7800, year = 1990, + maxrof = 4, -- maximum rounds per minute round = { maxlength = 154, propweight = 34 diff --git a/lua/acf/shared/guns/grenadelauncher.lua b/lua/acf/shared/guns/grenadelauncher.lua index 95608a6f..904777a3 100644 --- a/lua/acf/shared/guns/grenadelauncher.lua +++ b/lua/acf/shared/guns/grenadelauncher.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("GL", { muzzleflash = "40mm_muzzleflash_noscale", rofmod = 1, year = 1970, - sound = "weapons/acf_gun/grenadelauncher.wav", + sound = "ace_weapons/multi_sound/12_7mm_multi.mp3", nolights = true, noloader = true, diff --git a/lua/acf/shared/guns/heavymachinegun.lua b/lua/acf/shared/guns/heavymachinegun.lua index 566cbdce..18c82164 100644 --- a/lua/acf/shared/guns/heavymachinegun.lua +++ b/lua/acf/shared/guns/heavymachinegun.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("HMG", { muzzleflash = "50cal_muzzleflash_noscale", rofmod = 0.17, year = 1935, - sound = "weapons/ACF_Gun/mg_fire3.wav", + sound = "ace_weapons/multi_sound/30mm_hmg_multi.mp3", noloader = true, longbarrel = { diff --git a/lua/acf/shared/guns/machinegun.lua b/lua/acf/shared/guns/machinegun.lua index 0c8d723c..559c7a31 100644 --- a/lua/acf/shared/guns/machinegun.lua +++ b/lua/acf/shared/guns/machinegun.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("MG", { muzzleflash = "50cal_muzzleflash_noscale", rofmod = 0.9, year = 1910, - sound = "weapons/ACF_Gun/mg_fire4.wav", + sound = "ace_weapons/multi_sound/7_62mm_multi.mp3", noloader = true, } ) diff --git a/lua/acf/shared/guns/mortar.lua b/lua/acf/shared/guns/mortar.lua index 3c72cac7..6607bbfa 100644 --- a/lua/acf/shared/guns/mortar.lua +++ b/lua/acf/shared/guns/mortar.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("MO", { muzzleflash = "40mm_muzzleflash_noscale", rofmod = 2, year = 1915, - sound = "weapons/ACF_Gun/mortar_new.wav", + sound = "ace_weapons/multi_sound/40mm_multi.mp3", } ) diff --git a/lua/acf/shared/guns/semiauto.lua b/lua/acf/shared/guns/semiauto.lua index 0bc2717d..e61ecdd2 100644 --- a/lua/acf/shared/guns/semiauto.lua +++ b/lua/acf/shared/guns/semiauto.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("SA", { muzzleflash = "30mm_muzzleflash_noscale", rofmod = 0.5, year = 1935, - sound = "acf_extra/tankfx/gnomefather/25mm1.wav", + sound = "ace_weapons/multi_sound/20mm_multi.mp3", noloader = true, } ) diff --git a/lua/acf/shared/guns/shortcannon.lua b/lua/acf/shared/guns/shortcannon.lua index ee4d590b..35615fef 100644 --- a/lua/acf/shared/guns/shortcannon.lua +++ b/lua/acf/shared/guns/shortcannon.lua @@ -6,8 +6,9 @@ ACF_defineGunClass("SC", { desc = ACFTranslation.GunClasses[13], muzzleflash = "120mm_muzzleflash_noscale", rofmod = 1.3, + maxrof = 25, -- maximum rounds per minute year = 1915, - sound = "weapons/acf_gun/cannon_new.wav", + sound = "ace_weapons/multi_sound/100mm_multi.mp3", } ) diff --git a/lua/acf/shared/guns/smokelauncher.lua b/lua/acf/shared/guns/smokelauncher.lua index 8f40b25d..40af6f83 100644 --- a/lua/acf/shared/guns/smokelauncher.lua +++ b/lua/acf/shared/guns/smokelauncher.lua @@ -7,7 +7,7 @@ ACF_defineGunClass("SL", { muzzleflash = "40mm_muzzleflash_noscale", rofmod = 45, year = 1941, - sound = "weapons/acf_gun/smoke_launch.wav", + sound = "ace_weapons/multi_sound/smoke_multi.mp3", nolights = true } ) diff --git a/lua/acf/shared/guns/smoothcannon.lua b/lua/acf/shared/guns/smoothcannon.lua index 9ed46c3f..3576f16b 100644 --- a/lua/acf/shared/guns/smoothcannon.lua +++ b/lua/acf/shared/guns/smoothcannon.lua @@ -6,7 +6,7 @@ ACF_defineGunClass("SBC", { desc = ACFTranslation.GunClasses[15], muzzleflash = "120mm_muzzleflash_noscale", rofmod = 1.7, - sound = "acf_extra/ace/weapons/cannon/125mm_1.wav", + sound = "ace_weapons/multi_sound/120mm_multi.mp3", year = 1960, } ) diff --git a/lua/entities/ace_crewseat_loader/init.lua b/lua/entities/ace_crewseat_loader/init.lua index 82cdc902..bca356a4 100644 --- a/lua/entities/ace_crewseat_loader/init.lua +++ b/lua/entities/ace_crewseat_loader/init.lua @@ -27,22 +27,62 @@ function ENT:Initialize() self:PhysicsInit(SOLID_VPHYSICS); self:SetUseType(SIMPLE_USE); self:SetSolid(SOLID_VPHYSICS); + self:GetPhysicsObject():SetMass(80) --70 kilo people plus 3 kg seat + Equipment self.Master = {} self.ACF = {} self.ACF.Health = 1 self.ACF.MaxHealth = 1 + self.Stamina = 100 --initial stamina for crewseat + self.LinkedGun = nil end +function ENT:DecreaseStamina() + local linkedGun = self.LinkedGun + --print("A") -function ENT:Think() - self:GetPhysicsObject():SetMass(65) --62 kilo people plus 3 kg seat, hooray + if IsValid(linkedGun) then + local bulletWeight = 0 + local distanceToCrate = 0 + + if linkedGun.BulletData then + local ProjMass = linkedGun.BulletData.ProjMass + local PropMass = linkedGun.BulletData.PropMass + bulletWeight = ProjMass + PropMass -- in kgs + end + + if IsValid(linkedGun.AmmoLink) then + local CurAmmo = linkedGun.CurAmmo -- current key in the table + distanceToCrate = linkedGun:GetPos():Distance(linkedGun.AmmoLink[CurAmmo]:GetPos()) -- in units + end + + local distance_multiplier = 0.05 + local staminaMultipliers = bulletWeight + distanceToCrate * distance_multiplier --* distanceToCrate + local staminaCost = 10 + staminaMultipliers -- take x points out of self.Stamina + self.Stamina = math.Round(self.Stamina - staminaCost) -- Update the instance variable + self.Stamina = math.max(self.Stamina, 20) -- so the gun doesn't take forever to reload, keep the second variable above 0 + --print(self.Stamina) + end +end + +function ENT:IncreaseStamina() + + local staminaHeal = 0.5 -- adjust me + self.Stamina = self.Stamina + staminaHeal -- Update the instance variable + + self.Stamina = math.Clamp(self.Stamina, 0, 100) + return self.Stamina +end + +function ENT:Think() if self.ACF.Health < self.ACF.MaxHealth * 0.989 then - ACF_HEKill( self, VectorRand() , 0) + ACF_HEKill(self, VectorRand(), 0) self:EmitSound("npc/combine_soldier/die" .. tostring(math.random(1, 3)) .. ".wav") end + self:IncreaseStamina() + print(self.Stamina) end diff --git a/lua/entities/acf_gun/init.lua b/lua/entities/acf_gun/init.lua index 8c171826..3d34490a 100644 --- a/lua/entities/acf_gun/init.lua +++ b/lua/entities/acf_gun/init.lua @@ -305,6 +305,7 @@ function ENT:UpdateOverlayText() self:SetOverlayText( text ) + end local function IsInRetDist( enta, entb, Distance ) @@ -388,6 +389,7 @@ function ENT:Link( Target ) table.insert( Target.Master, self ) self.LoaderCount = self.LoaderCount + 1 + Target.LinkedGun = self return true, "Link successful!" @@ -502,23 +504,30 @@ function ENT:CanProperty( _, property ) end -function ENT:TriggerInput( iname, value ) - - if (iname == "Unload" and value > 0 and not self.Reloading) then +function ENT:TriggerInput(iname, value) + if iname == "Unload" and value > 0 and not self.Reloading then + -- Triggered to unload ammo self:UnloadAmmo() - elseif ( iname == "Fire" and value > 0 and ACF.GunfireEnabled and self.Legal ) then + elseif iname == "Fire" and value > 0 and ACF.GunfireEnabled and self.Legal then + -- Triggered to fire if conditions are met if self.NextFire < CurTime() then - self.User = ACE_GetWeaponUser( self, self.Inputs.Fire.Src ) - if not IsValid(self.User) then self.User = self:CPPIGetOwner() end + -- Check if it's time to fire + self.User = ACE_GetWeaponUser(self, self.Inputs.Fire.Src) + if not IsValid(self.User) then + self.User = self:CPPIGetOwner() + end self:FireShell() self:Think() + self.Firing = true end - self.Firing = true - elseif ( iname == "Fire" and value <= 0 ) then + elseif iname == "Fire" and value <= 0 then + -- Triggered to stop firing self.Firing = false - elseif ( iname == "Reload" and value ~= 0 ) then + elseif iname == "Reload" and value ~= 0 then + -- Triggered to start reloading self.Reloading = true - elseif ( iname == "Fuse Time" ) then + elseif iname == "Fuse Time" then + -- Set the fuse time if value is greater than 0 if value > 0 then self.FuseTime = value self.OverrideFuse = true @@ -526,15 +535,18 @@ function ENT:TriggerInput( iname, value ) self.FuseTime = 0 self.OverrideFuse = false end - elseif (iname == "ROFLimit") then + elseif iname == "ROFLimit" then + -- Set the rate of fire limit if value is greater than 0 if value > 0 then - self.ROFLimit = math.min(1 / (value / 60), 600) --Im not responsible if your gun start firing 1 bullet each 10 mins. + self.ROFLimit = math.min(1 / (value / 60), 600) -- Limit the rate of fire else self.ROFLimit = 0 end end end + + function ENT:Heat_Function() --print(DeltaTime) @@ -764,6 +776,24 @@ end do + function ENT:ChooseLoader() + + local highestStaminaLoader = nil + local highestStamina = 0 + + for _, crewEnt in ipairs(self.CrewLink) do + if crewEnt:GetClass() == "ace_crewseat_loader" then + local stamina = crewEnt.Stamina + if stamina > highestStamina then + highestStamina = stamina + highestStaminaLoader = crewEnt + end + end + end + + return highestStaminaLoader + end + local FusedRounds = { HE = true, HEFS = true, @@ -844,6 +874,11 @@ do self:LoadAmmo(false, false) end Wire_TriggerOutput(self, "Ready", 0) + + if self.LoaderCount > 0 then + self:ChooseLoader():DecreaseStamina() + end + else self.CurrentShot = 0 @@ -893,12 +928,29 @@ function ENT:LoadAmmo( AddTime, Reload ) local Adj = not self.BulletData.LengthAdj and 1 or self.BulletData.LengthAdj --FL firerate bonus adjustment local CrewReload = 1 + local curLoaderStamina = 100 + + local curLoader = self:ChooseLoader() + if IsValid(curLoader) then + curLoaderStamina = curLoader.Stamina + end + + local maxRof = self.ROFLimit + if Lookup.maxrof then + maxRof = math.min(maxRof, Lookup.maxrof) + end if not (self.Class == "AC" or self.Class == "MG" or self.Class == "RAC" or self.Class == "HMG" or self.Class == "GL" or self.Class == "SA") then - CrewReload = 1.25-(self.LoaderCount * 0.25) + if self.LoaderCount > 0 then + CrewReload = curLoaderStamina / 100 + else + CrewReload = 1 + end end - self.ReloadTime = math.max(( ( math.max(self.BulletData.RoundVolume,self.MinLengthBonus * Adj) / 500 ) ^ 0.60 ) * self.RoFmod * self.PGRoFmod * CrewReload * (AmmoEnt.RoFMul + 1), self.ROFLimit) + local reloadTimeMath_Mul = self.RoFmod * self.PGRoFmod * CrewReload * (AmmoEnt.RoFMul + 1) + local reloadTimeMath = ((math.max(self.BulletData.RoundVolume, self.MinLengthBonus * Adj) / 500) ^ 0.60) * reloadTimeMath_Mul + self.ReloadTime = math.max(reloadTimeMath, maxRof) -- keeping it with 3 variables, because too many things in one line Wire_TriggerOutput(self, "Loaded", self.BulletData.Type) self.RateOfFire = (60 / self.ReloadTime) @@ -944,7 +996,7 @@ end function ENT:UnloadAmmo() - if not self.BulletData or not self.BulletData.Crate then return end -- Explanation: http://www.youtube.com/watch?v=dwjrui9oCVQ + if not self.BulletData or not self.BulletData.Crate then return end if not self.Ready then if (self.NextFire-CurTime()) < 0 then return end -- see above; preventing spam if self.MagSize > 1 and self.CurrentShot >= self.MagSize then return end -- prevent unload in middle of mag reload