Setting up a vendor
Setting up a vendor can be a pretty elaborate job for some of you, but don't worry. We are going to cover the basics of creating, saving and removing a vendor from scratch.
Creating & saving a vendor
Step 1 Create a vendor file in schema/vendor. Use the following template as an example for your own vendor:
local VENDOR = {} VENDOR.UniqueID = "examplevendor" -- vendor's unique ID VENDOR.Name = "Example Vendor" -- vendor's name VENDOR.Desc = "A simple and basic vendor used as a template for other vendors." -- vendor's description VENDOR.Model = "models/player/kleiner.mdl" -- vendor's model VENDOR.Skin = 0 -- vendor's skin VENDOR.Bodygroups = "0032000004" -- vendor's bodygroups; using Entity:SetBodyGroups function, for more details visit: https://wiki.facepunch.com/gmod/Entity:SetBodyGroups VENDOR.Gender = "male" -- gender of the vendor; basic ones are male, female, cp, fisherman VENDOR.Talk = true -- should the vendor play any greeting sound VENDOR.Sell = { -- here you put what the vendor is selling to the player ["example_item"] = { -- must be a valid item's unique ID Cost = 50, -- the price Max = 3, -- maximum amount of items before the vendor will no longer sell to the player Restricted = true -- should the item that is bought be restricted? }, ["example_item2"] = { Cost = 10, BuyMax = 4, -- how many items of this type can a player buy from the vendor before his stock runs out TempCooldown = 60 -- time until the stock is refilled }, } VENDOR.Buy = { ["example_item"] = { Cost = 10 }, } function VENDOR:Initialize() end function VENDOR:CanUse(ply) end function VENDOR:Think() end function VENDOR:OnItemPurchased(class, ply) end function VENDOR:DoAnimation(animation) end impulse.RegisterVendor(VENDOR)
Expanded vendors are provided with the skeleton schema. Feel free to look at the source code for examples!
Step 2 (Re)start your server if you haven't already.
Although Garry's Mod allows live Lua refreshing, adding new files to impulse: Enhanced requires a server restart.
Step 3 Spawn a Vendor Base from Entities tab, impulse: Enhanced category. Step 4 While being close and looking at the Vendor Base entity, open your developer console (default key: `) and type the following commands in the given succession:
impulse_save_mark (marks an entity for saving)
impulse_save_keyvalue vendor examplevendor (sets the key value of the entity) - replace examplevendor with your vendor's unique ID
impulse_save_saveall (saves all marked entities)
impulse_save_reload (reloads all saved entities)
That's all! You have set your own vendor.
Removing a vendor
To remove a vendor from the game, aim at the vendor entity, open your developer console (default key: `) and type the following commands:
impulse_save_unmark (marks the entity for removal)
impulse_save_saveall
impulse_save_reload (optional, but recommended if you want to get rid of the entity immediately)