I am pretty sure everyone has seen the old weed plant, I made a remake of it with some other code I had with a working watering system that is still under development. That's not why I am here though, I am not the greatest coder as you can see by the slop of code, one day this whole entity was working and recently it doesn't work. I receive no errors in console nor does it bug out in anyway besides not updating the model. Does anyone have any suggestions? I will post the code for the entity.
[CODE]
--cl_init--
include("shared.lua")
function ENT:Draw()
self:DrawModel()
if PLANT_CONFIG.Mode == nil then return end
if LocalPlayer():GetEyeTrace().Entity == self then
local plypos, pos = LocalPlayer():GetPos(), self:GetPos()
pos.z = pos.z + 10
local faceplant = (plypos-pos):Angle()
local camPos = pos+faceplant:Forward()*10
faceplant.p = 180
faceplant.y = faceplant.y-90
faceplant.r = faceplant.r-90
cam.Start3D2D(camPos, faceplant, 0.5)
cam.IgnoreZ(true)
draw.SimpleText(table.concat({"Soil moisture: ", self:GetWater(), "%"}, ""), "DBonus20_NumberFix", 0, 0, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
cam.IgnoreZ(false)
cam.End3D2D()
end
if PLANT_CONFIG.Mode > 1 then
local Pos = self:GetPos()
local Ang = self:GetAngles()
local owner = self:Getowning_ent()
owner = (IsValid(owner) and owner:Nick()) or "Unknown"
surface.SetFont("HUDNumber5")
local TextWidth = surface.GetTextSize(PLANT_CONFIG.PlantName or "Weed Plant")
local TextWidth2 = surface.GetTextSize(owner)
Ang:RotateAroundAxis(Ang:Forward(), 90)
local TextAng = Ang
if PLANT_CONFIG.Mode == 3 then
TextAng:RotateAroundAxis(TextAng:Right(), CurTime()*-20)
end
cam.Start3D2D(Pos + Ang:Right() * -30, TextAng, 0.2)
draw.WordBox(1, -TextWidth*0.5 + 5, -60, PLANT_CONFIG.PlantName or "Weed Plant", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
draw.WordBox(1, -TextWidth2*0.5 + 5, -14, owner, "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
cam.End3D2D()
end
end
[/CODE]
[CODE]
--init--
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/nater/weedplant_pot.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE)
local phys = self:GetPhysicsObject()
if phys and phys:IsValid() then phys:Wake() end
self.isUsable = false
self.isPlantable = true
self.damage = 60
self.magic = false
end
function ENT:OnTakeDamage(dmg)
self.damage = self.damage - dmg:GetDamage()
if self.damage <= 0 then
self:Remove()
end
end
function ENT:Use( ply, activator )
local moneygain = PLANT_CONFIG.MoneyAmount -- variable for outcome 2
if self.isUsable == true then
self.isUsable = false
self.isPlantable = true
self:SetModel("models/nater/weedplant_pot_dirt.mdl")
local SpawnPos = self:GetPos()
if PLANT_CONFIG.Outcome == 1 then
local WeedBag = ents.Create("durgz_weed")
if !IsValid(WeedBag) then
DarkRPCreateMoneyBag(SpawnPos + Vector(0,0,15), PLANT_CONFIG.MoneyAmount or 150)
PrintMessage( HUD_PRINTTALK, "[Weed Plant] Drugzmod isn't installed correctly!")
PrintMessage( HUD_PRINTTALK, "[Weed Plant] Set Outcome to 2 in order to print money instead")
return false
end
WeedBag:SetPos(SpawnPos + Vector(0,0,15))
WeedBag:Spawn()
elseif PLANT_CONFIG.Outcome == 2 then -- Specifies for option 2?
activator:AddMoney(moneygain) -- Money goes straight to your wallet instead of create a money bag
GAMEMODE:Notify(ply, 0, 4, "You've received " .. GAMEMODE.Config.currency .. moneygain .. " for looting the money pot.")
end
end
self.magic = false
end
-- Who doesn't like a little magic for growing weed?
function ENT:Think()
if self.magic then
local effectdata = EffectData()
effectdata:SetOrigin(self:GetPos() + Vector( 0 , 0, 15 ))
effectdata:SetMagnitude(1)
effectdata:SetScale(1)
effectdata:SetRadius(2)
util.Effect("inflator_magic", effectdata)
end
end
local function Stages(self)
if !IsValid(self) then return end
-- Timers
timer.Simple( math.random(20, 40), function()//(tonumber(PLANT_CONFIG.Stage1) or 30, function()
self:SetWater(self:GetWater() - 3)
if !IsValid(self) then return end
self:SetModel("models/nater/weedplant_pot_growing1.mdl")
timer.Simple( math.random(25, 50), function()//(tonumber(PLANT_CONFIG.Stage2) or 30, function()
self:SetWater(self:GetWater() - 3)
if !IsValid(self) then return end
self:SetModel("models/nater/weedplant_pot_growing2.mdl")
timer.Simple( math.random(30, 60), function()//(tonumber(PLANT_CONFIG.Stage3) or 30, function()
self:SetWater(self:GetWater() - 3)
if !IsValid(self) then return end
self:SetModel("models/nater/weedplant_pot_growing3.mdl")
timer.Simple( math.random(35, 70), function()//tonumber(PLANT_CONFIG.Stage4) or 30, function()
self:SetWater(self:GetWater() - 3)
if !IsValid(self) then return end
self:SetModel("models/nater/weedplant_pot_growing4.mdl")
timer.Simple( math.random(40, 80), function()//(tonumber(PLANT_CONFIG.Stage5) or 30, function()
self:SetWater(self:GetWater() - 3)
if !IsValid(self) then return end
self:SetModel("models/nater/weedplant_pot_growing5.mdl")
timer.Simple( math.random(45, 90), function()//(tonumber(PLANT_CONFIG.Stage6) or 30, function()
self:SetWater(self:GetWater() - 3)
if !IsValid(self) then return end
self:SetModel("models/nater/weedplant_pot_growing6.mdl")
timer.Simple( math.random(50, 100), function()//(tonumber(PLANT_CONFIG.Stage7) or 30, function()
self:SetWater(self:GetWater() - 3)
if !IsValid(self) then return end
self:SetModel("models/nater/weedplant_pot_growing7.mdl")
self.isUsable = true
self.magic = true -- Final stage will display a small effect when it's done.
end)
end)
end)
end)
end)
end)
end)
end
function ENT:StartTouch(hitEnt)
if hitEnt:GetClass() == "seed_weed" and self.isPlantable == true then
self.isPlantable = false
hitEnt:Remove()
self:SetModel("models/nater/weedplant_pot_planted.mdl")
//Stages(self)
if self:GetWater() >= 3 then Stages(self)
else return end
end
if hitEnt:GetClass() == "durgz_water" and self:GetWater() < 100 then self:SetWater(self:GetWater() + 15)
hitEnt:Remove()
if self:GetWater() > 100 then self:SetWater(100)
end
end
end
[/CODE]
[CODE]
--shared--
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Growing Weed Plant"
ENT.Author = "N/A"
ENT.Spawnable = false
ENT.AdminSpawnable = false
function ENT:SetupDataTables()
self:NetworkVar("Int",0,"price")
self:NetworkVar("Entity",1,"owning_ent")
self:DTVar("Int", 1, "Water")
end
function ENT:GetWater()
return self:GetDTInt(1)
end
function ENT:SetWater(n)
self:SetDTInt(1, n)
end
PLANT_CONFIG = {}
-- Configuration ~ Start
-- Duration for Stages (in seconds)
PLANT_CONFIG.Stage1 = 20
PLANT_CONFIG.Stage2 = 20
PLANT_CONFIG.Stage3 = 30
PLANT_CONFIG.Stage4 = 30
PLANT_CONFIG.Stage5 = 40
PLANT_CONFIG.Stage6 = 40
PLANT_CONFIG.Stage7 = 45
-- Mode
PLANT_CONFIG.Mode = 1
/* MODE STAGES
Mode 1: Regular with no text
Mode 2: Owner Text
Mode 3: Spinning Owner Text
*/
-- Outcome (1 = drugs, 2 = money)
PLANT_CONFIG.Outcome = 1
-- Money Amount ONLY USED IF Outcome is 2
PLANT_CONFIG.MoneyAmount = 150
-- Plant Name
PLANT_CONFIG.PlantName = "Weed Plant" -- Some people prefer to call it Cannabis. Edit it if you want to.
-- Configuration ~ End
[/CODE]
[highlight](User was banned for this post ("Didn't even read the TITLE of the rules thread. "HELP" is not a descriptive thread title, wrong section." - postal))[/highlight]
Sorry, you need to Log In to post a reply to this thread.