Page 1 of 4

Shops (now with source)

Posted: Mon Apr 22, 2013 10:36 am
by alois
Here you will find the source for shops inside LoG. I will update the source (maybe correcting bugs...) and the newest version will always be here.

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,
}
3) Make a script_entity in the game editor, name it "gui_init" and add the following lines:

Code: Select all

spawn("guiFramework",1,1,1,0,"guiInit")
guiInit:open()
function main()
	guiInit:close()
end
4) The 'shop data' has the following structure:

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"},
	},
}
5) To create / activate a shop, just do

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
and link this function to a pressure plate/button/whatever you like.

-- 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 :)

Re: Shops (please test)

Posted: Mon Apr 22, 2013 12:28 pm
by AdrTru
Wow, its look fantastic.

Re: Shops (please test)

Posted: Mon Apr 22, 2013 12:34 pm
by Drakkan
wonderfull stuff ! test and no problems so far, unfortunately without source testing is quite limited. Here are some ideas for next improvements:

- NEXT / BACK button to have more available pages for some stuff (like two pages of weapons etc...)
- scripting should work with real money in inventories, not just these virtual ones. If you can use just one stacked currency it should be fine (golds or something like that) - script should check all inventories and return value how much coins you have overall maybe ?)
- placing bought stuff on some table / alcove should be better than just dropping on the floor, but thats just cosmetic correction
- basic charactericstic for items (like attack for weapons, protection for armors, weight...) - not sure if this should be part of main description or in tooltip, but you will need it as some traders will sell some unknown items
- whole sell table area could be even larger than this standard gui dialogue window

- probably some sell option for less money in the future ?
- provide us with source so we can do more tests and play with it a little ;)

Thanks and hope we will get more !

Re: Shops (please test)

Posted: Mon Apr 22, 2013 12:45 pm
by alois
Drakkan wrote:wonderfull stuff ! test and no problems so far, unfortunately without source testing is quite limited. Here are some ideas for next improvements:

- NEXT / BACK button to have more available pages for some stuff (like two pages of weapons etc...)
- scripting should work with real money in inventories, not just these virtual ones. If you can use just one stacked currency it should be fine (golds or something like that) - script should check all inventories and return value how much coins you have overall maybe ?)
- placing bought stuff on some table / alcove should be better than just dropping on the floor, but thats just cosmetic correction
- basic charactericstic for items (like attack for weapons, protection for armors, weight...) - not sure if this should be part of main description or in tooltip, but you will need it as some traders will sell some unknown items
- whole sell table area could be even larger than this standard gui dialogue window

- probably some sell option for less money in the future ?
- provide us with source so we can do more tests and play with it a little ;)

Thanks and hope we will get more !
1) further pages: upcoming!
2) real money: this will probably be the last thing I will (try to) implement
3) right now items only drop, but of course placing them somewhere else is not a problem!
4) Ok for basic characteristics - it will be hard to collect them all, however
5) sell area larger: not a problem
6) sell option: upcoming (I'm trying to do it via drag&drop of items)
7) source: upcoming, but let me clean it a little! Right now it's a mess!

alois :)

Re: Shops (please test)

Posted: Mon Apr 22, 2013 5:22 pm
by Diarmuid
No more file to test, but this looks fantastic ineed.

Re: Shops (please test)

Posted: Mon Apr 22, 2013 6:10 pm
by Drakkan
alois wrote:
Drakkan wrote:wonderfull stuff ! test and no problems so far, unfortunately without source testing is quite limited. Here are some ideas for next improvements:
2) real money: this will probably be the last thing I will (try to) implement
I am almost sure that somebody from the forum should help with this, shop with real coins is definitely required for LotNr project / some specific dungeons as well. Anyway looking forward for any news !

Re: Shops (please test)

Posted: Mon Apr 22, 2013 6:58 pm
by alois
Diarmuid wrote:No more file to test, but this looks fantastic ineed.
Sorry, deleted by mistake. Now it should be available!

alois :)

Re: Shops (please test)

Posted: Tue Apr 23, 2013 4:36 pm
by alois
Added a "sell" part of the shop (always to be - possibly - tested). Now I only (!) have to put the two together... Here's a screenshot:
SpoilerShow
Image
Link to the .dat file: here

alois :)

Re: Shops (please test)

Posted: Tue Apr 23, 2013 6:00 pm
by Komag
This is very impressive!

Re: Shops (please test)

Posted: Wed Apr 24, 2013 12:50 pm
by alois
Let's add a little bit of scripts: first of all, the 'gui' framework, with instructions. I assume that you make a script_entity named 'gui' and put the contents of guy.lua in it, and add, to your init.lua, the lines

Code: Select all

cloneObject {
   object = "party",
   baseObject = "party",
   onDrawGui = function(g)
      return gui.onDrawGui(g)
   end,
}
The files: gui.lua and the instructions.
--- edit ---
Aagh! I forgot the (copied from grimwidgets) assets to build buttons and window backgrounds! Here they are: dialog. You have to unzip the folder into the mod_assets folder (i.e., there should be a folder called dialog, with 18 images inside).
--- edit ---

Whatever you may need, please feel free to ask! :)

alois :)