Hello.
I am trying to draw.SimpleText() when player looking at entity.
But i can't get Variable from entity to show count.
I put this:
[code]
function ENT:SetupDataTables()
self:NetworkVar('Int', 1, 'Breads')
end
[/code]
in shared.lua
It's half of init.lua:
[code]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel( "models/props_c17/furnitureStove001a.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:SetTrigger(true)
self:SetUseType( SIMPLE_USE )
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then phys:Wake() end
self:SetOwner(self.Owner)
self.SID = self.Owner.SID
self.SID = self.Owner.SID
self:SetBreads(0)
end
[/code]
And there i am trying to GetBreads() value in cl_init.lua:
[code]
include('shared.lua')
function ENT:Draw()
self:DrawModel()
end
hook.Add("HUDPaint", "rp_stove", function()
local ply = LocalPlayer()
if !ply or !ply:IsValid() then return end
local tr = ply:GetEyeTrace()
if tr.Hit and tr.Entity:IsValid() and tr.Entity:GetClass() == "rp_stove" then
local pos = tr.HitPos
pos = pos:ToScreen()
draw.SimpleText("Stove |"..self:GetBreads(), "TargetID", pos.x, pos.y, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER)
end
end)
[/code]
Errors which i get:
[code]
[ERROR] addons/stove/lua/entities/rp_stove/cl_init.lua:15: attempt to index global 'self' (a nil value)
1. fn - addons/stove/lua/entities/rp_stove/cl_init.lua:15
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179
[/code]
I understand error text but I can't find info about how to get this variable in cl_init.lua.
You're doing self:GetBreads() where self means nothing. The only time self means something if it is in a function like ENT:Draw() or Swep:Deploy(), in functions like that self refers to whatever comes before the : like the ENT or the SWEP. You might want to use something like a networkvar to GetBreads.