Help With Entity I'm Making

Hey guys! First off, thanks for any help you provide.

Okay, so I’ve been trying to make my first entity ever and I’ve come into a problem that I don’t quite understand, I’m sure my issue is that I am just inexperienced and don’t understand it and I’m hoping one of you guys could explain it to me.

I have this code:

[lua]function ENT:Use( activator, caller )
local effectData = EffectData();
effectData:SetStart( self.Entity:GetPos() );
effectData:SetOrigin( self.Entity:GetPos() );
effectData:SetScale( 8 );
util.Effect( “GlassImpact”, effectData, true, true )

if (activator:IsPlayer()) then
SpawnDispenser()
self:Remove()
end
end[/lua]

[lua]function SpawnDispenser()

local ent = ents.Create(“jouarams_armordispenser”)
ent:SetPos(GetEyeTrace•().HitPos + Vector(0, 0, 16))
ent:Spawn()
ent:Activate()

end [/lua]

And I get this error when I press E on it:
init.lua:26: attempt to call method ‘GetEyeTrace•’ (a nil value)

Any suggestions? Thanks!

Sorry if I’m wrong, but is it just as simple as it seems? “GetEyeTrace” is just mispelled with a • at the end.

I’m not sure why the • appears, it isn’t in the code or visible to me when I copy, it only appears when I paste it

[editline]16th September 2015[/editline]

What encoding are you using?

UTF-8

As I’m aware of, facepunch doesn’t like unicode and it shows it.
That circle thing got into your code and is causing the error.
Delete that line and redo it but manually

Thanks. Did that and now I’m receiving this error:

attempt to call global ‘GetEyeTrace’ (a nil value)

Try doing “ply:GetEyeTrace” like as in the example on GetEyeTrace

EDIT: And I think the SpawnDispenser function would need a ply argument.

Like this:



function SpawnDispenser(ply)


attempt to call global ‘GetEyeTrace’ (a nil value)

with

[lua] ent:SetPos(ply:GetEyeTrace().HitPos + Vector(0, 0, 16)) [/lua]

Did you include the argument in the function? I’m sorry, it’s my fault, I edited that in later.

[lua]function SpawnDispenser(ply)

local ent = ents.Create(“jouarams_armordispenser”)
ent:SetPos(ply:GetEyeTrace().HitPos + Vector(0, 0, 16))
ent:Spawn()
ent:Activate()

end [/lua]

Still getting attempt to call global ‘GetEyeTrace’ (a nil value) on use

Try using ‘activator’ instead of ply.

I forgot to save when I retried with the new code, my bad.
With

[lua]function SpawnDispenser(ply)

local ent = ents.Create(“jouarams_armordispenser”)
ent:SetPos(ply:GetEyeTrace().HitPos + Vector(0, 0, 16))
ent:Spawn()
ent:Activate()

end [/lua]

I now get this error:

attempt to index global ‘ply’ (a nil value)

You’re not passing a player argument to SpawnDispenser

Could you show us the code where you are calling SpawnDispenser? Unless you have edited it from your original post, you aren’t supplying it with the ply argument. You need to call it with SpawnDispenser(activator).

[lua] function ENT:Use( activator, caller )
local effectData = EffectData();
effectData:SetStart( self.Entity:GetPos() );
effectData:SetOrigin( self.Entity:GetPos() );
effectData:SetScale( 8 );
util.Effect( “GlassImpact”, effectData, true, true )

if (activator:IsPlayer()) then
SpawnDispenser()
self:Remove()
end
end[/lua]



 function ENT:Use( activator, caller )
  local effectData = EffectData();
	effectData:SetStart( self.Entity:GetPos() );
	effectData:SetOrigin( self.Entity:GetPos() );
	effectData:SetScale( 8 );
  util.Effect( "GlassImpact", effectData, true, true )

  if (activator:IsPlayer()) then
    SpawnDispenser(activator) -- Pass the player argument
    self:Remove()
  end
end


That went straight over my head to even think of doing that.
Thanks so much for your time and help guys. Works perfectly now.