• Convars in if statments
    5 replies, posted
I was just wondering if I could use convars in if statments at all and how I would go about doing this. So far I have: [lua]if(GetConVar("thirdperson"):GetInt()==1) then ParticleEffectAttach(self.Particle, PATTACH_POINT_FOLLOW, ply, ply:LookupAttachment("eyes")) end [/lua] Any help is greatly appreciated :)
That will work as long as it is being called. Make sure to attach the particle only once so that it wont add particle systems over and over again, lagging the game.
The context is: [lua]game.AddParticles("particles/item_fx.pcf") ITEM.Name = 'Green Confetti' ITEM.Price = 30000 ITEM.Attachment = 'eyes' ITEM.Material = "vgui/particlepics/Green_Confetti.png" ITEM.Particle = "superrare_confetti_green" PrecacheParticleSystem(ITEM.Particle) if (GetConVar("thirdperson"):GetInt()==1) then function ITEM:OnEquip(ply, modifications) ParticleEffectAttach(self.Particle, PATTACH_POINT_FOLLOW, ply, ply:LookupAttachment("eyes")) end end function ITEM:OnHolster(ply) ply:StopParticles() end if (GetConVar("thirdperson"):GetInt()==0) then ply:SendLua("timer.Simple(1, function() LocalPlayer():StopParticles() end)") end [/lua] but I seem to be getting [ERROR] addons/pointshop-master/lua/pointshop/items/particles/greenconfetti.lua:18: attempt to index a nil value
thirdperson is not a convar
[QUOTE=Willox;46801018]thirdperson is not a convar[/QUOTE] Really? I always assumed it was. How would I adapt thirperson to this using another method then?
Also, I'd recommend using GetBool( ) instead of GetInt( ) == 1 You can set up your own convar; here are the basics: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/convars/creating_and_using_client_convars.lua.html[/url] 0 is false, 1 is true with GetBool. Anything other than 0 may be true but I haven't looked at the code so I can't say for sure but if you add the help text to the console command then you can list available options ( even with autofill if you use a concommand instead of convar ).
Sorry, you need to Log In to post a reply to this thread.