Tomm0017 / rsmod

New repository: https://github.com/rsmod/rsmod
https://github.com/rsmod/rsmod
Apache License 2.0
125 stars 101 forks source link

Prevent picking up a clue scroll item if player already has one of same tier #135

Closed JackRayfish closed 5 years ago

JackRayfish commented 5 years ago
on_global_item_pickup {
    if (player.inventory.contains(Items.CLUE_SCROLL_BEGINNER) || player.bank.contains(Items.CLUE_SCROLL_BEGINNER)) {
        val inventoryTransaction = player.attr[GROUNDITEM_PICKUP_TRANSACTION]?.get() ?: return@on_global_item_pickup
        val transactionItem = inventoryTransaction.items.first()
        if (transactionItem.item.id == Items.CLUE_SCROLL_BEGINNER) {
            player.message("You already have a clue scroll of this tier.")
            inventoryTransaction.revert(player.inventory)
        }
    }
}

Current Behavior

Using the above code, when picking up a beginner clue scroll with one already in your inventory or bank, the ground item will despawn and the player message will be sent and the transaction reverted.

Expected Behavior

The ground item should not despawn, it should stay on the ground allowing the player to drop their current clue scroll and pick up the other.

Steps to Reproduce the Problem

  1. Add code snippet above
  2. Spawn two beginner clue scrolls
  3. Drop one and pick it back up with the other still in your inventory