Skip to content

Commit

Permalink
fixed explosion inconsistency + added radius convar
Browse files Browse the repository at this point in the history
  • Loading branch information
mexikoedi committed Jun 17, 2024
1 parent ea1ee20 commit 0de1ff2
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ SWEP.Primary.Recoil = 50
SWEP.Primary.Damage = GetConVar("ttt2_explosive_crosstol_damage"):GetInt()
SWEP.Primary.NumShots = -1
SWEP.Primary.Delay = 1
SWEP.Primary.Distance = 10
SWEP.Primary.Radius = GetConVar("ttt2_explosive_crosstol_radius"):GetInt()
SWEP.Primary.ClipSize = GetConVar("ttt2_explosive_crosstol_clipSize"):GetInt()
SWEP.Primary.DefaultClip = GetConVar("ttt2_explosive_crosstol_ammo"):GetInt()
SWEP.Primary.Automatic = GetConVar("ttt2_explosive_crosstol_automaticFire"):GetBool()
Expand Down Expand Up @@ -90,21 +90,35 @@ if SERVER then
function SWEP:PrimaryAttack()
self:SetNextPrimaryFire(CurTime() + self.Primary.Delay / self.Primary.RPS)
if not self:CanPrimaryAttack() then return end
local eyetrace = self:GetOwner():GetEyeTrace()
self.BaseClass.ShootEffects(self)
local owner = self:GetOwner()
if not IsValid(owner) then return end
local eyetrace = owner:GetEyeTrace()
local hitPos = eyetrace.HitPos
self:ShootEffects()
local explode = ents.Create("env_explosion")
explode:SetPos(eyetrace.HitPos)
explode:SetOwner(self:GetOwner())
explode:SetPos(hitPos)
explode:SetOwner(owner)
explode:Spawn()
explode:Fire("Explode", 0, 0)
explode:Fire("Explode", "", 0)
if GetConVar("ttt2_explosive_crosstol_attack_primary_sound"):GetBool() then explode:EmitSound("explosive_crosstol.wav", 400) end
local tr = self:GetOwner():GetEyeTrace()
local dmg = DamageInfo()
dmg:SetDamageType(64)
dmg:SetDamage(self.Primary.Damage / 2)
dmg:SetAttacker(self:GetOwner())
dmg:SetInflictor(self)
util.BlastDamageInfo(dmg, tr.HitPos, 300)
local radius = self.Primary.Radius
local maxDamage = self.Primary.Damage
local entities = ents.FindInSphere(hitPos, radius)
for _, ent in ipairs(entities) do
if IsValid(ent) and ent:IsPlayer() and ent:IsActive() then
local distance = hitPos:Distance(ent:GetPos())
local damage = maxDamage
if distance > 0 then damage = maxDamage * math.max(0, 1 - distance / radius) end
if ent == eyetrace.Entity then damage = maxDamage end
local dmgInfo = DamageInfo()
dmgInfo:SetDamage(damage)
dmgInfo:SetAttacker(owner)
dmgInfo:SetInflictor(self)
dmgInfo:SetDamageType(DMG_BLAST)
ent:TakeDamageInfo(dmgInfo)
end
end

self:TakePrimaryAmmo(1)
end
end
Expand All @@ -115,7 +129,7 @@ function SWEP:SecondaryAttack()
self.NextSecondaryAttack = CurTime() + self.Secondary.Delay
if SERVER and GetConVar("ttt2_explosive_crosstol_attack_secondary_sound"):GetBool() then
self.currentOwner = self:GetOwner()
self:GetOwner():EmitSound("explosive_crosstol2.wav")
if IsValid(self.currentOwner) then self.currentOwner:EmitSound("explosive_crosstol2.wav") end
end
end

Expand Down Expand Up @@ -145,6 +159,14 @@ if CLIENT then
decimal = 0
})

form:MakeSlider({
serverConvar = "ttt2_explosive_crosstol_radius",
label = "label_explosive_crosstol_radius",
min = 0,
max = 500,
decimal = 0
})

form:MakeSlider({
serverConvar = "ttt2_explosive_crosstol_ammo",
label = "label_explosive_crosstol_ammo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CreateConVar("ttt2_explosive_crosstol_attack_primary_sound", "1", {FCVAR_ARCHIVE
CreateConVar("ttt2_explosive_crosstol_attack_secondary_sound", "1", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Sound of the secondary attack")
CreateConVar("ttt2_explosive_crosstol_automaticFire", "0", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Enable automatic fire")
CreateConVar("ttt2_explosive_crosstol_damage", "100", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Damage dealt on impact")
CreateConVar("ttt2_explosive_crosstol_radius", "300", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Radius of the explosion")
CreateConVar("ttt2_explosive_crosstol_ammo", "1", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Default ammo the explosive crosstol has when bought")
CreateConVar("ttt2_explosive_crosstol_clipSize", "1", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Clipsize of the explosive crosstol")
CreateConVar("ttt2_explosive_crosstol_rps", "1", {FCVAR_ARCHIVE, FCVAR_NOTIFY}, "Shots per second")
Expand Down
5 changes: 3 additions & 2 deletions lua/terrortown/lang/de/crosstol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ L["label_explosive_crosstol_primary_sound"] = "Aktiviere primäres Angriffsgerä
L["label_explosive_crosstol_secondary_sound"] = "Aktiviere sekundäres Angriffsgeräusch"
L["label_explosive_crosstol_automaticFire"] = "Aktiviere automatisches Feuer"
L["label_explosive_crosstol_damage"] = "Schaden, der zugefügt werden sollte"
L["label_explosive_crosstol_ammo"] = "Munition die vorhanden sein sollte"
L["label_explosive_crosstol_clipSize"] = "Clipgröße die vorhanden sein sollte"
L["label_explosive_crosstol_radius"] = "Radius, in welchem Explosionsschaden zugefügt wird"
L["label_explosive_crosstol_ammo"] = "Munition, die vorhanden sein sollte"
L["label_explosive_crosstol_clipSize"] = "Clipgröße, die vorhanden sein sollte"
L["label_explosive_crosstol_rps"] = "Schüsse pro Sekunde"
1 change: 1 addition & 0 deletions lua/terrortown/lang/en/crosstol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ L["label_explosive_crosstol_primary_sound"] = "Enable primary attack sound"
L["label_explosive_crosstol_secondary_sound"] = "Enable secondary attack sound"
L["label_explosive_crosstol_automaticFire"] = "Enable automatic fire"
L["label_explosive_crosstol_damage"] = "Damage which should be dealt"
L["label_explosive_crosstol_radius"] = "Radius in which explosion damage is inflicted"
L["label_explosive_crosstol_ammo"] = "Ammo which should be available"
L["label_explosive_crosstol_clipSize"] = "Clip size which should be available"
L["label_explosive_crosstol_rps"] = "Shots per second"
1 change: 1 addition & 0 deletions lua/terrortown/lang/es/crosstol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ L["label_explosive_crosstol_primary_sound"] = "Habilitar sonido de ataque primar
L["label_explosive_crosstol_secondary_sound"] = "Habilitar sonido de ataque secundario"
L["label_explosive_crosstol_automaticFire"] = "Habilitar fuego automático"
L["label_explosive_crosstol_damage"] = "Daño que se debe infligir"
L["label_explosive_crosstol_radius"] = "Radio en el que se inflige el daño por explosión"
L["label_explosive_crosstol_ammo"] = "Munición que debería estar disponible"
L["label_explosive_crosstol_clipSize"] = "Tamaño de clip que debería estar disponible"
L["label_explosive_crosstol_rps"] = "Disparos por segundo"
1 change: 1 addition & 0 deletions lua/terrortown/lang/ru/crosstol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ L["label_explosive_crosstol_primary_sound"] = "Включить звук осн
L["label_explosive_crosstol_secondary_sound"] = "Включить вторичный звук атаки"
L["label_explosive_crosstol_automaticFire"] = "Включить автоматический огонь"
L["label_explosive_crosstol_damage"] = "Ущерб, который необходимо нанести"
L["label_explosive_crosstol_radius"] = "Радиус, в котором наносится урон от взрыва"
L["label_explosive_crosstol_ammo"] = "Боеприпасы, которые должны быть в наличии"
L["label_explosive_crosstol_clipSize"] = "Размер клипа, который должен быть в наличии"
L["label_explosive_crosstol_rps"] = "Выстрелов в секунду"

0 comments on commit 0de1ff2

Please sign in to comment.