Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • stCky: Palidinho is your OpenGL (was it OpenGL?) stuff open source anywhere?
      August 16, 2017, 09:07:22 PM
    • Travas:BUILD THE WALL
      August 15, 2017, 09:28:49 PM
    • Travas: i have ass cancer
      August 15, 2017, 09:23:29 PM
    • stCky: what are the fudge are you tryna ask?
      August 15, 2017, 08:21:35 PM
    • bader: what are the rsps community alive ?
      August 15, 2017, 05:46:16 PM
    • bader: yo guys
      August 15, 2017, 05:46:08 PM
    • Spacehost:[link] Updated our thread :)
      August 15, 2017, 09:40:34 AM
    • Adaro: The client is in Download section at Homepage
      August 15, 2017, 01:09:20 AM
    • FaTe_Of_GoDs: where do i get the client?????????????
      August 14, 2017, 05:23:14 PM
    • stCky: can anyone help me? I cant login to the shoutbox
      August 13, 2017, 05:45:15 PM
    • drubrkletern: appeal denied
      August 13, 2017, 02:35:27 PM
    • King_Trout:[link]
      August 13, 2017, 11:17:12 AM
    • Cole1497: no sorry
      August 13, 2017, 10:27:14 AM
    • ayz: yo can anyone explain something to me
      August 13, 2017, 08:08:51 AM
    • coolking12: Hi
      August 13, 2017, 04:16:06 AM
    • stCky: n+1
      August 11, 2017, 06:09:24 PM
    • PalidinoDH: How many more pages are going to show errors before this dude gets on and fixes shit
      August 11, 2017, 04:57:00 PM
    • stCky: it is made by the wonderful people at jetbrains
      August 10, 2017, 10:00:06 PM
    • Zoravon: what's the difference between that and eclipse?
      August 10, 2017, 05:59:52 PM
    • stCky: use an IDE like IntelliJ or shitclipse
      August 10, 2017, 05:33:01 PM

    Author Topic: [PI] Pack opening  (Read 2018 times)

    0 Members and 1 Guest are viewing this topic.

    Offlinedianhua383

    • Member
    • **
    • Posts: 19
    • Thanks: +0/-0
      • View Profile
    [PI] Pack opening
    « on: December 02, 2015, 08:29:08 PM »
    I made this since I was bored, most PI's have them now adays, This is poorly made, and can be made better using it's own class. but here it is.

    Inside ClickItem.java under
    Quote
          if (itemId != c.playerItems[itemSlot] - 1) {
             return;
          }

    add this

    Quote
          if (itemId == 11877) { //empty vial pack
             if (c.getItems().playerHasItem(11877, 1)) {
                c.getItems().deleteItem(11877,c.getItems().getItemSlot(11877),1);
                c.getItems().addItem(230, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 11879) { //water filled vial pack
             if (c.getItems().playerHasItem(11879, 1)) {
                c.getItems().deleteItem(11879,c.getItems().getItemSlot(11879),1);
                c.getItems().addItem(228, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 11881) { //feather pack
             if (c.getItems().playerHasItem(11881, 1)) {
                c.getItems().deleteItem(11881,c.getItems().getItemSlot(11881),1);
                c.getItems().addItem(314, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 11883) { //bait pack
             if (c.getItems().playerHasItem(11883, 1)) {
                c.getItems().deleteItem(11883,c.getItems().getItemSlot(11883),1);
                c.getItems().addItem(313, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 11885) { //broad arrowhead pack
             if (c.getItems().playerHasItem(11885, 1)) {
                c.getItems().deleteItem(11885,c.getItems().getItemSlot(11885),1);
                c.getItems().addItem(11874, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 11887) { //unfinished broad bolt pack
             if (c.getItems().playerHasItem(11887, 1)) {
                c.getItems().deleteItem(11887,c.getItems().getItemSlot(11887),1);
                c.getItems().addItem(11876, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12728) { //air rune pack
             if (c.getItems().playerHasItem(12728, 1)) {
                c.getItems().deleteItem(12728,c.getItems().getItemSlot(12728),1);
                c.getItems().addItem(556, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12730) { //water rune pack
             if (c.getItems().playerHasItem(12730, 1)) {
                c.getItems().deleteItem(11883,c.getItems().getItemSlot(12730),1);
                c.getItems().addItem(555, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12732) { // earth rune pack
             if (c.getItems().playerHasItem(12732, 1)) {
                c.getItems().deleteItem(12732,c.getItems().getItemSlot(12732),1);
                c.getItems().addItem(557, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12734) { //fire rune pack
             if (c.getItems().playerHasItem(12734, 1)) {
                c.getItems().deleteItem(12734,c.getItems().getItemSlot(12734),1);
                c.getItems().addItem(554, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12736) { //mind rune pack
             if (c.getItems().playerHasItem(12736, 1)) {
                c.getItems().deleteItem(12736,c.getItems().getItemSlot(12736),1);
                c.getItems().addItem(558, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12738) { //chaos rune pack
             if (c.getItems().playerHasItem(12738, 1)) {
                c.getItems().deleteItem(12738,c.getItems().getItemSlot(12738),1);
                c.getItems().addItem(562, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12740) { //bird snare pack
             if (c.getItems().playerHasItem(12740, 1)) {
                c.getItems().deleteItem(12740,c.getItems().getItemSlot(12740),1);
                c.getItems().addItem(10007, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12742) { //box trap pack
             if (c.getItems().playerHasItem(12742, 1)) {
                c.getItems().deleteItem(12742,c.getItems().getItemSlot(12742),1);
                c.getItems().addItem(10009, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12744) { //magic imp box pack
             if (c.getItems().playerHasItem(12744, 1)) {
                c.getItems().deleteItem(12744,c.getItems().getItemSlot(12744),1);
                c.getItems().addItem(10026, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12009) { //soft clay pack
             if (c.getItems().playerHasItem(12009, 1)) {
                c.getItems().deleteItem(12009,c.getItems().getItemSlot(12009),1);
                c.getItems().addItem(1762, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12641) { //amylase pack
             if (c.getItems().playerHasItem(12641, 1)) {
                c.getItems().deleteItem(12641,c.getItems().getItemSlot(12641),1);
                c.getItems().addItem(12640, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12859) { //eye of newt
             if (c.getItems().playerHasItem(12859, 1)) {
                c.getItems().deleteItem(12859,c.getItems().getItemSlot(12859),1);
                c.getItems().addItem(222, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 12857) { //olive oil pack
             if (c.getItems().playerHasItem(12857, 1)) {
                c.getItems().deleteItem(12857,c.getItems().getItemSlot(12857),1);
                c.getItems().addItem(3423, 100);
                c.sendMessage("You have opened a pack");
          }
          }
          if (itemId == 13193) { //bone bolt pack
             if (c.getItems().playerHasItem(13193, 1)) {
                c.getItems().deleteItem(13193,c.getItems().getItemSlot(13193),1);
                c.getItems().addItem(8882, 100);
                c.sendMessage("You have opened a pack");
          }
          }


    « Last Edit: December 02, 2015, 08:31:19 PM by dianhua383 »

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #1 on: December 02, 2015, 10:47:17 PM »
    If you know it's poorly made, you might as well not release it.
    That's a poor excuse for writing bad code.

    You could easily convert this into an enum and minimize the amount of repeated code.


    Offlinedianhua383

    • Member
    • **
    • Posts: 19
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #2 on: December 03, 2015, 04:51:37 PM »
    True, but I have made this a while ago, when I was just learning and was bored. I have made a better method, and im running in on my server atm.


    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #3 on: December 03, 2015, 10:30:11 PM »
    True, but I have made this a while ago, when I was just learning and was bored. I have made a better method, and im running in on my server atm.
    Then release it.

    OfflinePest

    • Member
    • ***
    • Posts: 222
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #4 on: December 09, 2015, 11:22:06 PM »
    If you know it's poorly made, you might as well not release it.
    That's a poor excuse for writing bad code.

    You could easily convert this into an enum and minimize the amount of repeated code.

    OfflineXversial

    • First Time Poster
    • *
    • Posts: 3
    • Thanks: +10/-10
      • View Profile
    Re: [PI] Pack opening
    « Reply #5 on: March 15, 2016, 01:50:38 AM »
    I personally believe `Item Packs` is a really bad name when you have a crate in your inventory, this is reflected in the following code.
    The methods below are not 100% optimal because of the limited information that has been assumed from the original post.
    The methods assume the following information:
    • Each crates' contents, both item and quantity, are statically defined
    • Each crate contains only a single item type
    • The code featured in the original post is valid, and error-free

    Please note: I did not add all of the definitions to the enum. I'm simply assuming you will understand and be able to work with my code right out of the box. (No pun intended)

    Item Crate Definition Enum:
    Code: [Select]
    public enum ItemCrates {
    VIALS(11877, 230, 100),
    VIALS_OF_WATER(11879, 228, 100),
    FEATHERS(11881, 314, 100),
    FISHING_BAIT(11883, 313, 100),
    BROAD_ARROWHEADS(11885, 11874, 100);

    private static Map<Integer, ItemCrates> itemCrateIndex = new HashMap<Integer, ItemCrates>();

    static {
    for (ItemCrates itemCrate : ItemCrates.values())
    itemCrateIndex.put(itemCrate.getCrateID(), itemCrate);
    }

    private int crateID;
    private int contentItemID;
    private int contentQuantity;

    ItemCrates(int crateID, int contentItemID, int contentQuantity) {

    this.crateID = crateID;
    this.contentItemID = contentItemID;
    this.contentQuantity = contentQuantity;
    }

    public static boolean containsIndex(int id){
    return itemCrateIndex.containsKey(id);
    }

    public static ItemCrates getItemID(int id) {
    return itemCrateIndex.get(id);
    }

    public int getCrateID() {
    return crateID;
    }

    public int getContentItemID() {
    return contentItemID;
    }

    public int getContentQuantity() {
    return contentQuantity;
    }
    }

    Use this in-place of the original post's code:
    Code: [Select]
    if(ItemCrates.containsIndex(itemId)){
    ItemCrates itemCrate = ItemCrates.getItemID(itemId);
    if (c.getItems().playerHasItem(itemCrate.getCrateID(), 1)) {
    c.getItems().deleteItem(itemCrate.getCrateID(), c.getItems().getItemSlot(itemCrate.getCrateID()), 1);
    c.getItems().addItem(itemCrate.getContentItemID(), itemCrate.getContentQuantity());
    c.sendMessage("You have opened a pack");
    }
    }

    Offlinelare69

    • Member
    • ****
    • *
    • Posts: 5,321
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #6 on: March 15, 2016, 02:30:58 AM »
    all of the code on this thread is incorrect because none of it takes into account that all of the packs of the same type in your inventory are opened in intervals afterward just by clicking on one

    also "item crate" doesn't make sense since they're packs, not crates...
    hi. check out luna:)

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #7 on: March 15, 2016, 12:13:41 PM »
    all of the code on this thread is incorrect because none of it takes into account that all of the packs of the same type in your inventory are opened in intervals afterward just by clicking on one

    also "item crate" doesn't make sense since they're packs, not crates...
    Unless you're talking specifically how it operates on OSRS.. RS3 has it so when you open a pack, you get two options:
    Open one - does what it says.
    Open all - Again, pretty obvious what it does here.

    "Open all" opens all the packs instantly, why waste X ticks to open Y packs? The player can click faster than the server would open them using an event.
    Should also mention that the items are typically noted, unless they're stackable.

    OfflineCres

    • Member
    • ****
    • Posts: 1,389
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #8 on: March 15, 2016, 02:58:45 PM »
    in all these years nobody came up with the idea to do anything like this in PI?

    Code: Java
    1. HashMap<Integer, ClickItemAction> itemActions = ... ;
    2.  
    3. itemActions.put(11877, new ClickItemAction(){
    4.    @Override
    5.    publicvoid execute(Client c){
    6.       if(c.getItems().playerHasItem(11877, 1)){
    7.          c.getItems().deleteItem(11877,c.getItems().getItemSlot(11877),1);
    8.          c.getItems().addItem(230, 100);
    9.          c.sendMessage("You have opened a pack");
    10.       }
    11.    }
    12. });

    I know scripts are ideally the best for content wise stuff but this is essentially what you would want to be doing if you're hardcoding content anyways
    And I can find myself alone with just my thoughts
    As time crumbles away

    Avenged Sevenfold - Darkness Sourrounding

    Offlinelare69

    • Member
    • ****
    • *
    • Posts: 5,321
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #9 on: March 15, 2016, 05:47:40 PM »
    I know scripts are ideally the best for content wise stuff but this is essentially what you would want to be doing if you're hardcoding content anyways
    yup, people should be using some sort of event driven system to write content. you can even design your event system around an embedded DSL effectively having various "event listeners" within your scripts

    Code: Scala
    1. >>@[ClickItemEvent](11877){(msg, plr)=>
    2.   val items = plr.getItems
    3.  
    4.   items.deleteItem(11877, items.getItemSlot(11877), 1)
    5.   items.addItem(230, 100)
    6.   plr.sendMessage(s"You have opened a ${items.getItemName(11877)}.")
    7. }

    everything becomes much more flexible, and the overhead of interpretation becomes irrelevant because it's only done on startup or when trying to "hot fix"

    the only people that really use PI are beginners or people that don't care about programming in itself, so it's no mystery as to why it as a source and the people using it haven't progressed much in over half a decade
    « Last Edit: March 15, 2016, 05:51:35 PM by lare69 »
    hi. check out luna:)

    OfflineCres

    • Member
    • ****
    • Posts: 1,389
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #10 on: March 15, 2016, 09:00:54 PM »
    yeah true and the 'decent' servers put out there aren't being used anyways.

    just kind of sad

    tbh I think you could cut a gigantic cpu load off of PI servers just with some simple OOP techniques etc

    Player & npc updating in most servers still requires a cycle-through of the entire player/npc list
    Content directly related to packets is still being processed in thousand-line if-statements or switches
    Combat calculations are still done as if listeners were never invented; just imagine how much overhead bulk code this would save:
    Code: Java
    1. publicinterface CombatListener {
    2.  
    3.    //apply accuracy or damage boosts - called during hit registration
    4.    publicvoid preSendHit(Hit hit);
    5.  
    6.    //post hit effects such as freezing or blood heals could be done here, could also be used to track damage such as in pest control
    7.    publicvoid postSendHit(Hit hit);
    8.  
    9.    //right before a hit is received; this is where damage reduction could be handled
    10.    publicvoid preReceiveHit(Hit hit);
    11.  
    12.    //upon receiving a hit; vengeance and ring of recoil could be processed here
    13.    publicvoid postReceiveHit(Hit hit);
    14. }
    The Hit class would contain all relevant data such as attacker accuracy, defender accuracy, max hit, decided hit, hit type, attacker, defender, etc etc
    And I can find myself alone with just my thoughts
    As time crumbles away

    Avenged Sevenfold - Darkness Sourrounding

    Offlinelare69

    • Member
    • ****
    • *
    • Posts: 5,321
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #11 on: March 16, 2016, 12:04:30 PM »
    yeah i didn't really understand awhile ago but now i understand the importance of event driven content, just makes things magnitudes easier
    hi. check out luna:)

    OfflineRuby

    • Member
    • ****
    • *
    • *
    • Posts: 6,834
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #12 on: March 25, 2016, 11:14:00 AM »
    True, but I have made this a while ago, when I was just learning and was bored. I have made a better method, and im running in on my server atm.

    You must have a huge schlong
    Shreddology.

    Toms guilty pleasure: http://i.imgur.com/bmWqw7v.png

    OfflineTree

    • Member
    • ****
    • Posts: 2,638
    • Thanks: +0/-0
      • View Profile
    Re: [PI] Pack opening
    « Reply #13 on: April 07, 2016, 12:07:03 AM »
    Ugly.
    Quote
    <_^_> this community has really collapsed
    <_^_> it is like a shitty version of friendster for washed up nerds

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal