Vending machine

I was wondering if there is a way to create a vending machine for cider, so that people can get food out of it, and it takes money from them on use?

What food, I could make it drop/inventory a can or something.

Talk on steam now and I’ll do it.

Anyone see anything wrong with this

[lua]
AddCSLuaFile( “cl_init.lua” ) – Make sure clientside
AddCSLuaFile( “shared.lua” ) – and shared scripts are sent.

include(‘shared.lua’)

–=================================================–
– CONFIGURATION –
–=================================================–
Product = “Chinese” --The Product Name, Eg. Chinese
Amount = 5–Only a number please or code fucks up
Price = 2500 --The Price, Self Explanitory (Donor price is automatically halfed)
–=================================================–
– CONFIGURATION END –
–=================================================–
DonorPrice = (Price/2) - (Price/2) - (Price/2)
PriceTot = Price - Price - Price

function ENT:Initialize()
self:SetModel( “models/props_interiors/VendingMachineSoda01a.mdl” )
self:PhysicsInit( SOLID_VPHYSICS ) – Make us work with physics,
self:SetMoveType( MOVETYPE_NONE ) – after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS )
self:SetUseType( SIMPLE_USE )

local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end

end

function ENT:Use( player, call )
local item = cider.item.get(Product)
if player.cider._Donator > 0 then --DONOR STUFF
cider.player.giveMoney(player, DonorPrice);
cider.player.notify(player, "You Have Brought “…Amount…” “…item.name…” For “…DonorPrice…”.
", 1);
cider.inventory.update(player, item.uniqueID, Amount);
else --NON DONOR STUFF
cider.player.giveMoney(player, PriceTot);
cider.player.notify(player, "You Have Brought “…Amount…” “…item.name…” For “…PriceTot…”.
", 1);
cider.inventory.update(player, item.uniqueID, Amount);
end
end

function ENT:Think()
end
[/lua]

I made this by the way.

Just for your infomation Flawless.

shared.lua
[lua]
ENT.Type = “anim”
ENT.Base = “base_gmodentity”

ENT.PrintName = “Vending Machine”
ENT.Author = “RTM xBEASTx”
ENT.Contact = “N/A”
ENT.Purpose = “Cider Gamemode”
ENT.Instructions = “Use with care. Always handle with gloves :)”
[/lua]

cl_init.lua
[lua]
include(‘shared.lua’)

–[[---------------------------------------------------------
Name: Draw
Purpose: Draw the model in-game.
Remember, the things you render first will be underneath!
---------------------------------------------------------]]
function ENT:Draw()
self:DrawModel()
end
[/lua]

I can’t see how
[lua]
DonorPrice = (Price/2) - (Price/2) - (Price/2)
[/lua]
Will work, “1250 - 1250 - 1250 = -1250”

Yes, I couldnt think of any other way to make a price negate.

Could i do something like

Price = 100
DonorPrice = -Price

?

Yes.

It may help if you say what the problem is and why are you doing

[lua]
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
[/lua]

When you can just do

[lua]
self:PhysWake( )
[/lua]

Do i even need PhysWake if it is staying still.

Also, the problem is when you click it nothing spawns.

Nothing spawns because you’re spawning nothing. All you’re doing is taking money from the player, or at least I can assume it from the name of the Cider functions you’re calling.

You don’t expect the game to magically know when to spawn the product and where exactly, do you?

Oh also those pieces of code from shared.lua and cl_init.lua are the standard contents of almost every scripted entity, they prove absolutely nothing. Actually it’s nearly impossible to prove that you are the real author of a script, especially when said script is extremely basic, so I think you should stop being anxious about King Flawless being a meanie to your sorry person.

I suggest you read this and this, because you know something has to be done when you can’t negate numbers properly and don’t know about spawning entities.

Why will the entity itself not spawn.

Nothing happens when you press the icon.

No you don’t

-_Kilburned-

[editline]22nd March 2011[/editline]

http://luabin.overvprojects.nl/?path=/lua/entities/sent_ball/init.lua

Take a look at that you might learn something

Also is cider sandbox based?

Still doesnt explain why it does not spawn.

Reading the comments could actually help, you know. You said that you were actually trying hard to learn stuff, so it’s time to prove it, try harder.

[editline]22nd March 2011[/editline]

line 6-10, just in case you really missed it.

Sorry, i posted before i saw the edit.

Reading now.

That’s just what i needed, thank you!

  • Rate for you! :slight_smile:

How come no one even reads the sticky http://www.facepunch.com/threads/1055637-Section-Rules-Info-READ-BEFORE-POSTING

Thank you so much King Flawless

The entity has been worked, I wondered why all my entities failed to spawn.