Hello, so this is going to be the first post I create here, concerning my first addon I am inquiring about here / creating entirely.
Still pretty new to LUA with only vague prior coding experience and much more new to this forum and how things work, so if my code or conduct vexes anybody or breaks some unspoken rules: all I can say is “My bad.”
I have created a vending machine entity that opens a GUI on the caller’s screen when used and presents a number of selection buttons, utilizing Net.Send / Net.Receive and all that fun stuff. GUI’s not the problem though.
As of now, the vending machine works but it presents a strange bug in that if you have more than one vending machine active in your game: the latest created one will override the spawn location of the products being created.
I’ll post the snippet of my code that has to do with setting the position of the item.
Please note: it is currently inside the ENT:USE function only because it improved the issue by having it only occur if two players are simultaneously using different machines. Originally, the product position was set inside of ENT:Initialize.
This is not a fix, and I am aware that it is not.
net.Start("reservemachinemenu") net.Send(call) local Usesound = Sound(self.UseSound) if call:IsPlayer() then self:EmitSound(self.UseSound, 60, 100, .5, CHAN_AUTO) -- Selection Menu opened. for k,v in pairs(Selections) do net.Receive(v, function() self:EmitSound(self.ButtonSound, 75, 102, 1, CHAN_AUTO) -- Selection made SFX timer.Simple(.35, function() self:EmitSound("ProductFalling") -- SFX of item tumbling out of machine. end) local face = self:GetForward() local product = ents.Create(v) local name = self:GetForward() * -4 name:Rotate(Angle(0,90,0)) product:SetPos(self:GetPos() + (face*30) -Vector(0,0,32) + name) product:SetAngles(self:GetAngles() + Angle(0,0,90)) product:SetCollisionGroup(COLLISION_GROUP_WEAPON) timer.Simple(0.8, function() product:Spawn() product:GetPhysicsObject():SetMass(2) product:GetPhysicsObject():ApplyForceCenter(face*99) end) end ) end end end
If there is any other part of my code anyone would wish to see, please ask and I can provide it if it is relevant.
Also if there are simply ways I can improve this code, I would be more than grateful to know as again I am still rather new and learning a lot.
Thank you for your time.