I'm trying to make a config in one file, but when I use variables, it works in the beginning then stops working later on setting all the variables to 0. Please help me! Thanks in advance.
A little more information would be helpful. What does the file structure for the addon look like or are you talking about a singular file? If it's a singular file posting the config code would be useful.
Use include or AddCsFile
Including and/or addcsluafile both didn't work, and here is the
init.lua
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile("autorun/config.lua")
include( "shared.lua" )
include("autorun/config.lua")
function ENT:Initialize()
self:SetNWInt ( "time", WM_crusherTime )
self:SetNWInt ( "maxgrapes", WM_maxGrapes )
self:SetModel ( "models/props_wasteland/laundry_basket001.mdl" )
self:PhysicsInit (SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetNWInt ( "grapes", 0 )
self:SetNWInt ( "MaxTime", self:GetNWInt ( "time" ) )
self:SetNWInt( "status", 0 )
self:SetNWInt( "must", 1 )
end
function ENT:SpawnFunction (ply, tr)
local spawnPos = tr.HitPos + tr.HitNormal *16
local ent = ents.Create ( "wm_crusher" )
ent:SetPos(spawnPos)
ent:Spawn()
ent:Activate()
return ent
end
local effectData = EffectData()
function ENT:PhysicsCollide(data, phys)
if ( ( data.DeltaTime > 0 ) and ( data.HitEntity:GetClass() == "wm_grapes" ) and self:GetNWInt ( "grapes" ) < WM_maxGrapes ) then
self:SetNWInt ( "grapes", self:GetNWInt ( "grapes" ) + 1 )
data.HitEntity:Remove()
end
end
function ENT:OnTakeDamage(dmginfo)
effectData:SetStart(self:GetPos())
effectData:SetOrigin(self:GetPos())
effectData:SetScale(1)
util.Effect( "watersplash", effectData )
self:Remove()
end
function ENT:Think ()
if ((!self.nextCrush or CurTime() >= self.nextCrush) and (self:GetNWInt ( "grapes" ) == WM_maxGrapes)) then
self:SetNWInt("time", math.Clamp (self:GetNWInt ("time") - 1, 0, self:GetNWInt ( "MaxTime" ) ))
self.nextCrush = CurTime() + 1
if (self:GetNWInt("time") == 0) and (self:GetNWInt("status") == 0) then
self:SetNWInt("status", 2)
end
end
end
function ENT:Use(activator, caller)
if (self:GetNWInt("status") == 2) then
self:SetNWInt("must", 0)
end
end[/CODE]
cl_init.lua
[CODE]include ("shared.lua")
surface.CreateFont("WineFont", {
font = "HUDNumber",
size = 50,
weight = 600,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
});
function ENT:Initialize()
end
function ENT:Draw()
self:DrawModel()
local pos = self:GetPos()
local ang = self:GetAngles()
local grapes = 0
ang:RotateAroundAxis( ang:Up(), 90)
ang:RotateAroundAxis( ang:Forward(), 0)
if LocalPlayer():GetPos():Distance(self:GetPos()) < 256 then
cam.Start3D2D(pos + ang:Up(), Angle(1, LocalPlayer():EyeAngles().y-90, 90), .25)
draw.DrawText("Grape Crusher", "WineFont", 0, -230, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(25, 25, 25, 100))
draw.DrawText("Grapes " .. ( self:GetNWInt "grapes" .. "/" .. self:GetNWInt ( "maxgrapes" ) ), "WineFont", 0, -190, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(25, 25, 25, 100))
draw.DrawText("Time: " .. (math.Round(self:GetNWInt "time")) .. " sec", "WineFont", 0, -150, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(25, 25, 25, 100))
cam.End3D2D()
end
if LocalPlayer():GetPos():Distance(self:GetPos()) <256 and self:GetNWInt ("status") == 2 and self:GetNWInt("must") != 0 then
cam.Start3D2D(pos + ang:Up(), Angle(1, LocalPlayer():EyeAngles().y-90, 90), .25)
draw.DrawText("Press 'E' On Me to remove must", "WineFont", 0, -270, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(25, 25, 25, 100))
cam.End3D2D()
end
if LocalPlayer():GetPos():Distance(self:GetPos()) <256 and self:GetNWInt("must") == 0 then
cam.Start3D2D(pos + ang:Up(), Angle(1, LocalPlayer():EyeAngles().y-90, 90), .25)
draw.DrawText("Pour the wine from the crusher into the barrel!", "WineFont", 0, -270, Color(255, 0, 0, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, 1, Color(25, 25, 25, 100))
cam.End3D2D()
end
end[/CODE]
config.lua
[CODE]WM_crusherTime = 60
//How long in seconds you have to wait for the crusher to be ready
WM_maxGrapes = 5
//How many grapes you need to put in the crusher for the timer to start[/CODE]
Also there is an error that says
[ERROR] addons/wine/lua/entities/wm_crusher/init.lua:29: attempt to compare number with nil
1. unknown - addons/wine/lua/entities/wm_crusher/init. lua:29
The error is saying my '>' comparison which is comparing a NWInt and a variable defined in the config. The variable is nil proven by the error.
I'm having the same problem and idk how to fix it.
put your config in addonname/lua/config.lua then make a load file like this
addonname/lua/autorun/addonname_load.lua and in it put this
[code]
if (SERVER) then
AddCSLuaFile("config.lua")
include("config.lua")
end
if (CLIENT) then
include("config.lua")
end
[/code]
Didn't work. Anyone else?
Don't use Networked variables please. Use NetworkVars
[QUOTE=MelonShooter;50329271]Didn't work. Anyone else?[/QUOTE]
That does work. If it doesn't work for you you're doing something wrong, so instead of saying "Didn't work", why don't you supply us with the code and file locations so we can help you?
Sorry, you need to Log In to post a reply to this thread.