Trading System

Discussion in 'Plugin Development' started by CheesyFreezy, Mar 20, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    CheesyFreezy

    Heey developers,

    I'm currently working on a MMORPG plugin which also should have a trading system in it. I've been thinking for hours now on how to make a simple trading system between two players. But I can't get any ideas. So how can I easily do this?

    Just suggestions or ideas on how to make it would be really nice!
     
  2. Offline

    mcdorli

    A cool way would be to first open a chest GUI for both of them, with unmovable placeholders on the last 2 slots, and a ready button, and if both of them pressed the ready button, swap the inventories, and instea dof the 2 placeholders, put an accept and a don't accept button (also, make the inventory unchangeable), and if both presses the accept button, put the items in each others inventory
     
  3. Offline

    CheesyFreezy

    Thank you for the reply, but I just found a way on how to make it. Everything works just great, but there is just one problem. When one of the two players closes the trading window the other player will still have the trading window open. How am I supposed to make that when one player closes the window it'll do the same for the other player?
     
  4. Offline

    mcdorli

    You can force the window closing, by doing Player#closeInventory()
    Listen for InventoryCloseEvent, and if the player is one of the players in the current trade, then close the other player's window too,
     
  5. Offline

    CheesyFreezy

    I did this, this worked all fine. But again, there was a problem. When doing it this way the server would lag for about 15 seconds and after those 15 seconds the inventory of the other player would close.
     
  6. Offline

    CheesyFreezy

  7. Offline

    Lordloss

    That sounds very very bad. Please post your code.
     
  8. Offline

    mcdorli

    Do you have loops, recursive methods or anything in that code?
     
  9. Offline

    Desle

    what if you removed the inventory? would that not make them close the window?
     
  10. Offline

    CheesyFreezy

    Don't have the code anymore with the Player#closeInventory on the PlayerCloseInventoryEvent. But when trying to do this the server laggs for a few seconds and after this delay the inventory does close. But the delay is really annoying for the players.


    I don't have any loops in the trade closing.


    What do you mean with 'remove' the inventory?
     
  11. Offline

    Gonmarte

    If you wanna help, just post your code.
     
  12. Offline

    Desle

    Don't you create a custom inventory for both of the players trading? not sure if you can remove that inventory but if you can, wouldn't that close it for them?
     
  13. Offline

    mythbusterma

    @CheesyFreezy

    Make sure you don't use the click event code to close the inventory, as per the documentation:

    [​IMG]
     
Thread Status:
Not open for further replies.

Share This Page