My entity and weapon are now working. Im just having a few minor problems.
First one is pretty simple. I want the entity to remove itself after 10 secounds. How can i do that?
Secoundly im getting this error:
[ERROR] addons/name 10 thing that arent/lua/entities/the_button/init.lua:59: bad argument #2 to 'Simple' (function expected, got no value)
1. Simple - [C]:-1
2. unknown - addons/name 10 thing that arent/lua/entities/the_button/init.lua:59
It oviously referring to this function:
local pos = self:GetPos()
for k, v in pairs(player.GetAll()) do
if v:GetPos():Distance(pos) <= 50 then
timer.Simple(10,function() v:TakeDamage( 1)) -- I added the
--timer to stop the entity from killing people almost instantly and spamming them
--with damage. Also this is the line its referring to
And lastly i want the entity to spawn a bit further away from the player ( always barely outside its radius so the shooter doesnt get hurt ) and it should also fly further.
Here is the code i have been using to calculate the velocity( its in the swep ):
if(CLIENT) then return end
local ent = ents.Create("the_button")
if(!IsValid(ent)) then return end
ent:SetPos(self.Owner:EyePos()+(self.Owner:GetAimVector() * 16))
ent:SetAngles( self.Owner:EyeAngles ())
local phys = ent:GetPhysicsObject()
if ( !IsValid (phys)) then ent:Remove() return end
local velocity = self.Owner:GetAimVector()
velocity = velocity + (VectorRand() * 10)