Solved Variable Wont Update

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.
Doesnt it update the diamond now?
Oh it does update now. But it will only update if i drop 1 fish in at a time. If i drop a stack of fish in the gui, it wont show any fish in the menu. But if i drop 1 in at a time it will update.
0140ede9df516c63d7debeb62accd1e5.png

https://gyazo.com/0140ede9df516c63d7debeb62accd1e5
[doublepost=1584033859,1584033821][/doublepost]
Oh it does update now. But it will only update if i drop 1 fish in at a time. If i drop a stack of fish in the gui, it wont show any fish in the menu. But if i drop 1 in at a time it will update.
0140ede9df516c63d7debeb62accd1e5.png

https://gyazo.com/0140ede9df516c63d7debeb62accd1e5
The 3 fish that are unstacked are the 3 its reading in the menu. The 61 fish are not being detected
 
Oh it does update now. But it will only update if i drop 1 fish in at a time. If i drop a stack of fish in the gui, it wont show any fish in the menu. But if i drop 1 in at a time it will update.
0140ede9df516c63d7debeb62accd1e5.png

https://gyazo.com/0140ede9df516c63d7debeb62accd1e5
[doublepost=1584033859,1584033821][/doublepost]
The 3 fish that are unstacked are the 3 its reading in the menu. The 61 fish are not being detected

Ah okay i get it now Will work on fixing it wenn i am on pc
 
44 replies :eyes: Wish I had the full code to help you seeing as Lego isn't on his computer atm but I don't :joy:
 
Not a problem :emoji_slight_smile: I really appreciate all the help you given me! Thank you! :emoji_slight_smile:

Well i hope its done now :emoji_slight_smile:

For me its working

Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent

function getWorthOfFish(i: item) :: number:
    if name of {_i} contains "&7Common Herring":
        return 10
    else if name of {_i} contains "&7Common Crab":
        return 100
    else:
        return 0

#Bonus money u get wenn a fish has a bigger size than 1.
# Example:
#     Inc value = 1$:
#         size = 1 = 1$
#         size = 1.5 = 1.5$
#         size = 3 = 3$
#     Inc value = 2.5$:
#         size = 1 = 2.5$
#         size = 1.5 = 3.75$
#         size = 3 = 7.5$
function getSizeIncrease(i: item, s: number) :: number:
    if name of {_i} contains "&7Common Herring":
        return (1 * {_s})
    else if name of {_i} contains "&7Common Crab":
        return (10 * {_s})
    else:
        return 0

function getSize(i: item) :: number:
    set {_s} to line 1 of lore of {_i}
    set {_s::*} to {_s} split at "&8* &aSize: "
    set {_s} to {_s::2}
    replace every "cm" with "" in {_s}
    set {_s} to {_s} parsed as a number
    return {_s}

function getPriceOfFish(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value)
        set {_p::s} to getSize(loop-value)
        set {_p::i} to getSizeIncrease(loop-value,{_p::s})
        set {_p::p} to {_p::w} + {_p::i}
        set {_p::a} to item amount of loop-value
        set {_p::t} to {_p::a} * {_p::p}
        add {_p::t} to {_t}
    return {_t}

function getFish(p: player) :: items:
    loop all items in {_p}'s current inventory:
        if loop-value is raw cod, raw salmon or pufferfish:
            if name of loop-value contains "&7Common Herring" or "&7Common Crab":
                add loop-value to {_fish::*}
    return {_fish::*}

function getLatestPrice(i: item) :: number:
    set {_p} to name of {_i}
    replace every "&aSell for: &a$&a" with "" in {_p}
    set {_p} to {_p} parsed as a number
    return {_p}

function fishAmount(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        add item amount of loop-value to {_t}
    return {_t}

function updateFishPrice(p: player):
    wait 1 tick
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set name of slot 31 of {_p}'s current inventory to "&aSell for: &a$&a%{_totalprice}%"
    set line 1 of lore of slot 31 of {_p}'s current inventory to "&bAmount of fish: %{_fishamount}%"

function sellFish(p: player, i: item):
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set {_latestprice} to getLatestPrice({_i})
    if {_latestprice} = {_totalprice}:
        if {_totalprice} = 0:
            send "&b[Mr. Boatwright] &cNothing to sell" to {_p}
            stop
        close {_p}'s inventory
        add {_totalprice} to balance of {_p}
        send "&b[Mr. Boatwright] &7You sold all your fish for &a$%{_totalprice}%" to {_p}
    else:
        send "&b[Mr. Boatwright] &cOops something went wrong. ##001 Price Not Matching" to {_p}
        send "&b[Mr. Boatwright] &7Updating Price..." to {_p}
        updateFishPrice({_p})
        send "&b[Mr. Boatwright] &7##001 Pls try again." to {_p}

function openfish(p: player):
     open virtual chest with size 4 named "&bMr. Boatwright" to {_p}
     format gui slot 27, 28, 29, 30, 32, 33, 34 and 35 of {_p} with green stained glass pane named "" to do nothing
     format gui slot 31 of {_p} with diamond to run function sellFish({_p}, gui-clicked-item)
     updateFishPrice({_p})

on InventoryClickEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())

on InventoryDragEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())

on right click on entity:
     if name of clicked entity contains "&bMr. Boatwright":
         openfish(player)
 
Well i hope its done now :emoji_slight_smile:

For me its working

Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent

function getWorthOfFish(i: item) :: number:
    if name of {_i} contains "&7Common Herring":
        return 10
    else if name of {_i} contains "&7Common Crab":
        return 100
    else:
        return 0

#Bonus money u get wenn a fish has a bigger size than 1.
# Example:
#     Inc value = 1$:
#         size = 1 = 1$
#         size = 1.5 = 1.5$
#         size = 3 = 3$
#     Inc value = 2.5$:
#         size = 1 = 2.5$
#         size = 1.5 = 3.75$
#         size = 3 = 7.5$
function getSizeIncrease(i: item, s: number) :: number:
    if name of {_i} contains "&7Common Herring":
        return (1 * {_s})
    else if name of {_i} contains "&7Common Crab":
        return (10 * {_s})
    else:
        return 0

function getSize(i: item) :: number:
    set {_s} to line 1 of lore of {_i}
    set {_s::*} to {_s} split at "&8* &aSize: "
    set {_s} to {_s::2}
    replace every "cm" with "" in {_s}
    set {_s} to {_s} parsed as a number
    return {_s}

function getPriceOfFish(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value)
        set {_p::s} to getSize(loop-value)
        set {_p::i} to getSizeIncrease(loop-value,{_p::s})
        set {_p::p} to {_p::w} + {_p::i}
        set {_p::a} to item amount of loop-value
        set {_p::t} to {_p::a} * {_p::p}
        add {_p::t} to {_t}
    return {_t}

function getFish(p: player) :: items:
    loop all items in {_p}'s current inventory:
        if loop-value is raw cod, raw salmon or pufferfish:
            if name of loop-value contains "&7Common Herring" or "&7Common Crab":
                add loop-value to {_fish::*}
    return {_fish::*}

function getLatestPrice(i: item) :: number:
    set {_p} to name of {_i}
    replace every "&aSell for: &a$&a" with "" in {_p}
    set {_p} to {_p} parsed as a number
    return {_p}

function fishAmount(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        add item amount of loop-value to {_t}
    return {_t}

function updateFishPrice(p: player):
    wait 1 tick
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set name of slot 31 of {_p}'s current inventory to "&aSell for: &a$&a%{_totalprice}%"
    set line 1 of lore of slot 31 of {_p}'s current inventory to "&bAmount of fish: %{_fishamount}%"

function sellFish(p: player, i: item):
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set {_latestprice} to getLatestPrice({_i})
    if {_latestprice} = {_totalprice}:
        if {_totalprice} = 0:
            send "&b[Mr. Boatwright] &cNothing to sell" to {_p}
            stop
        close {_p}'s inventory
        add {_totalprice} to balance of {_p}
        send "&b[Mr. Boatwright] &7You sold all your fish for &a$%{_totalprice}%" to {_p}
    else:
        send "&b[Mr. Boatwright] &cOops something went wrong. ##001 Price Not Matching" to {_p}
        send "&b[Mr. Boatwright] &7Updating Price..." to {_p}
        updateFishPrice({_p})
        send "&b[Mr. Boatwright] &7##001 Pls try again." to {_p}

function openfish(p: player):
     open virtual chest with size 4 named "&bMr. Boatwright" to {_p}
     format gui slot 27, 28, 29, 30, 32, 33, 34 and 35 of {_p} with green stained glass pane named "" to do nothing
     format gui slot 31 of {_p} with diamond to run function sellFish({_p}, gui-clicked-item)
     updateFishPrice({_p})

on InventoryClickEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())

on InventoryDragEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())

on right click on entity:
     if name of clicked entity contains "&bMr. Boatwright":
         openfish(player)
Why do I feel like this skript could be simplified
Probably all the functions
 
Well i hope its done now :emoji_slight_smile:

For me its working

Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent

function getWorthOfFish(i: item) :: number:
    if name of {_i} contains "&7Common Herring":
        return 10
    else if name of {_i} contains "&7Common Crab":
        return 100
    else:
        return 0

#Bonus money u get wenn a fish has a bigger size than 1.
# Example:
#     Inc value = 1$:
#         size = 1 = 1$
#         size = 1.5 = 1.5$
#         size = 3 = 3$
#     Inc value = 2.5$:
#         size = 1 = 2.5$
#         size = 1.5 = 3.75$
#         size = 3 = 7.5$
function getSizeIncrease(i: item, s: number) :: number:
    if name of {_i} contains "&7Common Herring":
        return (1 * {_s})
    else if name of {_i} contains "&7Common Crab":
        return (10 * {_s})
    else:
        return 0

function getSize(i: item) :: number:
    set {_s} to line 1 of lore of {_i}
    set {_s::*} to {_s} split at "&8* &aSize: "
    set {_s} to {_s::2}
    replace every "cm" with "" in {_s}
    set {_s} to {_s} parsed as a number
    return {_s}

function getPriceOfFish(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value)
        set {_p::s} to getSize(loop-value)
        set {_p::i} to getSizeIncrease(loop-value,{_p::s})
        set {_p::p} to {_p::w} + {_p::i}
        set {_p::a} to item amount of loop-value
        set {_p::t} to {_p::a} * {_p::p}
        add {_p::t} to {_t}
    return {_t}

function getFish(p: player) :: items:
    loop all items in {_p}'s current inventory:
        if loop-value is raw cod, raw salmon or pufferfish:
            if name of loop-value contains "&7Common Herring" or "&7Common Crab":
                add loop-value to {_fish::*}
    return {_fish::*}

function getLatestPrice(i: item) :: number:
    set {_p} to name of {_i}
    replace every "&aSell for: &a$&a" with "" in {_p}
    set {_p} to {_p} parsed as a number
    return {_p}

function fishAmount(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        add item amount of loop-value to {_t}
    return {_t}

function updateFishPrice(p: player):
    wait 1 tick
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set name of slot 31 of {_p}'s current inventory to "&aSell for: &a$&a%{_totalprice}%"
    set line 1 of lore of slot 31 of {_p}'s current inventory to "&bAmount of fish: %{_fishamount}%"

function sellFish(p: player, i: item):
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set {_latestprice} to getLatestPrice({_i})
    if {_latestprice} = {_totalprice}:
        if {_totalprice} = 0:
            send "&b[Mr. Boatwright] &cNothing to sell" to {_p}
            stop
        close {_p}'s inventory
        add {_totalprice} to balance of {_p}
        send "&b[Mr. Boatwright] &7You sold all your fish for &a$%{_totalprice}%" to {_p}
    else:
        send "&b[Mr. Boatwright] &cOops something went wrong. ##001 Price Not Matching" to {_p}
        send "&b[Mr. Boatwright] &7Updating Price..." to {_p}
        updateFishPrice({_p})
        send "&b[Mr. Boatwright] &7##001 Pls try again." to {_p}

function openfish(p: player):
     open virtual chest with size 4 named "&bMr. Boatwright" to {_p}
     format gui slot 27, 28, 29, 30, 32, 33, 34 and 35 of {_p} with green stained glass pane named "" to do nothing
     format gui slot 31 of {_p} with diamond to run function sellFish({_p}, gui-clicked-item)
     updateFishPrice({_p})

on InventoryClickEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())

on InventoryDragEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())

on right click on entity:
     if name of clicked entity contains "&bMr. Boatwright":
         openfish(player)
Ok, no errors, updates with the correct amount of fish. But, it wont allow me to sell the fish, and it doesnt show how much they would sell for. Its soooooooo close!! xxD
 
Ok, no errors, updates with the correct amount of fish. But, it wont allow me to sell the fish, and it doesnt show how much they would sell for. Its soooooooo close!! xxD


Mmm it works for me :/.

Full plugin list?

Full skript ver? /ver skript

Full mirror ver? /ver skript-mirror

Full server ver? /ver
 

Back to debugging ig wait a sec
[doublepost=1584057585,1584057443][/doublepost]


Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent
 
function getWorthOfFish(i: item) :: number:
    if name of {_i} contains "&7Common Herring":
        return 10
    else if name of {_i} contains "&7Common Crab":
        return 100
    else:
        return 0
 
#Bonus money u get wenn a fish has a bigger size than 1.
# Example:
#     Inc value = 1$:
#         size = 1 = 1$
#         size = 1.5 = 1.5$
#         size = 3 = 3$
#     Inc value = 2.5$:
#         size = 1 = 2.5$
#         size = 1.5 = 3.75$
#         size = 3 = 7.5$
function getSizeIncrease(i: item, s: number) :: number:
    if name of {_i} contains "&7Common Herring":
        return (1 * {_s})
    else if name of {_i} contains "&7Common Crab":
        return (10 * {_s})
    else:
        return 0
 
function getSize(i: item) :: number:
    set {_s} to line 1 of lore of {_i}
    set {_s::*} to {_s} split at "&8* &aSize: "
    set {_s} to {_s::2}
    replace every "cm" with "" in {_s}
    set {_s} to {_s} parsed as a number
    return {_s}
 
function getPriceOfFish(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value)
        set {_p::s} to getSize(loop-value)
        set {_p::i} to getSizeIncrease(loop-value,{_p::s})
        set {_p::p} to {_p::w} + {_p::i}
        set {_p::a} to item amount of loop-value
        set {_p::t} to {_p::a} * {_p::p}
        add {_p::t} to {_t}
    return {_t}
 
function getFish(p: player) :: items:
    loop all items in {_p}'s current inventory:
        if loop-value is raw cod, raw salmon or pufferfish:
            if name of loop-value contains "&7Common Herring" or "&7Common Crab":
                add loop-value to {_fish::*}
    return {_fish::*}
 
function getLatestPrice(i: item) :: number:
    set {_p} to name of {_i}
    replace every "&aSell for: &a$&a" with "" in {_p}
    set {_p} to {_p} parsed as a number
    return {_p}
 
function fishAmount(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        add item amount of loop-value to {_t}
    return {_t}
 
function updateFishPrice(p: player):
    wait 1 tick
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    Broadcast "Total: %{_totalprice}%"
    set name of slot 31 of {_p}'s current inventory to "&aSell for: &a$&a%{_totalprice}%"
    set line 1 of lore of slot 31 of {_p}'s current inventory to "&bAmount of fish: %{_fishamount}%"
 
function sellFish(p: player, i: item):
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set {_latestprice} to getLatestPrice({_i})
    if {_latestprice} = {_totalprice}:
        if {_totalprice} = 0:
            send "&b[Mr. Boatwright] &cNothing to sell" to {_p}
            stop
        close {_p}'s inventory
        add {_totalprice} to balance of {_p}
        send "&b[Mr. Boatwright] &7You sold all your fish for &a$%{_totalprice}%" to {_p}
    else:
        send "&b[Mr. Boatwright] &cOops something went wrong. ##001 Price Not Matching" to {_p}
        send "&b[Mr. Boatwright] &7Updating Price..." to {_p}
        updateFishPrice({_p})
        send "&b[Mr. Boatwright] &7##001 Pls try again." to {_p}
 
function openfish(p: player):
     open virtual chest with size 4 named "&bMr. Boatwright" to {_p}
     format gui slot 27, 28, 29, 30, 32, 33, 34 and 35 of {_p} with green stained glass pane named "" to do nothing
     format gui slot 31 of {_p} with diamond to run function sellFish({_p}, gui-clicked-item)
     updateFishPrice({_p})
 
on InventoryClickEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())
 
on InventoryDragEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())
 
on right click on entity:
     if name of clicked entity contains "&bMr. Boatwright":
         openfish(player)
 
Back to debugging ig wait a sec
[doublepost=1584057585,1584057443][/doublepost]


Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent
 
function getWorthOfFish(i: item) :: number:
    if name of {_i} contains "&7Common Herring":
        return 10
    else if name of {_i} contains "&7Common Crab":
        return 100
    else:
        return 0
 
#Bonus money u get wenn a fish has a bigger size than 1.
# Example:
#     Inc value = 1$:
#         size = 1 = 1$
#         size = 1.5 = 1.5$
#         size = 3 = 3$
#     Inc value = 2.5$:
#         size = 1 = 2.5$
#         size = 1.5 = 3.75$
#         size = 3 = 7.5$
function getSizeIncrease(i: item, s: number) :: number:
    if name of {_i} contains "&7Common Herring":
        return (1 * {_s})
    else if name of {_i} contains "&7Common Crab":
        return (10 * {_s})
    else:
        return 0
 
function getSize(i: item) :: number:
    set {_s} to line 1 of lore of {_i}
    set {_s::*} to {_s} split at "&8* &aSize: "
    set {_s} to {_s::2}
    replace every "cm" with "" in {_s}
    set {_s} to {_s} parsed as a number
    return {_s}
 
function getPriceOfFish(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value)
        set {_p::s} to getSize(loop-value)
        set {_p::i} to getSizeIncrease(loop-value,{_p::s})
        set {_p::p} to {_p::w} + {_p::i}
        set {_p::a} to item amount of loop-value
        set {_p::t} to {_p::a} * {_p::p}
        add {_p::t} to {_t}
    return {_t}
 
function getFish(p: player) :: items:
    loop all items in {_p}'s current inventory:
        if loop-value is raw cod, raw salmon or pufferfish:
            if name of loop-value contains "&7Common Herring" or "&7Common Crab":
                add loop-value to {_fish::*}
    return {_fish::*}
 
function getLatestPrice(i: item) :: number:
    set {_p} to name of {_i}
    replace every "&aSell for: &a$&a" with "" in {_p}
    set {_p} to {_p} parsed as a number
    return {_p}
 
function fishAmount(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        add item amount of loop-value to {_t}
    return {_t}
 
function updateFishPrice(p: player):
    wait 1 tick
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    Broadcast "Total: %{_totalprice}%"
    set name of slot 31 of {_p}'s current inventory to "&aSell for: &a$&a%{_totalprice}%"
    set line 1 of lore of slot 31 of {_p}'s current inventory to "&bAmount of fish: %{_fishamount}%"
 
function sellFish(p: player, i: item):
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set {_latestprice} to getLatestPrice({_i})
    if {_latestprice} = {_totalprice}:
        if {_totalprice} = 0:
            send "&b[Mr. Boatwright] &cNothing to sell" to {_p}
            stop
        close {_p}'s inventory
        add {_totalprice} to balance of {_p}
        send "&b[Mr. Boatwright] &7You sold all your fish for &a$%{_totalprice}%" to {_p}
    else:
        send "&b[Mr. Boatwright] &cOops something went wrong. ##001 Price Not Matching" to {_p}
        send "&b[Mr. Boatwright] &7Updating Price..." to {_p}
        updateFishPrice({_p})
        send "&b[Mr. Boatwright] &7##001 Pls try again." to {_p}
 
function openfish(p: player):
     open virtual chest with size 4 named "&bMr. Boatwright" to {_p}
     format gui slot 27, 28, 29, 30, 32, 33, 34 and 35 of {_p} with green stained glass pane named "" to do nothing
     format gui slot 31 of {_p} with diamond to run function sellFish({_p}, gui-clicked-item)
     updateFishPrice({_p})
 
on InventoryClickEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())
 
on InventoryDragEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())
 
on right click on entity:
     if name of clicked entity contains "&bMr. Boatwright":
         openfish(player)
It says Total: 0
 
It says Total: 0
Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent
 
function getWorthOfFish(i: item) :: number:
    if name of {_i} contains "&7Common Herring":
        return 10
    else if name of {_i} contains "&7Common Crab":
        return 100
    else:
        return 0
 
#Bonus money u get wenn a fish has a bigger size than 1.
# Example:
#     Inc value = 1$:
#         size = 1 = 1$
#         size = 1.5 = 1.5$
#         size = 3 = 3$
#     Inc value = 2.5$:
#         size = 1 = 2.5$
#         size = 1.5 = 3.75$
#         size = 3 = 7.5$
function getSizeIncrease(i: item, s: number) :: number:
    if name of {_i} contains "&7Common Herring":
        return (1 * {_s})
    else if name of {_i} contains "&7Common Crab":
        return (10 * {_s})
    else:
        return 0
 
function getSize(i: item) :: number:
    set {_s} to line 1 of lore of {_i}
    set {_s::*} to {_s} split at "&8* &aSize: "
    set {_s} to {_s::2}
    replace every "cm" with "" in {_s}
    set {_s} to {_s} parsed as a number
    return {_s}
 
function getPriceOfFish(i: items) :: number:
    broadcast "Fish2: %{_i::*}%"
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value)
        set {_p::s} to getSize(loop-value)
        set {_p::i} to getSizeIncrease(loop-value,{_p::s})
        set {_p::p} to {_p::w} + {_p::i}
        set {_p::a} to item amount of loop-value
        set {_p::t} to {_p::a} * {_p::p}
        add {_p::t} to {_t}
        broadcast "Fish2DATA: %{_p::*}%"
    return {_t}
 
function getFish(p: player) :: items:
    loop all items in {_p}'s current inventory:
        if loop-value is raw cod, raw salmon or pufferfish:
            if name of loop-value contains "&7Common Herring" or "&7Common Crab":
                add loop-value to {_fish::*}
    return {_fish::*}
 
function getLatestPrice(i: item) :: number:
    set {_p} to name of {_i}
    replace every "&aSell for: &a$&a" with "" in {_p}
    set {_p} to {_p} parsed as a number
    return {_p}
 
function fishAmount(i: items) :: number:
    set {_t} to 0
    loop {_i::*}:
        add item amount of loop-value to {_t}
    return {_t}
 
function updateFishPrice(p: player):
    wait 1 tick
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    broadcast "Total: %{_totalprice}%"
    broadcast "Fish: %{_fish::*}%"
    set name of slot 31 of {_p}'s current inventory to "&aSell for: &a$&a%{_totalprice}%"
    set line 1 of lore of slot 31 of {_p}'s current inventory to "&bAmount of fish: %{_fishamount}%"
 
function sellFish(p: player, i: item):
    set {_fish::*} to getFish({_p})
    set {_fishamount} to fishAmount({_fish::*})
    set {_totalprice} to getPriceOfFish({_fish::*})
    set {_latestprice} to getLatestPrice({_i})
    if {_latestprice} = {_totalprice}:
        if {_totalprice} = 0:
            send "&b[Mr. Boatwright] &cNothing to sell" to {_p}
            stop
        close {_p}'s inventory
        add {_totalprice} to balance of {_p}
        send "&b[Mr. Boatwright] &7You sold all your fish for &a$%{_totalprice}%" to {_p}
    else:
        send "&b[Mr. Boatwright] &cOops something went wrong. ##001 Price Not Matching" to {_p}
        send "&b[Mr. Boatwright] &7Updating Price..." to {_p}
        updateFishPrice({_p})
        send "&b[Mr. Boatwright] &7##001 Pls try again." to {_p}
 
function openfish(p: player):
     open virtual chest with size 4 named "&bMr. Boatwright" to {_p}
     format gui slot 27, 28, 29, 30, 32, 33, 34 and 35 of {_p} with green stained glass pane named "" to do nothing
     format gui slot 31 of {_p} with diamond to run function sellFish({_p}, gui-clicked-item)
     updateFishPrice({_p})
 
on InventoryClickEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())
 
on InventoryDragEvent:
    if "%event.getView().getTitle()%" = "&bMr. Boatwright":
        updateFishPrice(event.getWhoClicked())
 
on right click on entity:
     if name of clicked entity contains "&bMr. Boatwright":
         openfish(player)
 
Status
Not open for further replies.