TTT Remote Detonator for Traitors not working as it should

So I have this remote detonator swep that is suppose to be placeable on living and dead players and also on health stations. It won’t detonate at all after you place it a health station. When you detonate it on a living or dead player, it does not damage players or make props move like an explosion is suppose to do. You can see the explosion, but the damage doesn’t register.

Code is below, you can also view it via pastebin: http://pastebin.com/e4sQynXx

The file name on the server is “weapon_ttt_rdetonate.lua”


if SERVER then    AddCSLuaFile()
   
end
 
SWEP.HoldType                   = "slam"
 
   SWEP.PrintName = "Remote Detonator"
if CLIENT then
   SWEP.Slot = 6
 
   SWEP.ViewModelFOV = 10
 
   SWEP.EquipMenuData = {
      type = "item_weapon",
      desc = "Primary: Plant bomb on player or
a corpse.

Secondary: Trigger explosive."
   };
 
   SWEP.Icon = "VGUI/ttt/icon_splode"
end
 
 
SWEP.Base = "weapon_tttbase"
 
SWEP.ViewModel = "models/weapons/v_crowbar.mdl"
SWEP.WorldModel = "models/weapons/w_defuser.mdl"


SWEP.DrawCrosshair              = false
SWEP.Secondary.Damage         	= 400
SWEP.Primary.ClipSize           = -1
SWEP.Primary.DefaultClip        = -1
SWEP.Primary.Automatic          = true
SWEP.Primary.Delay = 0.15
SWEP.Primary.Ammo               = "none"
SWEP.Secondary.ClipSize         = -1
SWEP.Secondary.DefaultClip      = -1
SWEP.Secondary.Automatic        = true
SWEP.Secondary.Ammo             = "none"
SWEP.Secondary.Delay = 0.1
 
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
SWEP.WeaponID = AMMO_DEFUSER
SWEP.LimitedStock = true -- only buyable once
 
 
--SWEP.AllowDrop = false
 
local sou = Sound("Weapon_TMP.Clipin")
local sou2 = Sound("Default.PullPin_Grenade")
 
local function tWarn(ent,armed)
  umsg.Start("c4_warn", GetTraitorFilter(true))
  umsg.Short(ent:EntIndex())
  umsg.Bool(armed)
  umsg.Vector(ent:GetPos())
  umsg.Float(0)
  umsg.End()
end
 
function SWEP:PrimaryAttack()
        if not IsValid(self.Owner) then return end
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
   if self.attach then return false end
   if SERVER and self.Owner:GetNWBool('disguised',false) == true and string.len(self.Owner:GetNWString('disgas','')) > 0 then self.Owner:ConCommand('ttt_set_disguise 0') end
        if SERVER and _rdm then
                local stid = self.Owner:SteamID()
                if not _rdm.shotsFired[stid] then _rdm.shotsFired[stid] = {} end
                table.insert(_rdm.shotsFired[stid],CurTime())
        end
        if SERVER and ShootLog then ShootLog(Format("WEAPON:	 %s [%s] planted a %s", self.Owner:Nick(), self.Owner:GetRoleString(), self.Weapon:GetClass())) end
 
   local spos = self.Owner:GetShootPos()
   local sdest = spos + (self.Owner:GetAimVector() * 120)
        if self.Owner.LagCompensation then -- for some reason not always true
      self.Owner:LagCompensation(true)
   end
   local tr = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT})
   if not tr.Entity or not IsValid(tr.Entity) then return end
        if IsValid(tr.Entity) and tr.Entity:GetClass() == "player" then
                if SERVER then
                        local ply = tr.Entity
                        if not self.attach then
                                self.attach = ply:UniqueID()
                                self.atype = 'ply'
                                sound.Play(sou,ply:GetPos(),40)
                                if tWarn then tWarn(ply,true) end
                        end
                end
        elseif IsValid(tr.Entity) and tr.Entity:GetClass() == "prop_ragdoll" and tr.Entity.player_ragdoll then
                if SERVER then
                        local rag = tr.Entity
                        if not self.attach then
                                self.attach = rag.uqid
                                self.atype = 'rag'
                                sound.Play(sou,rag:GetPos(),40)
                                if tWarn then tWarn(rag,true) end
                        end
                end
        elseif IsValid(tr.Entity) and tr.Entity:GetClass() == 'ttt_health_station' then
                if SERVER then
                        tr.toexp = self.Owner
                        self.attach = tr.Entity:EntIndex()
                        self.atype = 'hs'
                        sound.Play(sou,tr.Entity:GetPos(),40)
                        if tWarn then tWarn(tr.Entity,true) end
                end
        end
        if self.attach then
                self.planted = CurTime()
                self.Owner:ChatPrint("Planted!")
                self.Owner:AnimPerformGesture(ACT_GMOD_GESTURE_ITEM_GIVE)
        end
        self.Weapon:SetNextPrimaryFire( CurTime() + (self.Primary.Delay * 2) )
        if self.Owner.LagCompensation then
      self.Owner:LagCompensation(false)
   end
end
 
function SWEP:Detonate(v,t)
        if SERVER and self.Owner:GetNWBool('disguised',false) == true and string.len(self.Owner:GetNWString('disgas','')) > 0 then self.Owner:ConCommand('ttt_set_disguise 0') end
        if SERVER and _rdm then
                local stid = self.Owner:SteamID()
                if not _rdm.shotsFired[stid] then _rdm.shotsFired[stid] = {} end
                table.insert(_rdm.shotsFired[stid],CurTime())
        end
        if SERVER and ShootLog then ShootLog(Format("WEAPON:	 %s [%s] detonated a %s", self.Owner:Nick(), self.Owner:GetRoleString(), self.Weapon:GetClass())) end
        local pos = v:GetPos()
        local effect = EffectData()
        effect:SetStart(pos)
        effect:SetOrigin(pos)
        local rad = 50
        local dmg = 50
        effect:SetScale(rad * 0.2)
        effect:SetRadius(rad)
        effect:SetMagnitude(dmg)
        util.Effect("Explosion", effect, true, true)
        local ent = ents.Create("weapon_ttt_rdetonate")
        util.BlastDamage(ent,self.Owner,pos,rad,dmg)
        ent:Remove()
end
 
function SWEP:SecondaryAttack()
        if SERVER then
                if self.planted and CurTime()-self.planted < 1 then return end
                if self.attach and self.attach != -1 then
                        if self.atype == 'hs' then
                                for k,v in pairs(ents.FindByClass('ttt_new_hp')) do
                                        if v:EntIndex() == self.attach then
                                                self.attach = -1
                                                sound.Play(Sound("Default.PullPin_Grenade"),v:GetPos())
                                                --timer.Simple(2, function()
                                                        if tWarn then tWarn(v,false) end
                                                        self:Detonate(v,1)
                                                        self:Remove()
                                                --end)
                                                break
                                        end
                                end
                        else
                                for _, v in ipairs( player.GetAll() ) do
                                        if v:UniqueID() == self.attach then
                                                if not v:Alive() then
                                                        for _, v2 in ipairs( ents.FindByClass("prop_ragdoll") ) do
                                                                if IsValid(v2) then
                                                                        if v2.player_ragdoll and v2.uqid == self.attach then
                                                                                self.attach = -1
                                                                                sound.Play(sou2,v2:GetPos())
                                                                                --timer.Simple(2, function()
                                                                                        if tWarn then tWarn(v,false) tWarn(v2,false) end
                                                                                        self:Detonate(v2,1)
                                                                                        self:Remove()
                                                                                --end)
                                                                                break
                                                                        end
                                                                end
                                                        end
                                                else
                                                        self.attach = -1
                                                        sound.Play(sou2,v:GetPos())
                                                        --timer.Simple(2, function()
                                                                if tWarn then tWarn(v,false) end
                                                                self:Detonate(v,2)
                                                                self:Remove()
                                                        --end)
                                                end
                                                return true
                                        end
                                end
                        end
                end
        end
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
   self.Weapon:SetNextSecondaryFire( CurTime() + 0.1 )
end
 
 
if CLIENT then
   function SWEP:Initialize()
      //self:AddHUDHelp("defuser_help", nil, true)
                self.attach = nil
      return self.BaseClass.Initialize(self)
   end
 
   function SWEP:DrawWorldModel()
      if not IsValid(self.Owner) then
         self:DrawModel()
      end
   end
end
 
function SWEP:Reload()
   return false
end
 
function SWEP:Deploy()
   if SERVER and IsValid(self.Owner) then
      self.Owner:DrawViewModel(false)
   end
   return true
end
 
 
function SWEP:OnDrop()
end

Any help would be appreciated, even if it only solves a small part of this problem. Also if any other information is needed, just ask.

Explosions can be tricky if not done right. Odd effects can occur like no damage, etc… Magnitude is limited to 100 per explosion, but they stack… Take a look at my code: https://bitbucket.org/Acecool/acecooldev_base/src/160f40f48be46367b3b98c905ed4a0fb4c5819c4/gamemode/server/core/util_createexplosion.lua?at=master

Makes things easier, handles magnitude and blast damage. When you place the bomb on something, I’d recommend enabling a tracker on your swep to track the pos. When detonated, get the tracked entity position ( when you place it, just set a var like tracked = target entity ) and move the explosion up 16 units or so ( 1 foot ). The explosion could be happening underground.

weapon_ttt_rdetonator.lua

if SERVER then AddCSLuaFile( “shared.lua” )

end

Change AddCSLuaFile(“shared.lua”) to AddCSLuaFile()

Ok, I passed on this information to the person who made it. He said “I might just need to make a entity file for it. Which takes like 5 minutes.” Would this fix our problems with the SWEP or would he still need to look at what Acecool mentioned?

Also thanks Sm63, for noticing that.

Could you tell me, who made it? I need to confirm something, this is a little offtopic, but I need to know what you know.

He actually didn’t make it. It must have been stolen off of my server.

You can use it though. I don’t mind but don’t let him lie to you and definitely don’t give him any money for it.

EDIT:

To fix it, change “local ent = ents.Create(“weapon_ttt_remote”)” to “local ent = ents.Create(“weapon_ttt_rdetonate”)”

It was “made” by a mod on our server.

You have my apologies if he really did take this from your server without permission. Also thanks for letting us use it.

The error I am getting when I use it is:


[ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_rdetonator.lua:139: Tried to use a NULL entity!
  1. BlastDamage - [C]:-1
   2. Detonate - gamemodes/terrortown/entities/weapons/weapon_ttt_rdetonator.lua:139
    3. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_rdetonator.lua:183

Fixed and cleaned it up for you:

Thank you! It works now. It just needs some slight adjustments in range and damage which is easy enough to do. Also thanks again for fixing this and for your permission to use it even though it is highly likely that our mod took it from you without giving credit.