When I try to spawn an ent with a SWEP I made, it throws me the error:
Timer Failed! [Simple][@addons/sams_stuff/lua/weapons/fadingdooremp.lua (line 49)]
[ERROR] addons/sams_stuff/lua/weapons/fadingdooremp.lua:54: Tried to use a NULL entity!
1. __index - [C]:-1
2. unknown - addons/sams_stuff/lua/weapons/fadingdooremp.lua:54
Here is the code that causes the issue:
46 function SWEP:PrimaryAttack()
47 self:SendWeaponAnim(ACT_SLAM_THROW_THROW)
48 isthrowing = true
49 timer.Simple(0.1, function()
50 if SERVER then
51
52 local ent = ents.Create("fadeempent")
53 if !IsValid(ent) then return end
54 ent:SetPos( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 24 ) )
55 ent:SetAngles( self.Owner:EyeAngles() )
56 ent:Spawn()
57 local phys = ent:GetPhysicsObject()
58 if ( !IsValid( phys ) ) then ent:Remove() return end
59 local velocity = self.Owner:GetAimVector()
60 velocity = velocity * 10000
61 phys:ApplyForceCenter( velocity )
62
63 ent.DetonateOwner = self.Owner
64
65 self.Owner:StripWeapon(self:GetClass())
66 end
67 end)
68 end
I dont know why it is showing the entity as null, I can spawn it in the spawnmenu
Sorry if this is a stupid mistake I made, it's really late and I just want to get this done xD
My guess is that PrimaryAttack is being called several times every click, but since it strips itself, the second time around there's no "self.Owner" to set its position to.
Add a validity check to self.Owner as well.
Try checking if `self.Owner` is valid on line 53, since it throws the error when you're performing actions on the player.
Ok will try that, thanks
You need to check if self is valid before the self.Owner validity check.
thanks that worked!
Sorry, you need to Log In to post a reply to this thread.