# ---------=====----++--- # Splitting an item? # ---------=====----++--- def handle_split_item(msg, client) return unless zone = client.in_zone_obj incoming_itemid = msg["message"]["itemid"].as_i64 amount = msg["message"]["amount"].as_i tabid = msg["message"]["tabid"].as_i raise "Can't split an item while trading." if client.is_trading # pp incoming_itemid # pp amount if item = client.get_item(incoming_itemid, tabid) c_item_quantity = item[3] raise "You are splitting the item by too much quantity." if amount >= c_item_quantity raise "Invalid split amount, must be 1 or higher." if amount <= 0 raise "The item's quantity must be greater than 1.." if c_item_quantity <= 1 raise "Only Misc item types can be split." if Items[item[1]]["type"] != "Misc" # Remove quantity from the item new_item_quantity = c_item_quantity - amount client.stash[tabid].items[incoming_itemid] = modify_item_tuple(item, 3, new_item_quantity) client.send ({a: 6, q: new_item_quantity, itemid: incoming_itemid}), "ITEMUPDATE" db.exec "update rpg_user_items set q = ? where itemid = ? and user_id = ?", new_item_quantity, incoming_itemid, client.user_id # Now create the new item with amount new_c_item_quantity = amount duped_item_original = item.to_a new_duped_item = item.to_a new_duped_item[3] = new_c_item_quantity new_duped_item[4] = 2 item_query = item_to_mysql_insert_query(new_duped_item, client) result = db.exec(item_query) if result client.stash[tabid].items[result.last_insert_id] = ItemTuple.from(duped_item_original) client.stash[tabid].items[result.last_insert_id] = modify_item_tuple(client.stash[tabid].items[result.last_insert_id], 3, new_c_item_quantity) client.stash[tabid].items[result.last_insert_id] = modify_item_tuple(client.stash[tabid].items[result.last_insert_id], 4, 2) client.send ({a: 7, new_itemid: result.last_insert_id, item: client.stash[tabid].items[result.last_insert_id]}), "ITEMUPDATE" else raise "Error splitting item.. this is real bad.." end else raise "This item is not in your inventory.. it might be in the stash awww shit" end rescue e client.send e.message, "E" end