One Pot with up to 5 Seeds?

I’m trying to get a pot to accept up to 5 different “Seeds” that when placed against it, will grow and give 1 piece of whatever the seed was. Such as; A weed Seed in the Pot will put out 1 weed, but if you put a Coca seed in the pot, it will put out 1 cocaine.

Here’s the code;

[LUA]AddCSLuaFile(“cl_init.lua”)

AddCSLuaFile(“shared.lua”)

include(“shared.lua”)

function ENT:Initialize()

self.Entity:SetModel(“models/nater/weedplant_pot_dirt.mdl”)

self.Entity:PhysicsInit(SOLID_VPHYSICS)

self.Entity:SetColor(255, 255, 255, 255)

self.Entity:SetMoveType(MOVETYPE_VPHYSICS)

self.Entity:SetSolid(SOLID_VPHYSICS)

self.Entity:SetUseType(SIMPLE_USE)

local phys = self.Entity:GetPhysicsObject()

if phys and phys:IsValid() then phys:Wake() end

self.Entity:SetNWBool(“Usable”, false)

self.Entity:SetNWBool(“Plantable”, true)

self.damage = 10

local ply = self.Entity:GetNWEntity(“owning_ent”)

end

function ENT:OnTakeDamage(dmg)

self.damage = self.damage - dmg:GetDamage()

if (self.damage <= 0) then

local effectdata = EffectData()

effectdata:SetOrigin(self.Entity:GetPos())

effectdata:SetMagnitude(2)

effectdata:SetScale(2)

effectdata:SetRadius(3)

util.Effect(“Sparks”, effectdata)

self.Entity:Remove()

end

end


function ENT:Touch(hitEnt)

if hitEnt:GetClass() == “seed_weed” then

if self.Entity:GetNWBool(“Plantable”) == true then

self.Entity:SetNWBool(“Plantable”, false)

hitEnt:Remove()

self.Entity:SetModel(“models/nater/weedplant_pot_planted.mdl”)

timer.Create(“Stage2_”…self:EntIndex(), 5, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing1.mdl”)

end)

timer.Create(“Stage3_”…self:EntIndex(), 15, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing2.mdl”)

end)

timer.Create(“Stage4_”…self:EntIndex(), 30, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing3.mdl”)

end)

timer.Create(“Stage5_”…self:EntIndex(), 45, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing4.mdl”)

end)

timer.Create(“Stage6_”…self:EntIndex(), 60, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing5.mdl”)

end)

timer.Create(“Stage7_”…self:EntIndex(), 120, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing6.mdl”)

end)

timer.Create(“Stage8_”…self:EntIndex(), 180, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing7.mdl”)

self.Entity:SetNWBool(“Weed”, true)

end)

end

end

end

function ENT:Touch(hitEnt2)

if hitEnt2:GetClass() == “seed_cocaine” then

if self.Entity:GetNWBool(“Plantable”) == true then

self.Entity:SetNWBool(“Plantable”, false)

hitEnt2:Remove()

self.Entity:SetModel(“models/nater/weedplant_pot_planted.mdl”)

timer.Create(“Stage2_”…self:EntIndex(), 5, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing1.mdl”)

end)

timer.Create(“Stage3_”…self:EntIndex(), 15, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing2.mdl”)

end)

timer.Create(“Stage4_”…self:EntIndex(), 30, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing3.mdl”)

end)

timer.Create(“Stage5_”…self:EntIndex(), 45, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing4.mdl”)

end)

timer.Create(“Stage6_”…self:EntIndex(), 60, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing5.mdl”)

end)

timer.Create(“Stage7_”…self:EntIndex(), 120, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing6.mdl”)

end)

timer.Create(“Stage8_”…self:EntIndex(), 180, 1, function()

self.Entity:SetModel(“models/nater/weedplant_pot_growing7.mdl”)

self.Entity:SetNWBool(“Cocaine”, true)

end)

end

end

end

function ENT:Use()

if self.Entity:GetNWBool(“Cocaine”) == true then

self.Entity:SetNWBool(“Cocaine”, false)

self.Entity:SetNWBool(“Plantable”, true)

self.Entity:SetModel(“models/nater/weedplant_pot_dirt.mdl”)

local SpawnPos = self.Entity:GetPos()

local CocaineBag = ents.Create(“durgz_cocaine”)

CocaineBag:SetPos(SpawnPos)

CocaineBag:Spawn()

end

end

function ENT:Use()

if self.Entity:GetNWBool(“Weed”) == true then

self.Entity:SetNWBool(“Weed”, false)

self.Entity:SetNWBool(“Plantable”, true)

self.Entity:SetModel(“models/nater/weedplant_pot_dirt.mdl”)

local SpawnPos = self.Entity:GetPos()

local WeedBag = ents.Create(“durgz_weed”)

WeedBag:SetPos(SpawnPos)

WeedBag:Spawn()

end

end

function ENT:OnRemove()

if self.Entity:GetNWBool(“Plantable”) == false then

timer.Destroy(“Stage2”)

timer.Destroy(“Stage3”)

timer.Destroy(“Stage4”)

timer.Destroy(“Stage5”)

timer.Destroy(“Stage6”)

timer.Destroy(“Stage7”)

timer.Destroy(“Stage8”)

end

end[/LUA]

With this code the Pot will only take the Cocaine Seeds and actually grow. If I try to use Weed Seeds, it only bumps up against the Pot and does nothing. Once I remove the Cocaine “part”, it will then allow Weed to grow and put out 1 weed. Oh, and i’m not too great with LUA.

EDIT: I’m just learning LUA, and all i’m asking is for some help so I can actually learn.

If anyone could help, it would be greatly appreciated.

Use [lua], not


 so that your code is easier to read

First of all, self.Entity is deprecated; use self instead. Second, your remove function would be deleting timers that don’t exist. Third, you can use timer.Simple instead of making a timer that repeats once. Fourth, if you are only using your variables serverside, don’t use NW vars. And last, you can’t overload functions. Use if statements and elseif instead.

Heh, it worked thus far.

[LUA]function ENT:Touch(hitEnt)

if hitEnt:GetClass() == “seed_weed” then

if self:GetNWBool(“Plantable”) == true then

self:SetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

timer.Create(“Stage2_”…self:EntIndex(), 5, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing1.mdl”)

end)

timer.Create(“Stage3_”…self:EntIndex(), 15, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing2.mdl”)

end)

timer.Create(“Stage4_”…self:EntIndex(), 30, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing3.mdl”)

end)

timer.Create(“Stage5_”…self:EntIndex(), 45, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing4.mdl”)

end)

timer.Create(“Stage6_”…self:EntIndex(), 60, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing5.mdl”)

end)

timer.Create(“Stage7_”…self:EntIndex(), 120, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing6.mdl”)

end)

timer.Create(“Stage8_”…self:EntIndex(), 180, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing7.mdl”)

self:SetNWBool(“Weed”, true)

end)

elseif hitEnt:GetClass() == “seed_cocaine” then

if self:GetNWBool(“Plantable”) == true then

self:SetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

timer.Create(“Stage2_”…self:EntIndex(), 5, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing1.mdl”)

end)

timer.Create(“Stage3_”…self:EntIndex(), 15, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing2.mdl”)

end)

timer.Create(“Stage4_”…self:EntIndex(), 30, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing3.mdl”)

end)

timer.Create(“Stage5_”…self:EntIndex(), 45, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing4.mdl”)

end)

timer.Create(“Stage6_”…self:EntIndex(), 60, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing5.mdl”)

end)

timer.Create(“Stage7_”…self:EntIndex(), 120, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing6.mdl”)

end)

timer.Create(“Stage8_”…self:EntIndex(), 180, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing7.mdl”)

self:SetNWBool(“Cocaine”, true)

end)

elseif hitEnt:GetClass() == “seed_mushroom” then

if self:GetNWBool(“Plantable”) == true then

self:SetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

timer.Create(“Stage2_”…self:EntIndex(), 5, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing1.mdl”)

end)

timer.Create(“Stage3_”…self:EntIndex(), 15, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing2.mdl”)

end)

timer.Create(“Stage4_”…self:EntIndex(), 30, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing3.mdl”)

end)

timer.Create(“Stage5_”…self:EntIndex(), 45, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing4.mdl”)

end)

timer.Create(“Stage6_”…self:EntIndex(), 60, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing5.mdl”)

end)

timer.Create(“Stage7_”…self:EntIndex(), 120, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing6.mdl”)

end)

timer.Create(“Stage8_”…self:EntIndex(), 180, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing7.mdl”)

self:SetNWBool(“Mushroom”, true)

end)

elseif hitEnt:GetClass() == “seed_lsd” then

if self:GetNWBool(“Plantable”) == true then

self:SetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

timer.Create(“Stage2_”…self:EntIndex(), 5, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing1.mdl”)

end)

timer.Create(“Stage3_”…self:EntIndex(), 15, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing2.mdl”)

end)

timer.Create(“Stage4_”…self:EntIndex(), 30, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing3.mdl”)

end)

timer.Create(“Stage5_”…self:EntIndex(), 45, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing4.mdl”)

end)

timer.Create(“Stage6_”…self:EntIndex(), 60, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing5.mdl”)

end)

timer.Create(“Stage7_”…self:EntIndex(), 120, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing6.mdl”)

end)

timer.Create(“Stage8_”…self:EntIndex(), 180, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing7.mdl”)

self:SetNWBool(“LSD”, true)

end)

elseif hitEnt:GetClass() == “seed_pcp” then

if self:GetNWBool(“Plantable”) == true then

self:SetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

timer.Create(“Stage2_”…self:EntIndex(), 5, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing1.mdl”)

end)

timer.Create(“Stage3_”…self:EntIndex(), 15, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing2.mdl”)

end)

timer.Create(“Stage4_”…self:EntIndex(), 30, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing3.mdl”)

end)

timer.Create(“Stage5_”…self:EntIndex(), 45, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing4.mdl”)

end)

timer.Create(“Stage6_”…self:EntIndex(), 60, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing5.mdl”)

end)

timer.Create(“Stage7_”…self:EntIndex(), 120, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing6.mdl”)

end)

timer.Create(“Stage8_”…self:EntIndex(), 180, 1, function()

self:SetModel(“models/nater/weedplant_pot_growing7.mdl”)

self:SetNWBool(“PCP”, true)

end)

end

end

end

end

end

end

end
[/LUA]

Yeah I know it’s very long, but i’ll be changing each individual growth rate this way. Anyways, Weed will only grow. I know I did something wrong, What do I need to do to fix this?

@Chessnut What would I change the NW Variables to?

Why do you need a shitload of different timers when you could do that in ONE timer with the intervals?
I also suggest DTVars instead of NWVars.

Lol so I could make one Drug grow faster/slower than the others? Like i’ve said, i’m not THAT knowledgeable of LUA and am learning. >_>

Wouldn’t it be simpler just to make a look like:

[lua]
for i = 1, 12 do
timer.Simple(“Stage”…i…"_"…self:EntIndex(), i * 15, function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");

	if (i == 12) then
		self:SetNWBool("somedrug", true);
	end;
end);

end;
[/lua]

[editline]1st August 2012[/editline]

Changing 15 to another number would change the interval.

[editline]1st August 2012[/editline]

Now that I think of it, why are you even networking the variable? And why not just have one single string like: self:SetNWString(“type”, “weed”) or self:SetNWString(“type”, “cocaine”).

Wouldn’t the model number also be increased by each interval? Or am I wrong?

EDIT: Nevermind.

It basically condenses your giant block of ugly into a neater, more manageable small portion.
So it’ll still function the same.

[LUA]
function ENT:Touch(hitEnt)

if hitEnt:GetClass() == “seed_weed” then

if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 12 do
timer.Simple(“Stage”…i…"_"…self:EntIndex(), i * 15 , function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“Weed”, true)

elseif hitEnt:GetClass() == “seed_cocaine” then
if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 12 do
timer.Simple(“Stage”…i…"_"…self:EntIndex(), i * 15 , function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“Cocaine”, true)

elseif hitEnt:GetClass() == “seed_mushroom” then
if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 12 do
timer.Simple(“Stage”…i…"_"…self:EntIndex(), i * 15 , function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“Mushroom”, true)

elseif hitEnt:GetClass() == “seed_lsd” then
if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 12 do
timer.Simple(“Stage”…i…"_"…self:EntIndex(), i * 15 , function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“LSD”, true)

elseif hitEnt:GetClass() == “seed_pcp” then

if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 12 do
timer.Simple(“Stage”…i…"_"…self:EntIndex(), i * 15 , function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“PCP”, true)

end

end

end

end

end

end

end
[/LUA]

I’ll change the Vars to DT later. Regardless, this is how it looks currently and only weed can be used in a Pot.

Are you sure the class is correct? Try printing hitEnt’s class to see.
Also, why not just add the Plantable bool at the top, rather than copy pasting it.

Yes, I know for a 100% fact the class is correct. I’ve tried each and every seed to make sure it wasn’t that.

Also, what do you mean by “add the plantable bool at the top, rather than copy pasting it”?

Sorry again, noob here. :stuck_out_tongue:

EDIT: Error occurs when I place the Seed in the Pot for Weed:

[lua\includes\modules imer.lua:207] attempt to perform arithmetic on local ‘delay’ <a string value>

My bad, just remove the first argument for the timer.Simple, I thought it had a string as an argument.

Timer.Simple shouldn’t have a name.

Ex:
timer.Simple(1, function() print(‘noname’) end)

Edit: Nut you beat me to it. :dance:

EDIT: Fixed it. :stuck_out_tongue: Sorry about that. It’s working fine now, the last question is…Why is it only allowing “seed_weed” to begin growing while all of the other seeds are basically blocked from doing so?

[LUA]
function ENT:Touch(hitEnt)

if hitEnt:GetClass() == “seed_weed” then

if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 7 do
timer.Simple(i * 15, function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“Weed”, true)

elseif hitEnt:GetClass() == “seed_cocaine” then
if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 7 do
timer.Simple(i * 15, function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“Cocaine”, true)

elseif hitEnt:GetClass() == “seed_mushroom” then
if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 7 do
timer.Simple(i * 15, function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“Mushroom”, true)

elseif hitEnt:GetClass() == “seed_lsd” then
if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 7 do
timer.Simple(i * 15, function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“LSD”, true)

elseif hitEnt:GetClass() == “seed_pcp” then

if self:GetNWBool(“Plantable”) == true then

self:GetNWBool(“Plantable”, false)

hitEnt:Remove()

self:SetModel(“models/nater/weedplant_pot_planted.mdl”)

for i = 1, 7 do
timer.Simple(i * 15, function()
self:SetModel(“models/nater/weedplant_pot_growing”…i…".mdl");
end);
end;

self:GetNWBool(“PCP”, true)

end

end

end

end

end

end

end
[/LUA]

I’ve tried elseif before and it’s worked, but now in this instance it’s refusing to work, and I honestly am stumped.

Anyone?

Try this
–Edit–
Changed self:GetNWBool(“LSD”, true) to self:SetNWBool(“LSD”, true)
[lua]
function ENT:Touch(hitEnt)
if hitEnt:GetClass() == “seed_weed” then

	if self:GetNWBool("Plantable") == true then

		self:SetNWBool("Plantable", false)

		hitEnt:Remove()

		self:SetModel("models/nater/weedplant_pot_planted.mdl")

		for i = 1, 7 do
			timer.Simple(i * 15, function()
    			self:SetModel("models/nater/weedplant_pot_growing"..i..".mdl");
			end);
		end;

		self:SetNWBool("Weed", true)
	end

elseif hitEnt:GetClass() == "seed_cocaine" then

	if self:GetNWBool("Plantable") == true then

		self:SetNWBool("Plantable", false)

		hitEnt:Remove()

		self:SetModel("models/nater/weedplant_pot_planted.mdl")

		for i = 1, 7 do
			timer.Simple(i * 15, function()
			    self:SetModel("models/nater/weedplant_pot_growing"..i..".mdl");
			end);
		end;

		self:SetNWBool("Cocaine", true)
	end

elseif hitEnt:GetClass() == "seed_mushroom" then

	if self:GetNWBool("Plantable") == true then

		self:SetNWBool("Plantable", false)

		hitEnt:Remove()

		self:SetModel("models/nater/weedplant_pot_planted.mdl")

		for i = 1, 7 do
			timer.Simple(i * 15, function()
			    self:SetModel("models/nater/weedplant_pot_growing"..i..".mdl");
			end);
		end;

		self:SetNWBool("Mushroom", true)
	end
	
elseif hitEnt:GetClass() == "seed_lsd" then

	if self:GetNWBool("Plantable") == true then

		self:SetNWBool("Plantable", false)

		hitEnt:Remove()

		self:SetModel("models/nater/weedplant_pot_planted.mdl")

		for i = 1, 7 do
		   timer.Simple(i * 15, function()
			    self:SetModel("models/nater/weedplant_pot_growing"..i..".mdl");
			end);
		end;

		self:SetNWBool("LSD", true)
	end

elseif hitEnt:GetClass() == "seed_pcp" then

	if self:GetNWBool("Plantable") == true then

		self:SetNWBool("Plantable", false)

		hitEnt:Remove()

		self:SetModel("models/nater/weedplant_pot_planted.mdl")

		for i = 1, 7 do
			timer.Simple(i * 15, function()
			    self:SetModel("models/nater/weedplant_pot_growing"..i..".mdl");
			end);
		end;

		self:SetNWBool("PCP", true)
	end
end

end
[/lua]

You had the ends in the wrong spot.

Got it working! Thanks. I had to edit it a little bit further to have it work correctly. But it works. :slight_smile:

(Had to add a timer to the self:SetNWBool when a drug is growing)