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.
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)
https://gyazo.com/e6b8b2a7952494152ae2b8fefbdd6cff
 
Guess u replaced the wrong line u needed to replace broadcast "Fish2DATA: %{_p::*}%" ipv total:
[doublepost=1584059139,1584059069][/doublepost]

uhm the line where u give the common herring item
This is the function that will give the fish:

Code:
function fishgive(P: player):
    if {ranfish} is 1:
        set {_var} to random number between 3 and 7.99
        if {_var} is less than 7.99:
            give {_P} a cod named "&7Common Shrimp" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Caught by %{_P}%"
            send "&8[&bFishing&8] &7%{_P}% &7You cought a &7Common &aShrimp" to {_P}
        if {_var} > ({size::fish::%{_P}%} ? 0):
            set {size::fish::%{_P}%} to {_var}
    if {ranfish} is 2:
        set {_var} to random number between 7 and 12.99
        if {_var} is less than 12.99:
            give {_P} a cod named "&7Common Anchovy" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Caught By %{_P}%"
            send "&8[&bFishing&8] &7You cought a &7Common &aAnchovy" to {_P}
        if {_var} > ({size::fish::%{_P}%} ? 0):
            set {size::fish::%{_P}%} to {_var}
    if {ranfish} is 3:
        set {_var} to random number between 12 and 14.99
        if {_var} is less than 14.99:
            give {_P} a cod named "&7Common Croaker" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Caught By %{_P}%"
            send "&8[&bFishing&8] &7You cought a &7Common &aCroaker" to {_P}
        if {_var} > ({size::fish::%{_P}%} ? 0):
            set {size::fish::%{_P}%} to {_var}
    if {ranfish} is 4:
        set {_var} to random number between 10 and 14.99
        if {_var} is less than 14.99:
            give {_P} a cod named "&7Common Crab" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Caught By %{_P}%"
            send "&8[&bFishing&8] &7You cought a &7Common &aCrab" to {_P}
        if {_var} > ({size::fish::%{_P}%} ? 0):
            set {size::fish::%{_P}%} to {_var}
    if {ranfish} is 5:
        set {_var} to random number between 15 and 29.99
        if {_var} is less than 29.99:
            give {_P} a cod named "&7Common Mackerel" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Caught By %{_P}%"
            send "&8[&bFishing&8] &7You cought a &7Common &aMackerel" to {_P}
        if {_var} > ({size::fish::%{_P}%} ? 0):
            set {size::fish::%{_P}%} to {_var}
    if {ranfish} is 6:     #Common Herring    <--------------------------
        set {_var} to random number between 20 and 29.99
        if {_var} is less than 29.99:
            give {_P} a cod named "&7Common Herring" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Caught By %{_P}%"
            send "&8[&bFishing&8] &7You cought a &7Common &aHerring" to {_P}
        if {_var} > ({size::fish::%{_P}%} ? 0):
            set {size::fish::%{_P}%} to {_var}
    if {ranfish} is 7:
        set {_var} to random number between 10 and 29.99
        if {_var} is less than 29.99:
            give {_P} a bread named "&7Common Breadfish" with lore "&8* &aSize: %{_var}%cm" and "&b* &7Caught By %{_P}%"
            send "&8[&bFishing&8] &7You cought a &7Common &aBreadfish" to {_P}
        if {_var} > ({size::fish::%{_P}%} ? 0):
            set {size::fish::%{_P}%} to {_var}
[doublepost=1584059275][/doublepost]Line 37 is the common herring
 
u seen this?
Im sorry, but i dont 100% understand where you are talking about exactly. Is this the part you mean? xD

Code:
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}
 
Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent

function getWorthOfFish(i: item) :: number:
    broadcast "Fish4DATA: %{_i}% %name of {_i}%"
    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:
    broadcast "Fish5DATA: %{_i}% %name of {_i}% %{_s}%"
    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 "FishPriceTrigger"
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value) 0
        set {_p::s} to getSize(loop-value) 23.68
        set {_p::i} to getSizeIncrease(loop-value,{_p::s}) 0
        set {_p::p} to {_p::w} + {_p::i} 0
        set {_p::a} to item amount of loop-value 64
        set {_p::t} to {_p::a} * {_p::p} 0
        add {_p::t} to {_t}
        broadcast "Fish3DATA: %loop-value%"
        broadcast "Fish2DATA: %{_p::w}% %{_p::s}% %{_p::i}% %{_p::p}% %{_p::a}% %{_p::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)
 
Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent

function getWorthOfFish(i: item) :: number:
    broadcast "Fish4DATA: %{_i}% %name of {_i}%"
    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:
    broadcast "Fish5DATA: %{_i}% %name of {_i}% %{_s}%"
    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 "FishPriceTrigger"
    set {_t} to 0
    loop {_i::*}:
        delete {_p::*}
        set {_p::w} to getWorthOfFish(loop-value) 0
        set {_p::s} to getSize(loop-value) 23.68
        set {_p::i} to getSizeIncrease(loop-value,{_p::s}) 0
        set {_p::p} to {_p::w} + {_p::i} 0
        set {_p::a} to item amount of loop-value 64
        set {_p::t} to {_p::a} * {_p::p} 0
        add {_p::t} to {_t}
        broadcast "Fish3DATA: %loop-value%"
        broadcast "Fish2DATA: %{_p::w}% %{_p::s}% %{_p::i}% %{_p::p}% %{_p::a}% %{_p::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)
That gives me 6 errors xD
 
Code:
import:
    org.bukkit.event.inventory.InventoryDragEvent
    org.bukkit.event.inventory.InventoryClickEvent

function getWorthOfFish(i: item) :: number:
    broadcast "Fish4DATA: %{_i}% %name of {_i}%"
    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:
    broadcast "Fish5DATA: %{_i}% %name of {_i}% %{_s}%"
    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 "FishPriceTrigger"
    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 "Fish3DATA: %loop-value%"
        broadcast "Fish2DATA: %{_p::w}% %{_p::s}% %{_p::i}% %{_p::p}% %{_p::a}% %{_p::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)
 

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

function getWorthOfFish(i: item type) :: number:
    broadcast "Fish4DATA: %{_i}% %name of {_i}%"
    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 type, s: number) :: number:
    broadcast "Fish5DATA: %{_i}% %name of {_i}% %{_s}%"
    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 "FishPriceTrigger"
    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 "Fish3DATA: %loop-value%"
        broadcast "Fish2DATA: %{_p::w}% %{_p::s}% %{_p::i}% %{_p::p}% %{_p::a}% %{_p::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 type) :: 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 type):
    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.