#(Dangles) Item Flag not incrementing

156 messages · Page 1 of 1 (latest)

tawdry wharf
#

I have a custom flag assigned to my script item. Whenever the item is used, it should increment the flag, however, it reaches one and is reset to 0.
https://paste.denizenscript.com/View/132914

worthy urchinBOT
#

(Dangles) Item Flag not incrementing

worthy urchinBOT
#

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.

tawdry wharf
#

So I got the flag working now (thanks icecapade), but the item just does not take any durability loss

real nacelle
#

!debug

dense heathBOT
# real nacelle !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!

tawdry wharf
#

ignore the inject errors

real nacelle
#

Your event is cancelling on and off because of your mod[2] check.

wise bronzeBOT
real nacelle
#

Are you making custom durability?

tawdry wharf
#

yes!

#

it should cancel every other time you use the item

#

thus doubling its durability

real nacelle
#

That seems to be what it's doing.

#

I don't understand?

#

Maybe you should narrate the durability too just to make sure it's actually taking damage?

tawdry wharf
#

I am

#

the items durability is not increasing

#

I can even see the weapon hasn't taken any damage

#

yet the flag is incrementing

real nacelle
#

Uh.

#

Alright there's something weird going on.

mossy galleon
#

its working for me.

#

just testsed it

real nacelle
#

No I think I know the issue.

mossy galleon
#

is it a version error?

dense heathBOT
real nacelle
#

This is a

#

!l safety in events

dense heathBOT
# real nacelle !l safety in events

One of the more common issues in Denizen scripts (particularly ones relating to inventories) is
*event safety*. That is, using commands inside an event that don't get along with the event.

The most common example of this is editing a player's inventory, within an inventory-related event.
Generally speaking, this problem becomes relevant any time an edit is made to something involved with an event,
within the firing of that event.
Take the following examples:


on player clicks in inventory:
- take iteminhand
on entity damaged:
- remove <context.entity>

In both examples above, something related to the event (the player's inventory, and the entity being damaged)
is being modified within the event itself.
These break due a rather important reason: The event is firing before and...

Group

Script Events

real nacelle
#

You're editing the item when it's taking damage, and I think it's getting the item before the item took durability damage.

#

However, this... doesn't seem like correct behavior because it should account for the damage being taken?

#

But also

mossy galleon
#

i think another event is causing something to break

real nacelle
#

!e item takes damage

dense heathBOT
# real nacelle !e item takes damage
Group

Player

Event Lines

player item takes damage player <item> takes damage

Triggers

when the player damages an item.

Has Player

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

Context

<context.damage> returns the amount of damage the item has taken.
<context.original_damage> returns the original amount of damage the item would have taken, before ...
<context.item> returns the item that has taken damage.
<context.slot> returns the slot of the item that has taken damage. This value is a bit of a hack and is not reliable.

Determine

ElementTag(Number) to set the amount of damage the item will take.

Has Known Location

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

Cancellable

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

mossy galleon
#

are you cancelling something in another event? i see the block stuff

real nacelle
#

I am not.

#

I'm getting the same issue.

mossy galleon
real nacelle
#

Are you on 1.21.4 latest?

mossy galleon
#
dense heathBOT
# mossy galleon !logcheck https://paste.denizenscript.com/View/132918
Server Version

Paper version 1.21.4-211-main@6ea4202 (2025-03-13T11:49:31Z)

Plugin Version(s)

Citizens v2.0.35-SNAPSHOT (build 3597) -- (:warning:Outdated build, behind by 189)
Denizen v1.3.1-SNAPSHOT (build 7143-DEV) -- (:warning:Outdated build, behind by 14)

Checked For

@mossy galleon

UUID Version

4 (:white_check_mark: Online)

Java Version

21.0.1 :white_check_mark:

Potentially Bad Line(s)

Caused by: java.lang.ClassNotFoundException: org.bukkit.craftbukkit.v1_21_R1.boss.CraftBossBar :warning: Log contains error messages.

mossy galleon
#

thats my server rn

real nacelle
#

Well yeah, because your item isn't getting flagged.

#

It's returning false because the flag doens't exist.

mossy galleon
#

oh

#

is that a whole another issue then

real nacelle
#

Inventory flagging is whats preventing the item damage.

#

Now how do we get around this? uh...

mossy galleon
real nacelle
#

I don't know the why, I just know the reason it's happening. Inventory flagging is the reason why it's not updating it's damage. I assume because context.item is getting the item before it's durability is changed, but that's speculation.

#

Think we'd need a developer to explain why this is, but a solution is definitely needed as a work around.

#

I've made my own durability system, apparently I cancelled the event passively and ran my own event for calculating custom durability, and I'm adjusting the durability of the item via - adjust in my own event, and then setting the item back. But that's also due to some other nonsense I'm doing.

I don't think making your own event is the correct solution, but I do think you'll have to also adjust the items durability after flagging it since it's not currently updating.

tawdry wharf
#

Sorry, just returned.

real nacelle
#

Be aware that you can set the durability over it's maximum and it will not break the item, you may have to replicate that if you care. Otherwise the next item damage on that item will break it naturally.

tawdry wharf
#

I am just trying to find ways to give items more durability, without using unbreaking.

real nacelle
#

Understandable, just pointing out that flagging the item is the reason why it's not updating for some reason.

tawdry wharf
#

Is there a way to decrement the durability? Like when the durabilitycounter hits an even number reduce the amount of durability

real nacelle
#

Sure.

#

!m itemtag.durability

dense heathBOT
# real nacelle !m itemtag.durability

Changes the durability of damageable items.

Object

ItemTag

Input

ElementTag(Number)

Tags

<ItemTag.durability> Returns the current durability (number of uses) on the item.
<ItemTag.max_durability> Returns the maximum durability (number of uses) of this item. For use wit...
<ItemTag.repairable> Returns whether the item can be repaired. If this returns true, it will enabl...

real nacelle
#

Durability is weird because it's reverse from what you expect. It's not remaining uses, it's current uses.

#

So a durability of 0 means it's undamaged.

tawdry wharf
#

so the generated example...doesn't seem to work

real nacelle
#

The generated example is wrong.

#

!g adjust is not for inventory

dense heathBOT
#
Possible Confusion

Did you mean to search for common mistakes - the adjust command is not for items/materials/etc.?

real nacelle
#

I realize this can be confusing because I just said I used - adjust in my own event, but that's because I am adjusting a definition. Not the inventory.

tawdry wharf
#

so i'd use inventory to change its durability

real nacelle
#

Yes.

tawdry wharf
#

interesting, is there anyway to change durability by a value? so lets I want to reduce it by one? the operator -- doesn't seem to work, so I am guessing I'd have to get the items durability and sub / add by 1 or whatever number I like

#

that seems to work, but unfortunately can't go into the negatives lol booo

real nacelle
#

I mean you're not suppose to go into negatives.

#

Durability is added up until it's maximum durability, and then it breaks.

tawdry wharf
#

sadly doesn't appear max durability is adjustable 😐

real nacelle
#

It's not.

#

It's very unfortunate.

#

Well.

#

Not yet anyways.

#

You'll have to play with data components if you wanna change max durability, because max_damage is a data component.

#

My system was built before this, so I'm not familiar enough with data components to recommend playing with it.

tawdry wharf
#

Would it be bad to ask what your system is

real nacelle
#

I have many many data scripts for vanilla items, and when an item is spawned it calls a procedure to adjust it with all of my custom item information, attribute modifiers, lore, and durability changes. Calling this information from that data script.

Maximum durability is called from the data script, and if that doesn't exist than the max_durability flag.
When updating my vanilla durability, it will max_durabiliy - (max_durability * ( durability/max_durability ) )

#

So it tries it's best to replicate vanilla damage updating with the custom maximum.

tawdry wharf
#

okay

#

so

#

I tried this and it doesn't work...but I thought I had a work around

real nacelle
#

You're trying to get item durability to change right?

tawdry wharf
#

yessir

real nacelle
#

Don't use an after event.

#

Even though that... Should work.

#

Put it on your main event.

tawdry wharf
#

are after events just bad

mossy galleon
tawdry wharf
#

well combining them doesn't seem to work 😦

#

for adjusting durability I should be using inventory right?

real nacelle
#

Yes.

tawdry wharf
#

I have even just tried forcing the durability to a set number and that does not work

real nacelle
#

Is it even firing at all?

#

!debug

dense heathBOT
# real nacelle !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!

tawdry wharf
#

this is the script, trying to force something to happen

real nacelle
#

Looks like it error'd.

#

Yeah, I see the problem.

#

This is a bit problematic.

#

The context.slot is incorrect.

#

The event warns that this is hacky and not reliable.

#

This may get kind of tricky since the slot is unreliable.

#

I didn't realize that this occurs on my end probably too.

#

You may have to use...

#

!t inventorytag.find_item

dense heathBOT
real nacelle
#

Which is a problem because of duplicate items that may exist, assuming you have multiple copies. I'm not sure in which order it'll search, from the first slot or from the final slot in the inventory.

#

Perhaps, someone else has a different solution?

tawdry wharf
#

My idea was just to decrement a bonus durablility flag until it hits zero then the item takes damage but that’s lame

#

That worked.

real nacelle
#

Honestly, if it's an item and not armor use the players held item slot

#

If it's armor... I'm not sure how to match your inventory slot to that specific item off the bat

#

First thing I'm thinking of is material matching with choose to hard dictate the slot.

#

Or similar

tawdry wharf
#

silly question, is there a way to display an items flags in its lore?

mossy galleon
#

lore is a list

#

!m lore

dense heathBOT
# mossy galleon !m lore
Cannot Specify Searched Mechanism

Multiple possible mechanisms: ItemTag.lore, EntityTag.explored_locations.

#
Possible Confusion

Did you mean to search for command look?

mossy galleon
#

you just adjust it

#

inventory adjust slot:hand lore:<list[line_1|line_2|<player.flag[test]>]>

tawdry wharf
#

what about having them in an item scripts lore

real nacelle
#

It may not be smart to do that, since depending on where it's constructed there may not be a linked player.

#

Ex: Villager trades, mobs spawning with it, etc.

tawdry wharf
#

it would be an item flag

#

for that item in particular 🙂

real nacelle
#

You want the item script container to... Reference it's own flag?

tawdry wharf
#

yes. the flag increments and decrements

#

so its a dynamic value

real nacelle
#

I don't think you can tell the item script container to reference itself, since it's still being built on reload? You're better off hardcording the value.

Now if you mean, if you can adjust an already existing items lore and use the items flag? Sure, absolutely.

#

If you're using player flags, then it might work but as said be weary of where you're giving the item to since it may error if a linked player doesn't exist.

tawdry wharf
#

that makes sense

real nacelle
#

This is why I have an item lore rebuild procedure that generates all of the lore onto an item, but that's my extreme solution with all of my custom info on my items including durability.

tawdry wharf
#

I think in the meantime I am going to settle on the bonus durability idea, but I'd like an indicator to the player of what's remaining

#

so i might have when an item is "created" it would tack on durability as the last line of lore

real nacelle
#

Very much possible.

#

Theres several sources of items being made too. Villager trades. Mob spawning. Loot generated. Crafting.

#

Technically smithing too I believe?