Page 1 of 1
Shop using GTK
Posted: Wed Jul 08, 2015 3:35 pm
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.
Re: Shop using GTK
Posted: Wed Jul 08, 2015 3:40 pm
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

Re: Shop using GTK
Posted: Wed Jul 08, 2015 3:54 pm
by Eleven Warrior
This does not work in log 2
Re: Shop using GTK
Posted: Wed Jul 08, 2015 4:01 pm
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
Re: Shop using GTK
Posted: Thu Jul 09, 2015 9:18 pm
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
Re: Shop using GTK
Posted: Fri Jul 10, 2015 2:53 am
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.
Re: Shop using GTK
Posted: Sun Jul 12, 2015 9:35 pm
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!
Re: Shop using GTK
Posted: Mon Jul 13, 2015 7:11 am
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.