Shops (now with source)

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Shops (now with source)

Post 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 :)
Last edited by alois on Tue May 07, 2013 6:57 am, edited 4 times in total.
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: Shops (please test)

Post by AdrTru »

Wow, its look fantastic.
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Shops (please test)

Post 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 !
Breath from the unpromising waters.
Eye of the Atlantis
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Shops (please test)

Post 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 :)
User avatar
Diarmuid
Posts: 807
Joined: Thu Nov 22, 2012 6:59 am
Location: Montreal, Canada
Contact:

Re: Shops (please test)

Post by Diarmuid »

No more file to test, but this looks fantastic ineed.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Shops (please test)

Post 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 !
Breath from the unpromising waters.
Eye of the Atlantis
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Shops (please test)

Post by alois »

Diarmuid wrote:No more file to test, but this looks fantastic ineed.
Sorry, deleted by mistake. Now it should be available!

alois :)
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Shops (please test)

Post 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 :)
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Shops (please test)

Post by Komag »

This is very impressive!
Finished Dungeons - complete mods to play
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Shops (please test)

Post 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 :)
Last edited by alois on Sun Apr 28, 2013 11:27 am, edited 1 time in total.
Post Reply