Lua Error TTT Server (Golden Deagle/Damageinfo)

Hello =)

I have a TTT Server and I am trying to solve some lua errors. Maybe you guys can help me by this problem. I solved a few errors by my own but I dont know what I should do here. If players shoot with the golden deagle I get this lua error on my server (3 times in a row):

Picture of the errors:

[ERROR] lua/weapons/weapon_ttt_goldendeagle.lua:96: Tried to use a NULL entity!

  1. EmitSound - [C]:-1
  2. oldprimary - lua/weapons/weapon_ttt_goldendeagle.lua:96
  3. unknown - lua/sv_damageinfos.lua:34

Here is the golden deagle weapon script



if SERVER then
   AddCSLuaFile()
end
 
if CLIENT then
   SWEP.PrintName = "Golden Deagle"
   SWEP.Slot = 6
   SWEP.Icon = "vgui/ttt/icon_goldendeagle"
end
 
-- Always derive from weapon_tttbase
SWEP.Base = "weapon_tttbase"
 
-- Standard GMod values
SWEP.HoldType = "pistol"
 
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 0.08
SWEP.Primary.Recoil = 1.2
SWEP.Primary.Cone = 0.025
SWEP.Primary.Damage = 1
SWEP.Primary.Automatic = false
SWEP.Primary.ClipSize = 2
SWEP.Primary.DefaultClip = 2
SWEP.Primary.Sound = Sound( "weapons/goldendeagle/goldendeagle.wav" )
 
-- Model settings
SWEP.UseHands = true
SWEP.ViewModelFlip = true
SWEP.ViewModelFOV = 72
SWEP.ViewModel = "models/weapons/v_powerdeagle.mdl"
SWEP.WorldModel = "models/weapons/w_powerdeagle.mdl"
 
SWEP.IronSightsPos = Vector( -6.361, -3.701, 2.15 )
SWEP.IronSightsAng = Vector( 0, 0, 0 )
 
--- TTT config values
 
-- Kind specifies the category this weapon is in. Players can only carry one of
-- each. Can be: WEAPON_... MELEE, PISTOL, HEAVY, NADE, CARRY, EQUIP1, EQUIP2 or ROLE.
-- Matching SWEP.Slot values: 0      1       2     3      4      6       7        8
SWEP.Kind = WEAPON_EQUIP1
 
-- If AutoSpawnable is true and SWEP.Kind is not WEAPON_EQUIP1/2, then this gun can
-- be spawned as a random weapon.
SWEP.AutoSpawnable = false
 
-- CanBuy is a table of ROLE_* entries like ROLE_TRAITOR and ROLE_DETECTIVE. If
-- a role is in this table, those players can buy this.
SWEP.CanBuy = { ROLE_DETECTIVE }
 
-- InLoadoutFor is a table of ROLE_* entries that specifies which roles should
-- receive this weapon as soon as the round starts. In this case, none.
SWEP.InLoadoutFor = { nil }
 
-- If LimitedStock is true, you can only buy one per round.
SWEP.LimitedStock = true
 
-- If AllowDrop is false, players can't manually drop the gun with Q
SWEP.AllowDrop = true
 
-- If IsSilent is true, victims will not scream upon death.
SWEP.IsSilent = false
 
-- If NoSights is true, the weapon won't have ironsights
SWEP.NoSights = false
 
-- Equipment menu information is only needed on the client
if CLIENT then
   SWEP.EquipMenuData = {
      type = "item_weapon",
      desc = "Shoot a traitor, kill a traitor. 
Shoot an innocent, kill yourself. 
Be careful."
   };
end
 
function SWEP:PrimaryAttack()
        if ( !self:CanPrimaryAttack() ) then return end
        self:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
        local trace = util.GetPlayerTrace(self.Owner)
        local tr = util.TraceLine(trace)
 
        if tr.Entity.IsPlayer() then
                if tr.Entity:IsRole(ROLE_TRAITOR) then
                        bullet = {}
                        bullet.Num = self.Primary.NumberofShots
                        bullet.Src = self.Owner:GetShootPos()
                        bullet.Dir = self.Owner:GetAimVector()
                        bullet.Spread = Vector( 0, 0, 0 )
                        bullet.Tracer = 0
                        bullet.Force = 1000
                        bullet.Damage = 1000
                        bullet.AmmoType = self.Primary.Ammo
                        self.Owner:FireBullets(bullet)
                        self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
                        self:TakePrimaryAmmo(1)
                        self.Weapon.EmitSound(Sound( "Weapon_Deagle.Single" ))
                        return
                elseif tr.Entity:IsRole(ROLE_INNOCENT) or tr.Entity:IsRole(ROLE_DETECTIVE) then
                        self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
                        self.Weapon:EmitSound(Sound( "Weapon_Deagle.Single" ))
                        self:TakePrimaryAmmo(1)
                        if SERVER then
                                self.Owner:Kill()
                        end
                        return
        end
        end
        self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
        self:TakePrimaryAmmo(1)
        self.Owner:EmitSound(Sound( "Weapon_Deagle.Single" ))
        return
end


After that there is an error through the damagelog:

[ERROR] lua_sv_damageinfos.lua:15: attempt to call method ‘Nick’ (a nil value)

  1. shootCallback - lua/sv_damageinfos.lua:15
  2. unknown - lua/sv_damageinfos.lua:35

And here is the sv_damageinfos.lua script:



util.AddNetworkString("DL_AskDamageInfos")
util.AddNetworkString("DL_SendDamageInfos")
util.AddNetworkString("DL_AskShootLogs")
util.AddNetworkString("DL_SendShootLogs")
 
function Damagelog:shootCallback(weapon)
        local owner = weapon.Owner
        if GetRoundState() == ROUND_ACTIVE then
                if self.ShootTables[self.CurrentRound][self.Time] then
                        local info = { owner:Nick(), weapon:GetClass() }
                        table.insert(self.ShootTables[self.CurrentRound][self.Time], info)                     
                else
                        table.insert(self.ShootTables[self.CurrentRound], self.Time, {})
                        local info = { owner:Nick(), weapon:GetClass() }
                        table.insert(self.ShootTables[self.CurrentRound][self.Time], info)
                end
        end
end
         
function Damagelog:DamagelogInfos()
        for k,v in pairs(weapons.GetList()) do         
                if v.Base == "weapon_tttbase" then
                        if not v.PrimaryAttack then
                                v.PrimaryAttack = function(wep)
                                        wep.BaseClass.PrimaryAttack(wep)
                                        if wep.BaseClass.CanPrimaryAttack(wep) and IsValid(wep.Owner) then
                                                self:shootCallback(wep)
                                        end
                                end
                        else
                                local oldprimary = v.PrimaryAttack
                                v.PrimaryAttack = function(wep)
                                        oldprimary(wep)
                                        Damagelog:shootCallback(wep)
                                end
                        end
                end
        end
end
       
hook.Add("Initialize", "Initialize_DamagelogInfos", function() 
        Damagelog:DamagelogInfos()
end)
 
function Damagelog:SendDamageInfos(ply, t, att, victim, round)
        local results = {}
        local found = false
        for k,v in pairs(self.ShootTables[round] or {}) do
            if k >= t - 10 and k <= t then
                    for s,i in pairs(v) do
                        if i[1] == victim or i[1] == att then
                            if results[k] == nil then
                                            table.insert(results, k, {})
                                        end
                                        table.insert(results[k], i)
                                found = true
                                end
                        end
                end
        end
        local beg = t - 10
        if found then
                net.Start("DL_SendDamageInfos")
                net.WriteUInt(0,1)
                net.WriteUInt(beg, 32)
                net.WriteUInt(t, 32)
                net.WriteTable(results)
                net.WriteString(victim)
                net.WriteString(att)
                net.Send(ply)
        else
                net.Start("DL_SendDamageInfos")
                net.WriteUInt(1,1)
                net.WriteUInt(beg, 32)
                net.WriteUInt(t, 32)
                net.WriteString(victim)
                net.WriteString(att)
                net.Send(ply)
    end
end
 
net.Receive("DL_AskDamageInfos", function(_, ply)
        local time = net.ReadUInt(32)
        local attacker = net.ReadString()
        local victim = net.ReadString()
        local round = net.ReadUInt(32)
        Damagelog:SendDamageInfos(ply, time, attacker, victim, round)
end)
 
local orderedPairs = Damagelog.orderedPairs
net.Receive("DL_AskShootLogs", function(_, ply)
        if not ply:CanUseDamagelog() then return end
        local data = Damagelog.ShootTables[net.ReadUInt(8)]
        if not data then return end
        data = table.Copy(data)
        local count = table.Count(data)
        local i = 0
        if count <= 0 then
                net.Start("DL_SendShootLogs")
                net.WriteTable({"empty"})
                net.WriteUInt(1, 1)
                net.Send(ply)
        else
                for k,v in orderedPairs(data) do
                        i = i + 1
                        net.Start("DL_SendShootLogs")
                        net.WriteTable(v)
                        net.WriteUInt(i == count and 1 or 0, 1)
                        net.Send(ply)
                end
        end
end)


I hope you can help me and if there are any questions feel free to ask me =D

Can you post the log code in a Pastebin? Facepunch’s code parser screwed it up.

I tried to edit my first post =) Please tell me if the code is now readable

And here are the links to Pastebin if it doesnt work at all:

weapon_ttt_goldendeagle.lua:

sv_damageinfos.lua:

Nobody can help me? =(

Try “self.Weapon:EmitSound” instead of “self.Weapon.EmitSound”

self:EmitSound rather, self.Weapon is deprecated.

I will try it instantly =) I switched “self.Weapon.EmitSound” to self:EmitSound

and it worked :smiley: Thank you guys!

Now there is just the damageinfo error ( The second part of my post :< )

Where did you get that second file? Did it come with the gun?

Yes if I shoot with the golden deagle

No he means the file itself, not the error

The second file is from damageinfo, it is another addon

Edit: The Damageinfo is from tommy228 with the RDM Manager together

Well why isn’t it in addons?

I am using FastDL so normally I put my addons in the garrysmod folder (because of addons with materials or resources etc.) but shouldnt be a problem? Correct me if I’m wrong