Timer Failed!

Hello everyone, I have a problem with an addon and I try to solve the problem but I can not. It is actually a problem that comes from a timer (in a way it does not find value because the object has no physical but good) I would like to know if it is possible to m ’ help

This is error:

[ERROR] addons/dalek/lua/weapons/weapon_dalek_gun/shared.lua:95: attempt to call method ‘TakeDamageInfo’ (a nil value)

  1. unknown - addons/dalek/lua/weapons/weapon_dalek_gun/shared.lua:95

Timer Failed! [Simple][@addons/dalek/lua/weapons/weapon_dalek_gun/shared.lua (line 95)]*

Here is the Code file:

if ( SERVER ) then

AddCSLuaFile( "shared.lua" )

end

if ( CLIENT ) then

SWEP.PrintName			= "Dalek Ray Gun"			
SWEP.Author				= ""
SWEP.Slot				= 0
SWEP.SlotPos			= 1
SWEP.BounceWeaponIcon     = false
SWEP.DrawWeaponInfoBox = false

killicon.Add("weapon_dalek_gun","HUD/killicons/dalek/dalek",Color ( 255, 80, 0, 255 ) )

end

SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;
SWEP.Weight = 5;
SWEP.AutoSwitchTo = false;
SWEP.AutoSwitchFrom = false;
SWEP.UseHands = false
modeledit = Vector( 3, 0, -10)

SWEP.Category = “Dr. Who”

SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;
SWEP.ViewModel = “models/weapons/v_dalekray.mdl”;
SWEP.WorldModel = “models/weapons/w_dalekray.mdl”;
SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = -1;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = “none”;
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = “none”;
SWEP.Secondary.Delay = 1

SWEP.BaseCrit = 28;
SWEP.CritChance = 28;

SWEP.SoundOn = true
SWEP.Delay=0.5
SWEP.Range=1000
SWEP.Damage=9999
SWEP.DefaultDamage = 50
SWEP.Charging = false;

function SWEP:Initialize()
self:SetWeaponHoldType(“pistol”)

end

function SWEP:PrimaryAttack()

self:SetNextPrimaryFire(CurTime() + self.Delay)
self.Owner:SetAnimation(PLAYER_ATTACK1)



local pos = self:GetBonePosition( self:LookupBone( "ValveBiped.Bip01_R_Hand") )
local tracedata = {}
tracedata.start = self.Owner:EyePos()
tracedata.endpos = self.Owner:EyePos()+(self.Owner:GetAimVector()*self.Range)
tracedata.filter = {self.Owner}
local trace = util.TraceLine(tracedata)
util.ParticleTracerEx( "weapon_combine_ion_cannon_beam", pos, trace.HitPos, self , 1,  0 )
self:EmitSound( "dalek/dalek_shoot.wav", 90, 100 )
if(trace.Hit)then
	if trace.Entity:IsNPC() or trace.Entity:IsPlayer() then
    local cadaverific = trace.Entity
	if cadaverific:IsPlayer() then
    local cadaverific = trace.Entity		
    end

local dmg = DamageInfo()
dmg:SetDamage(9999)
dmg:SetInflictor(self)
dmg:SetDamageType( 1024 )
dmg:SetDamagePosition(cadaverific:GetPos())
dmg:SetAttacker(self.Owner)
timer.Simple(0.5, function() cadaverific:TakeDamageInfo( dmg, self ) end )

end
self.Owner:ViewPunch( Angle( -5, -5, 0 ) )

end
end

function SWEP:SecondaryAttack()

    self:EmitSound( "dalek/dalek.wav", 90, 100 )

end

function SWEP:AdjustMouseSensitivity()
if self.Owner:GetVelocity():Length() > 450 and self.Owner:OnGround() then
return 0.05
else
return 1
end
end

function SWEP:Deploy()
self:SendWeaponAnim(ACT_HL2MP_IDLE_FIST)
end

function SWEP:setReloadingFalse()
self:SetNetworkedBool( “reloading”, false)
end

Here is an image to better understand my problem.

https://img15.hostingpics.net/pics/304962Sanstitre.png

Moved to the developer discussion, please post anything regarding scripts/addons there.

Also please wrap your code in [lua] tags.

[lua]
if ( SERVER ) then

 AddCSLuaFile( "shared.lua" )

end

if ( CLIENT ) then

 SWEP.PrintName	= "Dalek Ray Gun"
 SWEP.Author	= ""
 SWEP.Slot	= 0
 SWEP.SlotPos	= 1
 SWEP.BounceWeaponIcon = false
 SWEP.DrawWeaponInfoBox = false

 killicon.Add("weapon_dalek_gun","HUD/killicons/dalek/dalek",Color ( 255, 80, 0, 255 ) )

end

SWEP.DrawAmmo = false;
SWEP.DrawCrosshair = true;
SWEP.Weight = 5;
SWEP.AutoSwitchTo = false;
SWEP.AutoSwitchFrom = false;
SWEP.UseHands = false
modeledit = Vector( 3, 0, -10)

SWEP.Category = “Dr. Who”

SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;
SWEP.ViewModel = “models/weapons/v_dalekray.mdl”;
SWEP.WorldModel = “models/weapons/w_dalekray.mdl”;
SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = -1;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = “none”;
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo = “none”;
SWEP.Secondary.Delay = 1

SWEP.BaseCrit = 28;
SWEP.CritChance = 28;

SWEP.SoundOn = true
SWEP.Delay=0.5
SWEP.Range=1000
SWEP.Damage=9999
SWEP.DefaultDamage = 50
SWEP.Charging = false;

function SWEP:Initialize()
self:SetWeaponHoldType(“pistol”)

end

function SWEP:PrimaryAttack()

 self:SetNextPrimaryFire(CurTime() + self.Delay)
 self.Owner:SetAnimation(PLAYER_ATTACK1)



 local pos = self:GetBonePosition( self:LookupBone( "ValveBiped.Bip01_R_Hand") )
 local tracedata = {}
 tracedata.start = self.Owner:EyePos()
 tracedata.endpos = self.Owner:EyePos()+(self.Owner:GetAimVector()*self.Range)
 tracedata.filter = {self.Owner}
 local trace = util.TraceLine(tracedata)
 util.ParticleTracerEx( "weapon_combine_ion_cannon_beam", pos, trace.HitPos, self , 1, 0 )
 self:EmitSound( "dalek/dalek_shoot.wav", 90, 100 )
 if(trace.Hit)then
      if trace.Entity:IsNPC() or trace.Entity:IsPlayer() then
           local cadaverific = trace.Entity
           if cadaverific:IsPlayer() then
                local cadaverific = trace.Entity
           end
           local dmg = DamageInfo()
           dmg:SetDamage(9999)
           dmg:SetInflictor(self)
           dmg:SetDamageType( 1024 )
           dmg:SetDamagePosition(cadaverific:GetPos())
           dmg:SetAttacker(self.Owner)
           timer.Simple(0.5, function() cadaverific:TakeDamageInfo( dmg, self ) end )

      end
      self.Owner:ViewPunch( Angle( -5, -5, 0 ) )


 end

end

function SWEP:SecondaryAttack()

 self:EmitSound( "dalek/dalek.wav", 90, 100 )

end

function SWEP:AdjustMouseSensitivity()
if self.Owner:GetVelocity():Length() > 450 and self.Owner:OnGround() then
return 0.05
else
return 1
end
end

function SWEP:Deploy()
self:SendWeaponAnim(ACT_HL2MP_IDLE_FIST)
end

function SWEP:setReloadingFalse()
self:SetNetworkedBool( “reloading”, false)
end
[/lua]

Let me start off by saying, you don’t want to use timers. Whenever possible just use variables like SWEP.TimeUntilThisThingGoesOff = CurTime() + 0.5, timers are a real pain and you always have to remember to stop them, if they go off and for example you don’t have the gun out and can’t run the function, they will return an error, so you have to remember to disable them when you die, or lose the gun, or holster it, or change it, etc.
To fix your problem (While still using timers, which you shouldn’t in my opinion) you should do something like this:

[lua]
function takeTheGodDamnDamage(victim, damage, weapon)

 victim:TakeDamageInfo(damage, weapon)

end

timer.Simple(0.5, takeTheGodDamnDamage(cadaverific, dmg, self))
[/lua]

Also you probably forgot to run it only serverside, since ENT:TakeDamageInfo can be run only serverside, and I guess it returned the error clientside

PS. If the error gets printed in your console is the color orange, it’s clientside, if it’s blue, it’s serverside

EDIT: Also sorry if I auto indented your code, I just didn’t like it, also first code I posted isn’t the fixed version, it’s just your version put in a lua tag and auto indented.

This is wrong. You are creating a timer, to call every 0.5 seconds what is returned by the takeTheGodDamnDamage(victim, damage, weapon) function. As this function doesn’t return anything, your timer.Simple call evaluates to

[lua]
timer.Simple(0.5, nil)
[/lua]

It does not work:

[ERROR] addons/dalek/lua/weapons/dw_dalek_gun/shared.lua:95: bad argument #2 to ‘Simple’ (function expected, got nil)

  1. Simple - [C]:-1
  2. unknown - addons/dalek/lua/weapons/dw_dalek_gun/shared.lua:95

Well, not much I know about timers, I made it pretty clear I hate them haha. Guess he would just have to go with the second option (Make a local variable as the timer and keep checking if it’s smaller then CurTime())

I don’t understand

Ignore what I said earlier, use your first original code and tell me, which color is the error printed? Is it orange or blue? Or both?

TakeDamageInfo() doesn’t exist on client.

[lua]if( SERVER ) then … end[/lua]

Problemo Solvedo

Thank you !

Please mark it as solved.

(Also that moment when your first post includes the fix but it got ignored)

Little problem with dalek swep

https://steamuserimages-a.akamaihd.net/ugc/868492508833105934/DAA9F6D01710C42DE76B8EBBD2D0F7F12F79C47F/?interpolation=lanczos-none&output-format=jpeg&output-quality=95&fit=inside|1024:576&composite-to%3D*%2C*|1024%3A576&background-color=black

When I shoot it pulls from a single player