#(JustinS) Swap 2 inventories and save contents

60 messages · Page 1 of 1 (latest)

forest fractal
#

Im trying to swap between the players inventory and a custom inventory (called Forcepowers_inventory), running the following code when right clicking a netherstar, and I don't get any errors though the inventories arent swapping

forcepower_input_script:
    type: world
    events:
        on player right clicks * with:force_powers:
        - ratelimit <player> 0.05s
        - if <player.inventory.title> != Force_Powers:
            - narrate "1"
            - note <player.inventory> as:player_inv<player.uuid>
            - note <inventory[forcepowers_inventory]> as:forcepowers_inv<player.uuid>
            - inventory swap origin:player_inv<player.uuid> destination:forcepowers_inv<player.uuid>
        - else:
            - narrate "2"
            - note <player.inventory> as:forcepowers_inv<player.uuid>
            - inventory swap origin:forcepowers_inv<player.uuid> destination:player_inv<player.uuid>

        - narrate "player right clicks netherstar"```
Inventory:```
forcepowers_inventory:
    type: inventory
    inventory: chest
    title: Force_Powers
    gui: false
    size: 36```

Debug of me right clicking twice:
https://paste.denizenscript.com/View/122911
pine hareBOT
#

(JustinS) Swap 2 inventories and save contents

pine hareBOT
#

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.

ornate spade
#

A players inventory never has a title (beyond just inventory) as indicated by the debug

#

So it wont ever equal "force_powers"

forest fractal
#

"13:19:21 Filled tag <player.inventory.title> with 'Inventory'. "

#

Doesnt that mean that the inventory title is Inventory?

ornate spade
#

Yes, and you cant change that

forest fractal
#

No

#

I want to change the whole inventory

#

does that not also change the title?

ornate spade
#

Unless im just completely mistaken here, a players inventory title will never change

#

No matter what you do to it

#

Might as well just use a flag

forest fractal
#

But then what happens if I use inventory swap with forcepowers_inventory: type: inventory inventory: chest title: Force_Powers gui: false size: 36

#

because that has a title

ornate spade
#

Not sure, but as i said, just use a flag to test whether or not to swap

forest fractal
#

But also, besides that, right now it runs ```
- narrate "1"
- note <player.inventory> as:player_inv<player.uuid>
- note <inventory[forcepowers_inventory]> as:forcepowers_inv<player.uuid>
- inventory swap origin:player_inv<player.uuid> destination:forcepowers_inv<player.uuid>

ornate spade
forest fractal
#

Or at least, the contents dont change when that runs

ornate spade
#

bc you swapped between 2 notes, not between the player and a note

#

you prob meant to do origin:<player.inventory>

forest fractal
#

Ill give that a try

ornate spade
storm walrusBOT
# ornate spade !c flag
Group

core

Syntax

flag [<object>|...] [<name>([<#>])](:<action>)[:<value>] (expire:<time>)

Short Description

Sets or modifies a flag on any flaggable object.

Description

The flag command sets or modifies custom data values stored on any flaggable object (the server, a player/NPC/entity, a block location, ...).
See also !language flag system.

This command supports data actions, see !language data actions.

Flags by default are added permanently (or for the lifetime of the object they're attached to).
You can optionally specify a system time the flag will expire at, using either a DurationTag or a TimeTag.
If a DurationTag is used, it will be equivalent to: <util.time_now.add[<your_duration_here>]>

ornate spade
#

if flag is 1 -> set flag to 2 else if flag is 2 -> set flag to 1

forest fractal
# ornate spade if flag is 1 -> set flag to 2 else if flag is 2 -> set flag to 1

Well I made some progress. I can now switch between the inventories, though only the contents of the player inventory gets saved. Whenever I switch to the forcepowers_inv, its empty and when I add items and swap again, those items dont get saved.

        on player right clicks * with:force_powers:
        - ratelimit <player> 0.05s
        - if <player.flag[inventory]> == player_inv:
            - narrate "1"
            - note <player.inventory> as:player_inv<player.uuid>
            - note <inventory[forcepowers_inventory]> as:forcepowers_inv<player.uuid>
            - inventory swap origin:<player.inventory> destination:forcepowers_inv<player.uuid>
            - flag <player> inventory:forcepowers_inv
        - else if <player.flag[inventory]> == forcepowers_inv:
            - narrate "2"
            - inventory swap origin:<player.inventory> destination:player_inv<player.uuid>
            - flag <player> inventory:player_inv```
#

I thought I read in the docs that any realtime changes made to a note get saved

#

oh wait I keep making a new forcepowers_inv dont I

ornate spade
#

for swap #1 you made a brand new note every time when swapping, which will overwrite any changes you made to the previous forcepowers_inv

forest fractal
#

yea

ornate spade
#

and for #2 you swap to smething else entirely

forest fractal
#

huh

#

this stuff is hurting my brain

ornate spade
#

i made this script a bit ago for swapping inventoires when switching gaemoes

#

might be a good starting point for you

forest fractal
#

👍 thanks Ill have a look

forest fractal
# ornate spade https://forum.denizenscript.com/resources/gamemode-inventories.46/

Sorry for bothering you again but I just dont get it.
I changed it to this so it works with my flag (I cant get the current inventory from the context like you did)

       on player right clicks * with:force_powers:
        - define from <player.flag[inventory]>
        - if <[from]> == player:
          - define to forcepowers
          - flag <player> inventory:forcepowers
        - if <[from]> == forcepowers:
          - define to player
        - flag <player> Inv.<[from]>_inventory:<player.inventory.list_contents>
        - define newInv <player.flag[Inv.<[to]>_inventory].if_null[<list>]>
        - inventory clear
        - if !<[newInv].is_empty>:
            - inventory set destination:<player.inventory> origin:<[newInv]>
        - define from to```
Though now whenever I give myself the netherstar and rightclick, I keep the netherstar but everything else in my inventory gets removed. That happens every time I keep pressing the netherstar
forest fractal
#

I have no idea why this version doesnt work. I went over it 300 times and it seems correct

forest fractal
#

Anyone?

latent phoenix
#

I think you're setting the note to the player's inventory then immediately swapping the player's inventory to the note which would be the player's inventory. I'm not positive on this being the only issue here though - the item coming back still seems odd to me.

Also - for pasting scripts the paste site is helpful since it will give proper syntax highlighting.

Beyond that - a debug will help identify what's going on.

#

!paste

storm walrusBOT
latent phoenix
#

!debug

storm walrusBOT
# latent phoenix !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!

forest fractal
#

the code is in the pastebin but yeah thats the wrong hightlighting let me change that

forest fractal
# latent phoenix I *think* you're setting the note to the player's inventory then immediately swa...

I dont think so...
Assume this scenario:
Im in my normal player inventory (and the flag recognizes that)
I run the event:
My inventory gets saved as "player_inventory": - note <player.inventory> as:player_inventory<player.uuid>
My inventory gets changed to the force_powers_inventory: - inventory swap origin:<player.inventory> destination:forcepowers_inv<player.uuid>
The forcepowers_inv was defined manually before triggering the event (see the code)
I then flag the player as using the forcepower_inventory - flag <player> inventory:forcepowers_inv
If I now run the event again:
My forcepowers_inventory gets saved: - note <player.inventory> as:forcepowers_inventory<player.uuid>
I switch back to the player inventory that I saved before: - inventory swap origin:<player.inventory> destination:player_inventory<player.uuid>
And I flag the player correctly: - flag <player> inventory:player_inv
And repeat

#

I don't see which part is wrong there

latent phoenix
#

Ahh no you're right. I missed the forcepowers_inventory vs player_inventory. Apparently I'm going cross-eyed today.

Looks like there might be a typo - you're noting forcepowers_inventory<player.uuid> then swapping to forcepowers_inv<player.uuid>

forest fractal
#

you're amazing

#

hoooooolyyy cow I love you

#

thank you so much it finally fucking works

#

I thought I was going crazy

#

Now I just need to figure out how to prevent the items from getting moved to different slots when swapping