Shop using GTK

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Shop using GTK

Post by Emera Nova »

So I'm currently working with GTK and I attempting to set up a store people to visit and buy their supplys from it. At the moment all it does is talk to them and spawns in the item, without taking the funds away from them.

How would I make it search to see if the party has the gold coins on them to first buy the object and then remove the correct amount of coins.
I was thinking it could look for the ID of them but the problem is I would think each coin would have a special ID to it. So unless I spawn in each coin myself I won't know what their ID will be making that quite impossible for my script to call on.
If I knew what each coins ID is I could have it then delete certain ID's as long as they are there. I'm not sure if this idea is one able to work and 2 the best option to go with. SO if anyone has a better idea or a way to make this one work correctly :) please leave some sort of comment explaining.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Shop using GTK

Post by Drakkan »

there are several custom mods with shops... I saw one nice from cromcrom recently, however my favorite so far is this one:
https://dl.dropboxusercontent.com/u/264 ... hop-r2.zip

or you can check this (seems not working 100%)
viewtopic.php?f=14&t=5351&hilit=working+shop

but if you manage to combine it together with some nice looking GUI I am sure many modders will welcome it and will praise you high ;) :)
Last edited by Drakkan on Wed Jul 08, 2015 4:01 pm, edited 1 time in total.
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Shop using GTK

Post by Eleven Warrior »

This does not work in log 2
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Shop using GTK

Post by Drakkan »

Eleven Warrior wrote:This does not work in log 2
ah sory wrong link, thats just another shop.... I am currently using this one from Prozail

https://dl.dropboxusercontent.com/u/264 ... hop-r2.zip
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Shop using GTK

Post by JohnWordsworth »

If you'd like to implement a store using the GTK dialogue system, then the following two functions should be extremely useful in achieving your goal!

countInventoryItem(name): This function simply counts how many of a given item the party has. So countInventoryItem("coin") would return the number of coins the party are carrying.

removeInventoryItem(name, count): This function will remove "count" of item with name = "name" from the player's inventory. Note. If they player doesn't have enough, none will be removed!

Hope these help.

Code: Select all

-- 
-- Count how many of a single type of item the player has in their inventory.
--
function countInventoryItem(name)
	if name == nil then return 0 end
	local count = 0
	
	for idx=1,4 do
		local champion = party.party:getChampion(idx)
		
		for slot=1,ItemSlot.MaxSlots do
			local item = champion:getItem(slot)
			
			if (item and (item.go.name == name)) then 
				count = count + item:getStackSize()
			end
		end
	end

	return count
end


--
-- Remove "count" of object "name" from the player's inventory.
--
function removeInventoryItem(name, count)
	if name == nil then return false end
	if count == nil then count = 0 end
	
	local remaining = count

	if countInventoryItem(name) < count then
		return false
	end
	
	for idx=1,4 do
		local champion = party.party:getChampion(idx)
		
		for slot=1,ItemSlot.MaxSlots do
			local item = champion:getItem(slot)
			
			if (item and (item.go.name == name)) then 
				if item:getStackSize() <= remaining then
					remaining = remaining - item:getStackSize()		
					champion:removeItemFromSlot(slot);		
				else
					item:setStackSize(item:getStackSize() - remaining)
					remaining = 0
				end
			end
			
			if remaining <= 0 then
				return true
			end
		end
	end
	
	print("ERROR: Should never get here - items lost but function failed!")
	return false
end
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Shop using GTK

Post by Eleven Warrior »

Hi John. Adrtru has a coin system out. You place the coins on a side bar with mouse and get them back with the mouse. It adds up the coins. Drakkan used the sytem in his mod.

Whith the code that you have is it possible for a small test dungeon? thxs man :)

EDIT: In the system imam using I have the following: coin_silver, coin_gold, coin_copper and dm_platium_coin. So I thinks that your needs a table of sorts not sure.
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: Shop using GTK

Post by JohnWordsworth »

I've added a very simple demo to GrimTK where you can buy things from a rating using Rocks. This should show you how you could make a simple "dialogue system" type shop with just a few items if it suits your needs.

I would like to make a full drag-drop store one day in the future, but it's quite low on the list of things I need to do right now!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Shop using GTK

Post by Eleven Warrior »

God I hope you do John it will be awesome like all the other things you have given us thxs man :) A Shop like the one in log 1 that Alois wrote.
Post Reply