Thread: [REV-AG] [KT] Simple ItemOnItem Handler

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 [REV-AG] [KT] Simple ItemOnItem Handler 
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    626
    Thanks given
    238
    Thanks received
    113
    Rep Power
    256
    hey guys, if you have itemonitem code looking like this

    Code:
    if ((firstItem == 420 && secondItem == 69) || (firstItem == 69 && secondItem == 420)) {
        // stuff
    } else (...){
        // stuff
    }
    .
    .
    .
    then ive got the code for you: [Only registered and activated users can see links. ]

    Heres a video of the code in action, not groundbreaking cause its just item on item but might as well. Also got a nice vibe in it.


    Features:
    • Simple and quick to create an item combination. No more monstrous if-else blocks!
    • Designed to be as revision-agnostic as possible. Note: You may need to change some stuff to make it work for your source
    • Supports an arbitrary amount of skill level requirements
    • Supports custom requirements to combine items
    • Supports custom behaviour during item combination
    • Supports requiring a tool to be in your inventory
    • Supports more than 2 any-sized stack of items to be taken as ingredients
    • Supports giving experience to an arbitrary amount of skills as an additional reward
    • Supports having separate animations and graphics per combine
    • Easy to write and read builder syntax


    Here's an example of tedious to write code vs my ItemCombination

    Tedious example code (its in kotlin, you should be able to read it anyway its not too different from java, at least in this example)
    Code:
    fun itemOnItem(player: Player, firstItem: Int, secondItem: Int){
        .
        .
        .
        // Base+Right combined with Left
        else if ((firstItem == 11686 && secondItem == 11714) || (firstItem == 11714 && secondItem == 11686)) {
            if (player.inventory.contains(firstItem, 1) && player.inventory.contains(secondItem, 1)) {
                if (player.skills.getLevel(Skills.SMITHING) == 80) {
                    player.inventory.deleteItem(11714, 1)
                    player.inventory.deleteItem(11686, 1)
                    player.inventory.addItem(11690, 1)
                    player.skills.addXp(Skills.SMITHING, 100.toDouble()) //kotlin doesnt have double literal
                }
            }
        // Base+Left combined with Right
        } else if ((firstItem == 11688 && secondItem == 11712) || (firstItem == 11712 && secondItem == 11688)) {
            if (player.inventory.contains(firstItem, 1) && player.inventory.contains(secondItem, 1)) {
                if (player.skills.getLevel(Skills.SMITHING) == 80) {
                    player.inventory.deleteItem(11712, 1)
                    player.inventory.deleteItem(11688, 1)
                    player.inventory.addItem(11690, 1)
                    player.skills.addXp(Skills.SMITHING, 100.toDouble()) //kotlin doesnt have double literal
                }
            }
        // Left+Right combined with Base
        } else if ((firstItem == 11692 && secondItem == 11710) || (firstItem == 11710 && secondItem == 11692)) {
            if (player.inventory.contains(firstItem, 1) && player.inventory.contains(secondItem, 1)) {
                if (player.skills.getLevel(Skills.SMITHING) == 80) {
                    player.inventory.deleteItem(11710, 1)
                    player.inventory.deleteItem(11692, 1)
                    player.inventory.addItem(11690, 1)
                    player.skills.addXp(Skills.SMITHING, 100.toDouble()) //kotlin doesnt have double literal
                }
            }
        }
    }
    and here is my ItemCombination
    Code:
    // Godsword blade
    ItemCombination {
        combinator(Item(11686), Item(11714))
        combinator(Item(11688), Item(11712))
        combinator(Item(11692), Item(11710))
        combined(Item(11690))
        skillRequirements(Skills.SMITHING to 80)
        experienceRewards(Skills.SMITHING to 100)
        combineMessage = "You combine all of the shards together to form a Godsword Blade"
    }
    Last edited by nbness2; 01-22-2019 at 04:37 AM. Reason: updated 2019/01/21
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables made Easy and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers made Safe, Easy and Powerful - 2019/05/04 UPDATED V2 - [Only registered and activated users can see links. ]
    KT - Utils to make your life easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Registered Member
    Tommeh's Avatar
    Join Date
    Nov 2015
    Age
    20
    Posts
    1,916
    Thanks given
    300
    Thanks received
    917
    Rep Power
    5000
    wouldn't a plugin system be better for things like this rather than handling everything in one class
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Registered Member

    Join Date
    Aug 2012
    Posts
    2,366
    Thanks given
    226
    Thanks received
    401
    Rep Power
    218
    Aye this is pretty neat Cool Thanks for the education
    Reply With Quote  
     

  6. #4  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    626
    Thanks given
    238
    Thanks received
    113
    Rep Power
    256
    Quote Originally Posted by Tommeh View Post
    wouldn't a plugin system be better for things like this rather than handling everything in one class
    probably but im not there yet plus this is more easily understandable at first glance to most people. it does the job, the boilerplate is there, all you need to do is write a quick enum!

    Quote Originally Posted by Guruu View Post
    Aye this is pretty neat Cool Thanks for the education
    any time man
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables made Easy and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers made Safe, Easy and Powerful - 2019/05/04 UPDATED V2 - [Only registered and activated users can see links. ]
    KT - Utils to make your life easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #5  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    626
    Thanks given
    238
    Thanks received
    113
    Rep Power
    256


    Updated my ItemOnItem handler, now looks better and feels better, as well as adds functionality.
    • Same features as before
    • 1/3 LOC for the handler compared to past
    • Custom requirements (example I used was not in pvp zone)
    • Custom functionality (example I used was open bank)
    • You can now choose whether or not to delete the ingredients
    • You can now choose whether or not to give any items as a result of combination
      • You must specify as false in ItemCombination if you want to give no items
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables made Easy and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers made Safe, Easy and Powerful - 2019/05/04 UPDATED V2 - [Only registered and activated users can see links. ]
    KT - Utils to make your life easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. #6  
    Registered Member Brainpower's Avatar
    Join Date
    Jan 2019
    Posts
    50
    Thanks given
    1
    Thanks received
    1
    Rep Power
    11
    Looks alright, any benchmarks on how this performs?
    Reply With Quote  
     

  9. #7  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    626
    Thanks given
    238
    Thanks received
    113
    Rep Power
    256
    Quote Originally Posted by Brainpower View Post
    Looks alright, any benchmarks on how this performs?
    1ms with 100 "people" (on the same machine as the server) doing 1 item on item action every 2 ticks compared to big nested if else chains. performance shouldnt be an issue at all given that server has 600ms to process anything it needs to and typically servers process everything within 100-300ms (mine is currently in the 200-250ms range)

    Thats with an R7 1800X at 4ghz, similar results on a 2970wx and 8700k.

    im sure theres some sort of optimizations to be made regarding hotspot optimization, and maybe some in the bytecode, but I try not to get too deep in to that and write readable code instead
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables made Easy and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers made Safe, Easy and Powerful - 2019/05/04 UPDATED V2 - [Only registered and activated users can see links. ]
    KT - Utils to make your life easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. #8  
    Registered Member Brainpower's Avatar
    Join Date
    Jan 2019
    Posts
    50
    Thanks given
    1
    Thanks received
    1
    Rep Power
    11
    Sounds good, I was just curious as to how it performs compared to the usual code as this looks a lot cleaner.
    Reply With Quote  
     

  11. #9  
    Super Donator

    Tyluur's Avatar
    Join Date
    Jun 2010
    Posts
    3,993
    Thanks given
    1,345
    Thanks received
    1,235
    Rep Power
    564
    this is a nice system, i like this implementation



    slowly becoming a fan of kotlin as time goes by.

    but like someone mentioned before, plugins would be better for this. here's an example of how I did mine via plugins

    [Only registered and activated users can see links. ]

    Quote Originally Posted by Velocity View Post
    i'd love to get called in the middle of the night just to hear an indian voice whisper "the nulls are back friend, how i fix"
    Reply With Quote  
     

  12. Thankful user:


  13. #10  
    nbness2#5894

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    626
    Thanks given
    238
    Thanks received
    113
    Rep Power
    256
    Quote Originally Posted by Tyluur View Post
    this is a nice system, i like this implementation



    slowly becoming a fan of kotlin as time goes by.

    but like someone mentioned before, plugins would be better for this. here's an example of how I did mine via plugins

    Hey, thanks man! Come join the bright side!

    My mind is still a bit boggled when it comes to plugins, but having an actual example like yours does help.
    Is a plugin system as simple to implement as just describing an interface?
    Thats a makes some sense but its still confusing to me because you can define what your plugins do, but how does the rest of the code know to call this plugin for this action?
    KT/JAVA - NBX 637 - [Only registered and activated users can see links. ]!
    KT - Drop tables made Easy and Readable - [Only registered and activated users can see links. ]!
    KT - Item Containers made Safe, Easy and Powerful - 2019/05/04 UPDATED V2 - [Only registered and activated users can see links. ]
    KT - Utils to make your life easier - [Only registered and activated users can see links. ]
    KT - Hopping Islands: From Java to Kotlin - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ] - [Only registered and activated users can see links. ]
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [PI]Simple Teleport Handler[PI]
    By jummppy1 in forum Snippets
    Replies: 19
    Last Post: 09-02-2014, 07:48 PM
  2. Simple ItemOnItem handler.
    By Own4g3 in forum Snippets
    Replies: 15
    Last Post: 10-03-2012, 05:27 PM
  3. ItemOnItem handler
    By Laxika in forum Tutorials
    Replies: 21
    Last Post: 10-11-2008, 11:17 PM
  4. A simple "Command Handler"
    By samuraiblood2 in forum Tutorials
    Replies: 7
    Last Post: 11-24-2007, 11:15 AM
  5. Sweet and simple way to make a handler
    By Harvey in forum Tutorials
    Replies: 24
    Last Post: 10-05-2007, 05:38 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •