First and foremost, as usual, thanks to all those which have given me ideas in order to set up a decent framework; many ideas I have copied, very few are of my own!
-- Instructions --
0) Take the .zip file here
1) Put inside mod_assets the two folders contained in "put inside mod_assets" (put the contents of 'textures' inside 'mod_assets/textures' if you do not want to destroy the resources you already have put there!)
2) Add the following lines at the end of init.lua (inside mod_assets/scripts/)
Code: Select all
import "mod_assets/gui/initgui.lua"
cloneObject {
name = "party",
baseObject = "party",
onDrawGui = function(g)
return gui.onDrawGui(g)
end,
onMove = function(self)
if (gui.globalVars["shopOn"]) then
return false
else
return true
end
end,
}
Code: Select all
spawn("guiFramework",1,1,1,0,"guiInit")
guiInit:open()
function main()
guiInit:close()
end
The 'data' field has entries of the form {item_name,[price,quantity]}; item_name is the same used by LoG; price and quantity can be specified (or left as 'nil'); if price is specified, then the 'standard' price is overridden in the shop; if quantity is not specified, the item is sold as unique (i.e., quantity = 1).
The name of the shop owner (.merc.name) is used to refer to the shop in the scripts; therefore, it is important that you assign it (and, possibly, assign different shops to different merchants!).
Code: Select all
shopData = {
name = "Ye olde shoppe", -- the name of the shop
text = "Welcome to my humble shop\no customer!\nFeel free to look around\nand buy\nwhatever you want!", -- a text to be displayed
merc = {name = "Sellerone", img = "mod_assets/textures/dds/image1212.tga"}, -- the name of the shop owner (see below) and its portrait
selm = 0.85, -- multiplier for prices to sell (i.e., in this case, selling a sword you receive the 85% of its standard price)
buym = 1.05, -- multiplier for prices to buy (i..e, in this case, buying a sword costs 5% more than its standard price)
data = {
{"hand_axe"}, -- the names are those of the items.lua in the LoG assets folder
{"long_sword"},
{"ogre_hammer"},
{"nex_sword"},
{"dismantler"},
{"cutlass"},
{"machete"},
{"cudgel"},
{"knoffer"},
{"warhammer"},
{"legionary_shield"},
{"round_shield"},
{"boots_valor"},
{"full_helmet"},
{"plate_greaves"},
{"leather_pants"},
{"doublet"},
{"circlet_war"},
{"leather_brigandine"},
{"chitin_mail"},
{"potion_healing",nil,10}, -- 10 of these in the shop; the 'nil' is, if needed, the price, overriding the standard price
{"potion_energy",nil,5},
{"whitewood_wand"},
{"magic_orb"},
{"zhandul_orb"},
{"tar_bead",nil,10},
{"cave_nettle",nil,10},
{"slime_bell",nil,10},
{"blooddrop_blossom",nil,5},
{"milkreed",nil,5},
{"lightning_blade"},
},
}
Code: Select all
function openShop()
if (gui.globalVars["totalMoney"] == nil) then
gui.setVar("totalMoney",2000) -- initial amount of money
end
if (gui.globalVars["shopData"] == nil) then
gui.setVar("shopData",shopData) -- initial data for the shop, set as global variable
end
shopid,shop = shopscript.makeShop(gui.globalVars["shopData"]) -- make the shop
gui.setVar("shopOn",true) -- signal (globally) that the shop is on
gui.globalVars["shop"]:activate() -- activate the shop (an object contained in the global variable "shop")
end
-- important note --
The actual data for the shop is saved in a variable whose name is the shop's merchant name; therefore, when invoking the 'makeShop' command, the contents of this variable will be checked; if the var is existent (i.e., not nil) then the saved data (which take into account the fact that some items may have been sold, or decreased in quantity) is used; otherwise, the supplied data will be used.
-- second important note --
Every time the 'makeShop' command is invoked, the 'old' version of the shop is destroyed, and a brand new version is created, using the data of the shop, and the data coming from the party.
An example of loG editor project of a (hopefully working) shop is here.
alois