RPG in a Box

RPG in a Box

View Stats:
Way to check equipped item
Hi, I was wondering if anyone has come up with a way to check a player's equipped item. I have a torch system I'm trying to implement where a script will check if player has a torch equipped and, if so, start to tick down a variable with each tile moved.

I can get that working, but I am currently not sure how to check if a player is holding a torch. Is there a way to do this in the engine yet?
< >
Showing 1-6 of 6 comments
Ol' Smaug  [developer] Jun 23, 2022 @ 1:23am 
Originally posted by ugly muffins:
Hi, I was wondering if anyone has come up with a way to check a player's equipped item. I have a torch system I'm trying to implement where a script will check if player has a torch equipped and, if so, start to tick down a variable with each tile moved.

I can get that working, but I am currently not sure how to check if a player is holding a torch. Is there a way to do this in the engine yet?

This can be done by accessing the widget where the equipment slot is and checking the item ID of the applicable equipment slot. If there isn't an item in that slot, the "item" property of the slot will be null. For example, the slot element IDs of the built-in equipment widget are "0005", "0006", and "0007", so to check the "right hand" slot you could do something like below (replacing "ITEM_0001" with the torch's ID). Hopefully this helps!
if widget["equipment"].element["0006"].item != null then $item_id = widget["equipment"].element["0006"].item.id; if $item_id == "ITEM_0001" then print("Torch equipped"); end; end;
Originally posted by Ol' Smaug:
Originally posted by ugly muffins:
Hi, I was wondering if anyone has come up with a way to check a player's equipped item. I have a torch system I'm trying to implement where a script will check if player has a torch equipped and, if so, start to tick down a variable with each tile moved.

I can get that working, but I am currently not sure how to check if a player is holding a torch. Is there a way to do this in the engine yet?

This can be done by accessing the widget where the equipment slot is and checking the item ID of the applicable equipment slot. If there isn't an item in that slot, the "item" property of the slot will be null. For example, the slot element IDs of the built-in equipment widget are "0005", "0006", and "0007", so to check the "right hand" slot you could do something like below (replacing "ITEM_0001" with the torch's ID). Hopefully this helps!
if widget["equipment"].element["0006"].item != null then $item_id = widget["equipment"].element["0006"].item.id; if $item_id == "ITEM_0001" then print("Torch equipped"); end; end;
Thank you, this worked! One more, thing, there seems to be a bug with saving and loading. When I load my game, I can no longer open my player's inventory.
Ol' Smaug  [developer] Jun 24, 2022 @ 11:05pm 
No problem! I'm glad that worked. :) I will take a look at the loading bug, thanks for letting me know about it.
El Chico Gordo Dec 5, 2022 @ 4:26pm 
Ah, that was what I also needed.
Not sure where to get that information about 0006 for the "right hand" but at least I can use that.
Any idea how to use this in a dialogue?
I would like to have a different dialogue if the item is equipped. But all I can make is print to the console. What would be the flow for using this as a condition in a dialog?
Or do I have to create a variable and then read the value as condition or so?
Ol' Smaug  [developer] Dec 6, 2022 @ 6:56pm 
Originally posted by El Chico GordoGER:
Ah, that was what I also needed.
Not sure where to get that information about 0006 for the "right hand" but at least I can use that.
Any idea how to use this in a dialogue?
I would like to have a different dialogue if the item is equipped. But all I can make is print to the console. What would be the flow for using this as a condition in a dialog?
Or do I have to create a variable and then read the value as condition or so?

In order to find the ID of a built-in slot, e.g. the "0006", you can duplicate the widget in the Widget Editor, then select the slots and check the ID from the Element Properties panel. I'll try to provide a reference for all of these when I can.

Regarding dialogue, you'd probably need to include a script node at the beginning that does the check above and then stores it into a global property, for example true/false according to whether or not they have the item equipped, then you could check that global property in the condition where needed later in the dialogue. Hopefully that helps!
El Chico Gordo Dec 7, 2022 @ 10:07am 
Yea, I did the script solution which then executes one dialog or the other. Just wasn't sure if this could work in the condition statement of the dialoges as well but wasn't sure how to implement this.
< >
Showing 1-6 of 6 comments
Per page: 1530 50