#(nicochulo2) Modify item in clicked slot (on player clicks in inventory)

106 messages · Page 1 of 1 (latest)

cerulean beacon
#

I am trying to make it so that clicking on an item in the inventory with another certain item modifies the former's lore. So far I'm able to detect the click and modify the ItemTag correctly but the item refuses to be modified. Here is my code, I've tried both adjust and inventory set, the idea is to change the item clicked to go from Ammo: 0 to Ammo: # where # is the number of items in the cursor when the item was clicked:

https://paste.denizenscript.com/View/128144

(P.S; I did also just notice I used adjust wrong, but when I print <context.inventory.slot[<context.raw_slot>]> or <context.inventory.slot[<context.slot>]> both return AIR anyways

hallow cragBOT
#

(nicochulo2) Modify item in clicked slot (on player clicks in inventory)

hallow cragBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

trim tinsel
#

Why not have the ammo as a flag on the item, and adjust the lore whenever it changes?

cerulean beacon
trim tinsel
#

!debug

hushed mulchBOT
# trim tinsel !debug
Info: debug

If you need help with a script issue, one of the most powerful tools Denizen has to offer is full debug output. This is displaying in your console whenever scripts are running until you turn debug off. To share a debug log quickly and easily with helpers, simply run the command /denizen debug -r in-game to begin recording, then run through the part of the script you need help with, then run the command /denizen submit. This will give you a link to a paste of the debug log, which you can then copy/paste back to us!

cerulean beacon
#

let me see

cerulean beacon
#

maybe I've misunderstood the inventory command

#

oh nvm, I'm a fool, I'm trying to provide it with a list instead of an item

#

let me patch that up

#

@trim tinsel

#

have done another debug now

#

no errors but still doesn't work

#

I guess I don't know what I'm doing, this is a confusing ordeal

#

I just want to modify the item in the slot ;-;

trim tinsel
hushed mulchBOT
# trim tinsel !logcheck https://paste.denizenscript.com/View/128159
Server Version

Paper version git-Paper-550 (MC: 1.19.4)

Plugin Version(s)

Denizen: 1.2.8-SNAPSHOT (build 6844-DEV) -- (:warning:Outdated build, behind by 248)
Depenizen: 2.1.0 (build 840) -- (:warning:Outdated build, behind by 25)

Checked For

@trim tinsel

UUID Version

4 (:white_check_mark: Online)

Java Version

17.0.11 :white_check_mark:

Other Noteworthy Plugin(s)

ProtocolLib: 5.1.1-SNAPSHOT-668

Possibly Relevant Plugin(s)

ViaVersion: 4.10.1 - Mixed client vs server versions can sometimes cause packet-related issues.

trim tinsel
#

You are wildly outdated. Update Denizen and Depenizen, and check to see if this issue is fixed

#

!update denizen Depenizen

hushed mulchBOT
trim tinsel
#

@cerulean beacon has this resolved your issue?

cerulean beacon
#

let me try

wanton badgerBOT
cerulean beacon
#

yay

cerulean beacon
#

I think my code is just wrong but idk what to do to do what I want to do XD

#

all I want is just to update the lore of the item in the slot I click on

vapid fractal
#

Possible.

#

Give me a moment.

#

Your method is rather complicated, a flag method is better.

#

But let me see why the slot is incorrect.

cerulean beacon
#

I run the debug thing again and it gives no errors, so it's doing non-wrong things, just not the things I want it to do XD

vapid fractal
#

I see the problem.

#

adjust can adjust definitions, but you're doing it incorrectly.

#

!c adjust

hushed mulchBOT
# vapid fractal !c adjust
Group

core

Syntax

adjust [<ObjectTag>/def:<name>|...] [<mechanism>](:<value>)

Short Description

Adjusts an object's mechanism.

Description

Many object tag types contains options and properties that need to be adjusted.
Denizen employs a mechanism interface to deal with those adjustments.
To easily accomplish this, use this command with a valid object mechanism, and sometimes accompanying value.

Specify "def:<name>" as an input to adjust a definition and automatically save the result back to the definition.

You can optionally adjust a MapTag of mechanisms to values.

To adjust an item in an inventory, use !command inventory...

vapid fractal
#

Check the third example.

#

Also, this is highly unnecessary.

#

There is no need to set the item again.

#

!c inventory

hushed mulchBOT
# vapid fractal !c inventory
Group

item

Syntax

inventory [open/close/copy/move/swap/set/keep/exclude/fill/clear/update/adjust <mechanism>:<value>/flag <name>(:<action>)[:<value>] (expire:<time>)] (destination:<inventory>) (origin:<inventory>/<item>|...) (slot:<slot>)

Short Description

Edits the inventory of a player, NPC, or chest.

Description

Use this command to edit the state of inventories.
By default, the destination inventory is the current attached player's inventory.

If you are copying, swapping, removing from (including via "keep" and "exclude"), adding to, moving, or filling inventories,
you'll need both destination and origin inventories.

Origin inventories may be specified as a list of ItemTags, but destinations must be actual InventoryTags.

Using "open", "clear", or "update" only require a destination.
"Update" also req...

vapid fractal
#

- inventory adjust d:<[inv]> slot:<[slot]> lore:my_lore

#

Etc.

#

Using flags is probably a good idea too.

cerulean beacon
#

I was about to say, I also tried - inventory adjust slot:<context.raw_slot> "lore:<[newlore]>" to no avail

vapid fractal
#

Also don't use raw_slot

cerulean beacon
#

I'm confused as to the difference XD

#

since both returned AIR upon testing

vapid fractal
#

Raw slot is for ... I forget, but it's handy for having an external inventory open like a chest and it counts beyond the limit of that. I think someone else can explain it much better.

cerulean beacon
#

intrigante

#

let me try some tweaking

vapid fractal
#

Hm it is weird that it is returning air, let me..

#

!e clicks in inventory

hushed mulchBOT
# vapid fractal !e clicks in inventory
Group

Player

Event Lines

player (<click_type>) clicks (<item>) in <inventory>

Switches

with:<item> to only process the event if a specified cursor item was used.
in_area:<area> replaces the default 'in:<area>' for this event.
action:<action> to only process the event if a specified action occurred.
slot:<slot> to only process the event if a specified slot or slot_type was clicked. For slot input options, see !language Slot Inputs.

Triggers

when a player clicks in an inventory. Note that you likely will also want to listen to !event player drags in inventory.

Has Player

Always. - this adds switches flagged:<flag name> + permission:<node>, in addition to the <player> link.

Context

<context.item> returns the ItemTag the player has clicked on.
<context.inventory> returns the InventoryTag (the 'top' inventory, regardless of which slot was clicked).
<context.clicked_inventory> returns the InventoryTag that was clicked in.
<context.cursor_item> returns the item the Player is clicking with.
<context.click> returns an ElementTag with the name of the click type. Click type list: <@link url...
<context.slot_type> returns an ElementTag with the name of the slot type that was clicked. Slot ty...
<context.slot> returns an ElementTag with the number of the slot that was clicked.
<context.raw_slot> returns an ElementTag with the raw number of the slot that was clicked.
<context.is_shift_click> returns true if 'shift' was used while clicking.
<context.action> returns the inventory_action. See <@link language Inventory Actions>.
... and 1 more.

Determine

ItemTag to set the current item for the event.

Has Known Location

True - this adds switches in:<area> + location_flagged:<flag name>.

Cancellable

True - this adds <context.cancelled> and determines cancelled + cancelled:false.

vapid fractal
#

Hmm.

#

I see the problem.

cerulean beacon
#

it's finally working :D

vapid fractal
#

context.inventory returns the 'top' inventory, so it's getting your crafting table.

#

Or uh.

#

Crafting inventory.

#

Use context.clicked_inventory

cerulean beacon
#

I went for ```yml

  • inventory adjust d:<context.inventory> slot:<context.slot> "lore:<[newlore]>"
#

and it worked

vapid fractal
#

That...

#

Shouldn't work.

cerulean beacon
#

well, it did XD

vapid fractal
#

Where was the item?

#

Because this feels like a

#

!itworks

hushed mulchBOT
# vapid fractal !itworks
Info: itworks

Many newer scripters tend to not realize the important difference between "it works" and "it is correct". Just because a script works does not mean everything's fine.

Helpers are encouraged to refuse to continue helping a user with the "if it works it's good enough" mindset until they fix all the things that are wrong (but seem to work) in their script.

Read a longer writeup explaining this idea on the forum here: https://forum.denizenscript.com/threads/public-information-writeup-the-it-works-fallacy.265/

vapid fractal
#

As asked, where was the item when you clicked on it?

cerulean beacon
#

right there

vapid fractal
#

I don't know what inventory that is.

cerulean beacon
#

player inventory

vapid fractal
#

That shouldn't have worked at all, what?

cerulean beacon
#

let me test it on a chest XD

#

works on a shulker too

#

does not work on the crafting grid

vapid fractal
#

I'd still recommend using context.clicked_inventory because this genuinely feels like unintended behavior, since the meta states that context.inventory is only for the 'top' inventory.

cerulean beacon
#

intrigante

#

let's try if that works

#

it does, indeed, still work

#

well, I guess now you know about a... bug(???)... to look out for in the future

vapid fractal
#

More of, a scripter problem than a bug.

#

If this is all then

polar caveBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@cerulean beacon

cerulean beacon
#

indeed, I may have to make another ticket if I can't remove the items from the cursor but that's another thing entirely XD

#

if it isn't too much to ask, do you know how to do that? XD

vapid fractal
#

!c take

hushed mulchBOT
# vapid fractal !c take
Group

item

Syntax

take [iteminhand/cursoritem/bydisplay:<name>/bycover:<title>|<author>/slot:<slot>/flagged:<flag>/item:<matcher>] (quantity:<#>) (from:<inventory>)

Short Description

Takes an item from the player.

Description

Takes items from a player or inventory.

If the player or inventory does not have the item being taken, nothing happens.

Using 'slot:' will take the items from that specific slot.

Using 'flagged:' with a flag name will take items with the specified flag name, see !language flag system.

Using 'iteminhand' will take from the player's held item slot.

Using 'cursoritem' will take from the player's held cursor item (as in, one that's actively being picked up and moved in an inventory scree...

vapid fractal
#

cursoritem

cerulean beacon
#

gnarly

vapid fractal
#

As per the meta.

cerulean beacon
#

perfect, perfect

#

well, that should be all, then

#

thank you very much for your assistance

#

it has been a most pleasant experience