Example project made with Godot 3.2 beta4
new items
and item slots
rarity levels
from a base item with visual item rarity border and background coloringmouse drag & drop
with different dropzones
and returns on reset
depending on item ownership
price calculation
depending on exchange rates
between the partiesitem tooltip on mouse hover
that scales and always stays inside the viewport
sizedoubleclick items
and added item comparison
to the tooltip with a keymodifiernotification messages
that autohide after a few secondsutility
that scans for images and items
in defined folders at startup and create a dictionary for convenient access by filename.I wasn't able to provide the full code for the dialog and interactions part with this first release. It was way to dependent on my current dialog system so it has to wait until I can release the full dialog and camera system as well in the near future.
The example project comes with a premade trading scene that autostarts and various helper scripts to get you started but first we need some item images.
Place all your images in the assets/images/
folder or below in as many subfolders as you need for your project and use unique filenames
for them.
The image script scans for .webp, .png.
and .jpg
file endings.
All found images are added as key:value
pair to a dictionary with the imagename as key and the loadpath as value. From now on you can access the loadpath of images by typing game.image_data.get("unique_image_name")
from everywhere in your game without caring for the excact path as long as you keep your imagenames unique e.g. with a prefix. If you need other formats edit the scan_dir_for_images()
function in the data
script.
Place all your item resources in the data/items/
folder or below in any subfolder. The scripts scans for all .tres
resource files so don't mix them with anything else in the items subfolders. Same as with images, all items are added to a dictionary and you access them with game.item_data.get("unique_item_name")
.
Edit your item resources one by one. Give them a unique item_id
, a display_name
, a desription
and your image. Some stats are already for the next expensions and have no effect rightnow apart from visuals like max_stack
and unique
. sellable
prevents the items from showing up in trade, the base_price
is the cost and sell value of the item before exchange modifiers are applied. category
, rarity
and slot
are self-explanatory and pick from the pulldown menu what you see fit..
You can add as many new trader npcs as you want with their own inventories.
The current setup is, that you add them as a child node to the characters
node, name them how you want and attach the NPC.gd
Script to the node.
At the moment there is a project cheat that adds all created items to both player and npc trader at the game start.
You find this block in the game
script in the _ready()
function. There you can see a script example how to create and add items as well as money to the inventories of both player and npc.
You can control the trade window manually by calling game.start_trading( "the_trader_name" )
function from everywhere with the traders name as a text string
.
There are two optional parameters as well. inventory_id
replaces the npcs real inventory temporarily. This is usefull for quests or other special events where you want to hide the real inventory of the npc for this interaction. Selling and buying is still possible and sold player items are added to the real inventory to not get lost. The dialog_id
at the moment serves no purpose but will be important when the dialog addon is added.
MIT or my personal 'Don't care' license, do whatever you want with this example and create something fun and awesome with Godot.
The code has some parts that may seem redundent ... and they are. I ripped this example from a larger project of mine and had to fix many dependencies by copy&pasting from old versions. It was a real hassle and I ran out of patient ... left those dead code blocks that didn't produce any issues for now. Will revisit it later with the dialog, camera and look_at integration.
On rare occasion the drop exchange zones can get stuck and prevent further itemdrags. Annoying but nothing gamebreaking and fixed by pressing the cancel button. I was able to track the error down to the way godot handles mouse enter/exit signals under the hood (and chokes on them) but even with a workaround couldn't fix it completly for now.