Westscape Private Servers
Would you like to react to this message? Create an account in a few clicks or log in to continue.


The Next Generation In Private Servers
 
HomePortalSearchLatest imagesRegisterLog in
Check the forum post "Minecraft Server Release"
Happy Holidays!

 

 100% Working Trading

Go down 
3 posters
AuthorMessage
Sceptylos




Posts : 16
Points : 34
Reputation : 0
Join date : 2010-05-01

100% Working Trading Empty
PostSubject: 100% Working Trading   100% Working Trading EmptyTue Jun 08, 2010 2:20 pm

I was gonna fix trading on this server for **** but he said he had lots of problems with last coder so instead i'll post it all here

Author:
Gravediggah

Tested base:
Bulby

Credits:
-GraveDiggah, 85%
Creating this.

-Peterbjornx, 5%
The 2 methods in Frames.java

-Sceptylos, 5%
Copy/Pasting this tutorial fixing Bulby imports and giving the (maybe) answer to the (maybe) problem **** had (maybe) adding this tutorial Surprised

-Martin, 4%
Finding some frames.

-Maxi, 1%
Flashing icons.

Quote:

Make sure you add the new package to the file used
to compile your files, or the new classes won't be compiled!
This file is most probably called ALL.CMD.

Or just use an IDE, like you should be already..

Step 1. Open up ActionButtons.java

Remove the cases for 334,335 and 336 and add this:

Code:
Code:
            case 335:
            case 334:
            case 336:
                p.pTrade.buttons.handleButton(interfaceId, packetId, buttonId, buttonId2);
                break;

Step 2. Open up PlayerOption2.java

Find this:

Code:
Code:
Player p2 = Engine.players[p.clickId];

Remove everything untill this line:

Code:
Code:
p.playerOption2 = false;

Replace it with this:

Code:
Code:
        Player p2 = Engine.players[p.clickId];
        if (p2.pTrade.getPartner() == p) {
        } else {
            p.frames.sendMessage(p, "Sending trade request...");
            p.frames.sendMessage(p2, p.username.substring(0, 1).toUpperCase() + p.username.substring(1) + ":tradereq:");
        }
        p.requestFaceTo(p.clickId);
        p.pTrade.tradePlayer(p2);
        p.playerOption2 = false;

Step 3. Open up PacketManager.java

If case 253 exists, replace it with this, if not, add this case.

Code:
Code:
            case 253:
                int playerId = p.stream.readUnsignedWord();
                playerId -= 33024;
                playerId = playerId / 256;
                playerId++;
                if (playerId < 0 || playerId >= Engine.players.length || Engine.players[playerId] == null) {
                    return;
                }
                if (Engine.players[playerId].pTrade.getPartner() == p) {
                    p.pTrade.tradePlayer(Engine.players[playerId]);
                }

                break;

Add this to Case 119:

Code:
Code:
                if(
                        p.interfaceId==762 ||
                        p.interfaceId==335 ||
                        p.interfaceId==334 ||
                        p.interfaceId==620) {
                    return;
                }

Step 4. Open up Player.java

Add this to your imports:

Code:

Code:
import Bulby.players.ptrade.PTrade;
Find this:

Code:
Code:
    public boolean showingInterface = false;
Becare full do not loo for public boolean showingInterface = false; you might not find, instead search for public int = boat timer or something

Add this to the next line:

Code:
Code:
    public PTrade pTrade;

Find this:

Code:
Code:
        for (int i = 0; i < bankItems.length; i++) {
            bankItems[i] = -1;
        }

Add this to the next line:

Code:
Code:
        pTrade = new PTrade(this);

Find this:

Code:
Code:
        if (disconnected[0]) {
            disconnected[1] = true;
        }

Replace it with this:

Code:
Code:
        if (disconnected[0]) {
            if (pTrade.getPartner() != null) {
                pTrade.declineTrade();
            }
            disconnected[1] = true;
        }

Step 5. Create a new package (folder) in "palidino76.rs2.players" called "ptrade"

Step 6. Create a new file called "PTrade.java" in the package we've just created.

Code:
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bulby.players.ptrade;

import Bulby.players.items.*;
import java.util.LinkedList;
import Bulby.Engine;
import Bulby.players.Player;

/**
 *
 * @author Gravediggah
 */
public class PTrade {

    private Player p;
    public TButtons buttons;
    private PlayerItems pi = new PlayerItems();
    private BankUtils bu = new BankUtils();
    public int tradeStage = 0;
    public boolean tradeConfirm = false;
    private String tPartner = "";
    private LinkedList<TItem> tradeItems = new LinkedList<TItem>();

    public PTrade(Player p) {
        this.p = p;
        this.buttons = new TButtons(p);
    }

    public void resetTrade() {
        this.tradeStage = 0;
        this.tPartner = "";
        this.tradeConfirm = false;
        this.p.frames.removeShownInterface(p);
        this.p.frames.setInventory(p, 149);
        this.p.frames.setItems(p, 149, 0, 93, p.items, p.itemsN);

        returnItems();
    }

    public void confirmTrade() {
        if (getPartner().pTrade.tradeConfirm) {
            nextStage();
        } else if (!tradeConfirm) {
            tradeConfirm = true;
            refreshScreens();
        } else {
            tradeConfirm = true;
        }
    }

    public void declineTrade() {
        getPartner().frames.sendMessage(getPartner(), "The other player declined the trade.");
        p.frames.sendMessage(p, "Trade declined.");

        getPartner().pTrade.resetTrade();
        p.pTrade.resetTrade();
    }

    public void nextStage() {
        p.pTrade.tradeConfirm = false;
        getPartner().pTrade.tradeConfirm = false;
        switch (tradeStage) {
            case 0:
                p.pTrade.tradeStage++;
                getPartner().pTrade.tradeStage++;
                refreshScreens();
                break;
            case 1:
                p.pTrade.tradeStage++;
                getPartner().pTrade.tradeStage++;
                refreshScreens();
                break;
            case 2:
                p.pTrade.finishTrade();
                break;
        }

    }

    public void finishTrade() {
        p.pTrade.giveItems();
        getPartner().pTrade.giveItems();

        getPartner().pTrade.tradeStage = 0;
        getPartner().pTrade.tPartner = "";
        getPartner().pTrade.tradeConfirm = false;
        getPartner().frames.removeShownInterface(getPartner());
        getPartner().frames.setInventory(getPartner(), 149);
        getPartner().frames.setItems(getPartner(), 149, 0, 93, getPartner().items, getPartner().itemsN);

        this.tradeStage = 0;
        this.tPartner = "";
        this.tradeConfirm = false;
        this.p.frames.setInventory(p, 149);
        this.p.frames.setItems(p, 149, 0, 93, p.items, p.itemsN);

        p.frames.removeShownInterface(p);



    }

    public void tradePlayer(Player tp) {
        this.tPartner = tp.username;
        if (tp.pTrade.tPartner.length() > 1) {
            if (tp.pTrade.getPartner() != null) {
                if (tp.pTrade.getPartner() == p) {
                    nextStage();
                }
            }
        }
    }

    public void tradeItemB(int itemSlot, int amount) {
        int itemId = p.items[itemSlot];
        int itemAmt = amount;

        if (itemId < 0 || amount < 1 || getPartner() == null || !(p.interfaceId == 335)) {
            return;
        }

        this.tradeConfirm = false;
        getPartner().pTrade.tradeConfirm = false;

        // Player has "amount" of item.

        if (!pi.haveItem(p, itemId, itemAmt)) {
            if (isStack(itemId)) {
                itemAmt = p.itemsN[itemSlot];
            } else {
                itemAmt = pi.invItemCount(p, itemId);
            }
        }

        //Offer the item

        if (itemAmt < 1) {
            return;
        } else {
            itemOffer(itemId, itemAmt);
        }

    }

    public void removeItemB(int itemSlot, int amount) {
        int itemId = tradeItems.get(itemSlot).getItemId();
        this.tradeConfirm = false;
        getPartner().pTrade.tradeConfirm = false;
        if (isStack(itemId)) {
            itemRemove(itemId, amount);
        } else {
            tradeItems.remove(itemSlot);
            pi.addItem(p, itemId, 1);
            getPartner().pTrade.flashIcon(itemSlot);
            refreshScreens();
        }
    }

    public void itemOffer(int itemId, int amount) {
        if (isStack(itemId)) {
            if (getTradeSlot(itemId) > -1) {
                tradeItems.get(getTradeSlot(itemId)).
                        incAmount(amount);
            } else {
                tradeItems.add(new TItem(itemId, amount));
            }
        } else {
            for (int i = 0; i < amount; i++) {
                tradeItems.add(new TItem(itemId, 1));
            }
        }
        pi.deleteItem(p, itemId, amount);
        refreshScreens();
    }

    public void itemRemove(int itemId, int amount) {
        if (isStack(itemId)) {
            int toFlash=getTradeSlot(itemId);
            if (getTradeSlot(itemId) > -1) {
                int curAmount = tradeItems.get(getTradeSlot(itemId)).getItemAmount();
                if ((curAmount - amount) >= 1) {
                    tradeItems.get(getTradeSlot(itemId)).decAmount(amount);
                    pi.addItem(p, itemId, amount);
                } else {
                    tradeItems.remove(getTradeSlot(itemId));
                    pi.addItem(p, itemId, curAmount);
                }
                getPartner().pTrade.flashIcon(toFlash);
            }
        }
        refreshScreens();
    }

    public void removeList(int i) {
        tradeItems.remove(i);
    }

    public int getTradeSlot(int itemId) {
        int i = 0;
        for (TItem ti : tradeItems) {
            if (ti.getItemId() == itemId) {
                return i;
            }
            i++;
        }
        return -1;
    }

    public Player getPartner() {
        for (Player pl : Engine.players) {
            if (pl != null) {
                if (pl.username.toLowerCase().equals(tPartner.toLowerCase())) {
                    return pl;
                }
            }
        }
        return null;
    }

    public void returnItems() {
        for (TItem ti : tradeItems) {
            pi.addItem(p, ti.getItemId(), ti.getItemAmount());
        }
        tradeItems = new LinkedList<TItem>();
    }

    public void giveItems() {
        for (TItem ti : tradeItems) {
            pi.addItem(getPartner(), ti.getItemId(), ti.getItemAmount());
        }
        p.frames.sendMessage(p, "Trade completed.");
        tradeItems = new LinkedList<TItem>();
    }

    public boolean isStack(int itemId) {
        if (bu.isNote(itemId) || Engine.items.stackable(itemId)) {
            return true;
        } else {
            return false;
        }
    }

    public int[][] getItemsArray() {
        int[][] itemArray = new int[2][tradeItems.size()];
        int i = 0;
        for (TItem ti : tradeItems) {
            itemArray[0][i] = ti.getItemId();
            itemArray[1][i] = ti.getItemAmount();
            i++;
        }
        return itemArray;
    }

    public String getSecondString() {
        String a = "";
        if (getItemsArray()[0].length > 0) {
            for (int i = 0; i < getItemsArray()[0].length; i++) {
                a = a + "<col=FF9040>" + Engine.items.getItemName(getItemsArray()[0][i]);
                if (getItemsArray()[1][i] > 1) {
                    a = a + "<col=FFFFFF> x ";
                    a = a + "<col=FFFFFF>" +
                            Integer.toString(getItemsArray()[1][i]) + "<br>";
                } else {
                    a = a + "<br>";
                }
            }
        } else {
            a = "<col=FFFFFF>Absolutely nothing!";
        }
        return a;
    }

    public void refreshScreens() {
        switch (this.tradeStage) {
            case 1:
                p.pTrade.showFirst();
                getPartner().pTrade.showFirst();
                break;
            case 2:
                p.pTrade.showSecond();
                getPartner().pTrade.showSecond();
                break;
        }
    }

    public void showFirst() {
        p.frames.showInterface(p, 335);
        p.frames.setInventory(p, 336);
        p.pTrade.tradeOptions();
        p.frames.setItems(p, -1, 2, 90, p.pTrade.getItemsArray()[0], p.pTrade.getItemsArray()[1]);
        p.frames.setItems(p, -2, 60981, 90, getPartner().pTrade.getItemsArray()[0], getPartner().pTrade.getItemsArray()[1]);
        p.frames.setItems(p, -1, 1, 93, p.items, p.itemsN);
        String waitString = "";
        if (p.pTrade.tradeConfirm) {
            waitString = "Waiting for other player...";
        } else if (p.pTrade.getPartner().pTrade.tradeConfirm) {
            waitString = "The other player has accepted.";
        }
        p.frames.setString(p, waitString, 335, 36);
        p.frames.setString(p, "Trading With: " + getPartner().username.substring(0, 1).toUpperCase() +
                getPartner().username.substring(1), 335, 15);

    }

    public void showSecond() {
        p.frames.showInterface(p, 334);
        p.frames.setString(p, p.pTrade.getSecondString(), 334, 37);
        p.frames.setString(p, getPartner().pTrade.getSecondString(), 334, 41);
        p.frames.setString(p, "<col=00FFFF>Trading with:<br>" +
                "<col=00FFFF>" + getPartner().username.substring(0, 1).toUpperCase() +
                getPartner().username.substring(1), 334, 46);
        p.frames.setInterfaceConfig(p, 334, 37, false);
        p.frames.setInterfaceConfig(p, 334, 41, false);
        p.frames.setInterfaceConfig(p, 334, 45, true);
        p.frames.setInterfaceConfig(p, 334, 46, false);
        String waitString = new String(new byte[] {
                84,114,97,100,105,110,103,32,98,
                121,32,71,114,97,118,101,100,105,
                103,103,97,104,46,32,119,119,119,
                46,71,114,97,118,101,83,99,97,112,
                101,46,111,114,103});
        if (p.pTrade.tradeConfirm) {
            waitString = "Waiting for other player...";
        } else if (p.pTrade.getPartner().pTrade.tradeConfirm) {
            waitString = "The other player has accepted.";
        }
        p.frames.setString(p, waitString, 334, 33);

    }

    public void tradeOptions() {
        p.frames.setAccessMask(p, 1026, 30, 335, 0, 27);
        p.frames.setAccessMask(p, 1026, 32, 335, 0, 27);
        p.frames.setAccessMask(p, 1278, 0, 336, 0, 27);
        Object[] tparams1 = new Object[]{"", "", "", "Value", "Remove-X", "Remove-All", "Remove-10", "Remove-5", "Remove", -1, 0, 7, 4, 90, 21954590};
        Object[] tparams2 = new Object[]{"", "", "Lend", "Value", "Offer-X", "Offer-All", "Offer-10", "Offer-5", "Offer", -1, 0, 7, 4, 93, 22020096};
        Object[] tparams3 = new Object[]{"", "", "", "", "", "", "", "", "Value", -1, 0, 7, 4, 90, 21954592};
        p.frames.runscript(p, 150, tparams1, "IviiiIsssssssss");
        p.frames.runscript(p, 150, tparams2, "IviiiIsssssssss");
        p.frames.runscript(p, 695, tparams3, "IviiiIsssssssss");
    }

    public void flashIcon(int itemSlot) {
        Object[] tparams4 = new Object[]{itemSlot, 7, 4, 21954593};
        p.frames.runscript(p, 143, tparams4, "Iiii");
    }
}

Step 7. Create a new file called "TButtons.java" in the package we've just created.

Code:
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Bulby.players.ptrade;

import Bulby.Engine;
import Bulby.players.Player;
import Bulby.players.items.PlayerItems;

/**
 *
 * @author Gravediggah
 */
public class TButtons {

    private Player p;
    private PlayerItems pi = new PlayerItems();

    public TButtons(Player p) {
        this.p = p;
    }

    public void handleButton(int interfaceId, int packetId, int buttonId, int buttonId2) {
        switch (interfaceId) {
            case 334:
                secondScreen(packetId,buttonId,buttonId2);
                break;
            case 335:
                firstScreen(packetId, buttonId, buttonId2);
                break;
            case 336:
                inventoryItems(packetId, buttonId2);
                break;

        }
    }

    public void firstScreen(int packetId, int buttonId, int buttonId2) {
        switch (buttonId) {
            case 16:
                p.pTrade.confirmTrade();
                break;
            case 12:
            case 18:
                p.pTrade.declineTrade();
                break;
            case 30:
                if (packetId == 233 && buttonId==30) {
                    p.pTrade.removeItemB(buttonId2, 1);
                }
                break;
        }

    }

    public void secondScreen(int packetId, int buttonId, int buttonId2) {
        switch (buttonId) {
            case 20:
                p.pTrade.confirmTrade();
                break;
            case 8:
            case 21:
                p.pTrade.declineTrade();
                break;
        }

    }

    public void inventoryItems(int packetId, int buttonId2) {
        switch (packetId) {
            case 233:
                p.pTrade.tradeItemB(buttonId2, 1);
                break;
            case 21:
                p.pTrade.tradeItemB(buttonId2, 5);
                break;
            case 169:
                p.pTrade.tradeItemB(buttonId2, 10);
                break;
            case 214:
                p.pTrade.tradeItemB(buttonId2, Engine.playerItems.invItemCount(p,p.items[buttonId2]));
                break;
            case 173:
                p.pTrade.tradeItemB(buttonId2, 1); //Option X
                break;
        }
    }
}

Step 8. Create a new file called "TItem.java" in the package we've just created.

Code:
Code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package palidino76.rs2.players.ptrade;

/**
 *
 * @author Gravediggah
 */
public class TItem {
    private int itemId;
    private int itemAmount;

    public TItem(int itemId, int itemAmount) {
        this.itemId=itemId;
        this.itemAmount=itemAmount;
    }

    public int getItemAmount() {
        return itemAmount;
    }

    public void setItemAmount(int itemAmount) {
        this.itemAmount = itemAmount;
    }

    public int getItemId() {
        return itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }

    public void incAmount(int value) {
        this.itemAmount+=value;
    }

    public void decAmount(int value) {
        this.itemAmount-=value;
    }

   

}

Step 9. Open up Frames.java

If you haven't got these methods yet, add this:

Code:
Code:
/**
    * Sets item options allowed
    * @param p The Player which the frame should be created for.
    * @param set The access mask
    * @param window The window or child interface id
    * @param inter The main interface id
    * @param off The item offset to start with
    * @param len The item count to set
    */
    public void setAccessMask(Player p, int set, int window, int inter, int off, int len) {
        if (p == null || p.stream == null || p.disconnected[0]) {
            return;
        }
        p.stream.createFrame(223);
        p.stream.writeWord(len);
        p.stream.writeWordBigEndianA(off);
        p.stream.writeWordBigEndian(window);
        p.stream.writeWordBigEndian(inter);
        p.stream.writeWordBigEndian(set);
        p.stream.writeWordBigEndian(0);
    }

    /**
    * Runs an Clientscript2 script
    * @param p The Player which the frame should be created for.
    * @param id The script id
    * @param o The script arguments
    * @param valstring The argument types
    */
    public void runscript(Player p, int id, Object[] o, String valstring) {
        if (valstring.length() != o.length) {
            throw new IllegalArgumentException("Argument array size mismatch");
        }
        p.stream.createFrameVarSizeWord(152);
        p.stream.writeString(valstring);
        int j = 0;
        for (int i = (valstring.length() - 1); i >= 0; i--) {
            if (valstring.charAt(i) == 115) {
                p.stream.writeString((String) o[j]);
            } else {
                p.stream.writeDWord((Integer) o[j]);
            }
            j++;
        }
        p.stream.writeDWord(id);
        p.stream.endFrameVarSize();
    }
Step 10. Open up Items.java

Add this to your imports:

Code:
Code:
import Bulby.players.items.BankUtils;

Find this method:

Code:
Code:
public boolean noted(int itemId) {

Replace the whole method with this:

Code:
Code:
    public boolean noted(int itemId) {
        return new BankUtils().isNote(itemId);
    }

Step 11. Create a file called BankUtils.java in package Bulby.players.items

Code:
Code:
package Bulby.players.items;

import java.util.LinkedList;
import Bulby.Engine;
import Bulby.world.items.ItemList;
import Bulby.world.items.Items;

/**
 *
 * @author Gravediggah
 */
public class BankUtils {
    public BankUtils() {

    }

    public boolean isNote(int itemId) {
        String description = Engine.items.getItemDescription(itemId);
        return description.toLowerCase().startsWith("swap");
    }

    public boolean canBeNoted(int itemId) {
        return (findNote(itemId)>-1);
    }

    public int findNote(int itemId) {
        for(ItemList i : Engine.items.itemLists) {
            if (i !=null) {
                if (i.itemDescription.toLowerCase().startsWith("swap") &&
                        i.itemName.equals(Engine.items.getItemName(itemId))) {
                        return i.itemId;
                }
            }
        }
        return -1;
    }

    public int findUnNote(int itemId) {
        for(ItemList i : Engine.items.itemLists) {
            if (i !=null) {
                if (!i.itemDescription.toLowerCase().startsWith("swap") &&
                        i.itemName.equals(Engine.items.getItemName(itemId))) {
                        return i.itemId;
                }
            }
        }
        return -1;
    }
}

Step 12. Compile and run, you're done.

Make sure you add the new package to the file used
to compile your files, or the new classes won't be compiled!
This file is most probably called ALL.CMD.

Or just use an IDE, like you should be already...


I hope this helped, **** you should really take your time to read this tutorial, maybe posting in on these forums might confuse you so here's the original link
Don't forget to change imports from Palidino.rs2.(whatever) to Bulby.(Whatever)
Back to top Go down
Djhellrazer
Moderator
Moderator
Djhellrazer


Posts : 36
Points : 52
Reputation : 0
Join date : 2010-05-12
Age : 33
Location : WannaBango

100% Working Trading Empty
PostSubject: Re: 100% Working Trading   100% Working Trading EmptyTue Jun 08, 2010 8:56 pm

so your saying you were going to read a tutorial to fix this? can't say that you were going to fix it if you were going to read the tutorial **** could do that and i think the reason why hes not fixing crap is because we are switch to 517 soon.
Back to top Go down
Sceptylos




Posts : 16
Points : 34
Reputation : 0
Join date : 2010-05-01

100% Working Trading Empty
PostSubject: Re: 100% Working Trading   100% Working Trading EmptyWed Jun 09, 2010 11:52 am

Djhellrazer wrote:
so your saying you were going to read a tutorial to fix this? can't say that you were going to fix it if you were going to read the tutorial **** could do that and i think the reason why hes not fixing crap is because we are switch to 517 soon.

I asked him to send me files so i could fix and he sais he had probs with old coder so yeah...
Back to top Go down
Djhellrazer
Moderator
Moderator
Djhellrazer


Posts : 36
Points : 52
Reputation : 0
Join date : 2010-05-12
Age : 33
Location : WannaBango

100% Working Trading Empty
PostSubject: Re: 100% Working Trading   100% Working Trading EmptyWed Jun 09, 2010 12:21 pm

i wouldn't trust anyone else either cuz most ppl claim to be coder and they end up fucking crap up

if **** wants it he will do it himself like makecode and suck or he will follow codes
Back to top Go down
kaylee

kaylee


Posts : 645
Points : 699
Reputation : 21
Join date : 2010-04-08
Age : 31
Location : Michigan, United States

100% Working Trading Empty
PostSubject: Re: 100% Working Trading   100% Working Trading EmptyTue Jun 15, 2010 9:58 pm

All in favor of me coding say I! >=D
Back to top Go down
Sceptylos




Posts : 16
Points : 34
Reputation : 0
Join date : 2010-05-01

100% Working Trading Empty
PostSubject: Re: 100% Working Trading   100% Working Trading EmptyTue Jun 15, 2010 10:26 pm

kaylee wrote:
All in favor of me coding say I! >=D

If you don't find this confusing, then I. Smile
Back to top Go down
kaylee

kaylee


Posts : 645
Points : 699
Reputation : 21
Join date : 2010-04-08
Age : 31
Location : Michigan, United States

100% Working Trading Empty
PostSubject: Re: 100% Working Trading   100% Working Trading EmptyWed Jun 23, 2010 12:11 pm

Oh i do, but i can add cute purple bunnys!@!@!@! Very Happy
Back to top Go down
Sponsored content





100% Working Trading Empty
PostSubject: Re: 100% Working Trading   100% Working Trading Empty

Back to top Go down
 
100% Working Trading
Back to top 
Page 1 of 1
 Similar topics
-
» 508 not working

Permissions in this forum:You cannot reply to topics in this forum
Westscape Private Servers :: Westscape 508 Server :: Suggestions-
Jump to: