1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Script Bad little trading skript - Version 1.0a

Allows GUI trading with other players on the server

  1. Juc70
    Contributors:
    Me, Juc70 and our lord and savior SkUnity docs
    ◆Description
    A skript that allows player's to trade items with a GUI. Should be safe and secure. Player's can initiate trade with a command or shift- double right clicking or clicking the underlined chat message (version 1.0a or newer).

    ◆Screenshots
    [​IMG]
    ⬥ Messages trade skript sends players​
    [​IMG]
    ⬥ LinkTheSink's point of view in a trade​
    [​IMG]
    ⬥ Juc70's point of view in a trade
    [​IMG]
    ⬥ Trade window tool-tipped​
    ◆Add-ons
    Skellet
    SkStuff (Not sure if needed)
    json.sk

    ◆Commands
    /trade [<player>]
    ⬥Description: Allows trading with other players. If player is not defined it only tries to accept a trade instead of sending one.
    ⬥Permission: Available for everyone by default

    ◆Terms of use
    Anyone can use and modify the skript but not publicly distribute it. You may not take credit for the work.

    ◆Coming soon
    ⬥Comment ideas below
    ⬥Possibly configs​


    I made a trading skript after around half a year break from skripting. Half way making the skript, I decided to let anyone wanting use it, so here it is..
    Code (Skript):
    1. # Version 0.1 Made by Creep = Juc70
    2.  
    3. function opengui(for: player, other: player):
    4.    close {_for}'s inventory
    5.    set {tradeready.%{_for}%} to 0
    6.    set {trade.%{_for}%} to {_other}
    7.    set {trading.%{_for}%} to true
    8.    send "&3Opened trade window with %{_other}%"  to {_for}
    9.    open "chest" with 4 rows named "&4%{_for}% and %{_other}%" to {_for}
    10.    set slot 4 of {_for}'s current inventory to gray wool named " &r "
    11.    set slot 13 of {_for}'s current inventory to gray glass pane named " &r "
    12.    set slot 22 of {_for}'s current inventory to green wool named "&rAccept trade"
    13.    set slot 31 of {_for}'s current inventory to red wool named "&rCancel trade"
    14.  
    15. function drawStage(for: player,stage: number):
    16.    if {_stage} is 0:
    17.        set slot 4 of {_for}'s current inventory to gray wool named " &r "
    18.    if {_stage} is 1:
    19.        set slot 4 of {_for}'s current inventory to yellow wool named " &r "
    20.    if {_stage} is 2:
    21.        set slot 4 of {_for}'s current inventory to light green wool named " &r "
    22.  
    23. function drawInventory(for: player,other: player):
    24. #ME
    25.    set {tradeready.%{_for}%} to 0
    26.    set {tradeready.%{_other}%} to 0
    27.    set {_x} to 0
    28.    set {_y} to 0
    29.    loop {tradelist.%{_for}%::*}:
    30.        set slot {_x}+{_y}*9 of {_for}'s current inventory to {tradelist.%{_for}%::%loop-index%}
    31. #       broadcast "&ax%{_x}%y%{_y}% -- %{tradelist.%{_for}%::%loop-index%}%"
    32.        add 1 to {_x}
    33.        if {_x} is more than 3:
    34.            set {_x} to 0
    35.            add 1 to {_y}
    36.    loop (16 - {_x}) - {_y}*4 times:
    37.        set slot {_x}+{_y}*9 of {_for}'s current inventory to air
    38. #       broadcast "&bx%{_x}%y%{_y}%"
    39.        add 1 to {_x}
    40.        if {_x} is more than 3:
    41.            set {_x} to 0
    42.            add 1 to {_y}
    43. #YOU
    44.    set {_x} to 0
    45.    set {_y} to 0
    46.    loop {tradelist.%{_other}%::*}:
    47.        set slot {_x}+5+{_y}*9 of {_for}'s current inventory to {tradelist.%{_other}%::%loop-index%}
    48. #       broadcast "&ax%{_x}+5%y%{_y}% -- %{tradelist.%{_other}%::%loop-index%}%"
    49.        add 1 to {_x}
    50.        if {_x} is more than 3:
    51.            set {_x} to 0
    52.            add 1 to {_y}
    53.    loop (16 - {_x}) - {_y}*4 times:
    54.        set slot {_x}+5+{_y}*9 of {_for}'s current inventory to air
    55. #       broadcast "&bx%{_x}+5%y%{_y}%"
    56.        add 1 to {_x}
    57.        if {_x} is more than 3:
    58.            set {_x} to 0
    59.            add 1 to {_y}
    60.        drawStage({_for},0)
    61.        drawStage({_other},0)
    62.  
    63. function doTrade(for: player,other: player):
    64.    set {trading.%{_for}%} to false
    65.    set {trading.%{_other}%} to false
    66.    send "&3Trade successful with %{_other}%" to {_for}
    67.    loop {tradelist.%{_other}%::*}:
    68.        give {tradelist.%{_other}%::%loop-index%} to {_for}
    69. #       broadcast "%loop-index% - %loop-value%"
    70.    delete {tradelist.%{_other}%::*}
    71.    close {_for}'s inventory
    72.  
    73. command /trade [<player>]:
    74.    trigger:
    75.        if arg-1 is player:
    76.            send "&3You silly ^^" to player
    77.            exit
    78.        if arg-1 is set:
    79.            if {trading.%arg-1%} is not set:
    80.                set {trading.%arg-1%} to false
    81.            if {trading.%arg-1%} is not true:
    82.                if {trade.%player%} is arg-1:
    83.                    if {tradetimer.%player%} was less than 30 seconds ago:
    84.                        opengui(player,{trade.%player%})
    85.                        opengui({trade.%player%},player)
    86.                        delete {tradetimer.%player%}
    87.                        exit
    88.            else:
    89.                send "&cThat person is busy" to player
    90.                exit
    91.            if {trading.%arg-1%} is true:
    92.                send "&cThat person is busy" to player
    93.                exit
    94.            send "&3Sent trade request to %arg-1%"
    95.            send "&3%player's name% wants to trade with you, /trade to accept" to arg-1
    96.            set {trade.%arg-1%} to player
    97.            set {tradetimer.%arg-1%} to now
    98.        else:
    99.            if {trade.%player%} is set:
    100.                if {trading.%{trade.%player%}%} is not true:
    101.                    if {tradetimer.%player%} was less than 30 seconds ago:
    102.                        opengui(player,{trade.%player%})
    103.                        opengui({trade.%player%},player)
    104.                        delete {tradetimer.%player%}
    105.                    else:
    106.                        if {tradetimer.%player%} was less than 1 hour ago:
    107.                            send "&cTrade timed out with %{trade.%player%}%"
    108.                        else:
    109.                            send "&cUsage: &o/trade <player>" to player
    110.                else:
    111.                    send "&cThat person is busy" to player
    112.            else:
    113.                send "&cUsage: &o/trade <player>" to player
    114.  
    115. on inventory click:
    116.    {trading.%player%} is true
    117.    cancel event
    118.    "%clicked action%" is "pickup all"
    119.    if "%clicked inventory%" is "inventory of <none>":
    120.        # TRADE INVENTORY
    121.        if clicked slot is 31:
    122.            close player's inventory
    123.        else if clicked slot is 22:
    124.            if {tradeready.%{trade.%player%}%} is 0:
    125.                set {tradeready.%player%} to 1
    126.                drawStage(player,2)
    127.                drawStage({trade.%player%},1)
    128.            if {tradeready.%{trade.%player%}%} is 1:
    129.                doTrade(player,{trade.%player%})
    130.                doTrade({trade.%player%},player)
    131.        else:
    132.            set {_slt} to clicked slot +1
    133.            while {_slt} is more than 4:
    134.                remove 9 from {_slt}
    135.                if {_slt} is less than 1:
    136.                    exit
    137.            give player clicked item
    138.            remove clicked item from {tradelist.%player%::*}
    139.            set slot clicked slot of player's current inventory to air
    140.            drawInventory(player,{trade.%player%})
    141.            drawInventory({trade.%player%},player)
    142.    else if clicked inventory is player's inventory:
    143.        # PLAYER INVENTORY
    144.        clicked item exists
    145.        clicked item is not air
    146.        if size of {tradelist.%player%::*} is less than 16:
    147.            add clicked item to {tradelist.%player%::*}
    148.            remove clicked item from inventory of player
    149.            drawInventory(player,{trade.%player%})
    150.            drawInventory({trade.%player%},player)
    151.        else:
    152.            send "&cSlots full" to player
    153.  
    154. on inventory close:
    155.    {trading.%player%} is true
    156.    send "&cTrading interrupted" to player
    157.    set {trading.%player%} to false
    158.    if {trading.%{trade.%player%}%} is true:
    159.        close {trade.%player%}'s inventory
    160.    loop {tradelist.%player%::*}:
    161.        give player {tradelist.%player%::%loop-index%}
    162.    delete {tradelist.%player%::*}

    [​IMG]
    [​IMG]

Recent Updates

  1. Standardised version names, Woohoo!
  2. Hotfix 0.3
  3. Update 0.2
  • About Us

    Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.
  • Support skUnity

    The staff team works very hard to make sure the community is running its best. This means constantly performing upgrades to systems and other features. This does cost a bit of money to keep doing. Donating to skUnity would allow the server to keep running smoothly for years to come!

    Support Us!
  • Join Our Discord

    Discord is an all-in-one voice and text chat for gamers that’s free, secure, and works on both your desktop and phone.