First of all sorry for my terrible english skill
I upload video this will show you what is problem
[video=youtube;kHWrZ5jMGLs]http://www.youtube.com/watch?v=kHWrZ5jMGLs[/video]
As you can see owner of bathtub changes when another guy uses seed
So i need to fix this but i don't know how..
Thanks for any help!
Here my shared.lua of bathtub :
[code]
name = "Яблоня"
pname = "неизвестно"
function ENT:Use( activator, caller )
end
function ENT:Initialize()
timer.Create("start" .. tostring(self:EntIndex()), 1, 1, function()
if self:GetNWString("owner"):IsValid() then
pname = tostring(self:GetNWString("owner"):GetName())
end
self:SetNWInt("button",1)
end)
end
function ENT:DrawInfos()
local offset = Vector( 0, 0, 50 )
local ang = LocalPlayer(): EyeAngles()
local pos = self:GetPos() + offset + ang:Up()
if self:GetNWInt("button") == 1 then
cam.Start3D2D( pos, Angle( 0, ang.y - 90, 90 ), 0.25 )
draw.DrawText( name .. ". \n" .. "Посадил: " .. pname , "DrawFont", 2, 2, Color( 255, 255, 255, 255), TEXT_ALIGN_CENTER )
cam.End3D2D()
end
end
[/code]
Here code of seed init.lua
[code]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel( "models/props_lab/box01a.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
end
function ENT:Use( activator, caller )
local pos = self:GetPos()
local ent = ents.Create("plant_tree")
ent:SetPos( pos )
ent:Spawn()
ent:SetNWString("owner",activator)
self:Remove()
end
[/code]
-Snip bad reading-
name and pname is being shared across all of the entities. Put something like self.name = "BLah blah" in ENT:Initialize()
[QUOTE=Chessnut;42682584]name and pname is being shared across all of the entities. Put something like self.name = "BLah blah" in ENT:Initialize()[/QUOTE]
Thank you! now i know about self. thing in variables and fixed my poor code
Sorry, you need to Log In to post a reply to this thread.