Help Needed for Plugin Development

Hello everyone,

I hope this message finds you well. I’m reaching out to the community, especially @Ryan, because I’ve been trying to create a plugin that would allow us to split “Gold Coin 1 (B)” into stacks of 1 and then sell those units to the NPC. Unfortunately, I have no programming experience and I’m not sure how to go about it. So far, nothing has worked, and I’m looking for some guidance.

Here’s the closest we’ve come to achieving this:

Click to expand code
from phBot import *
import QtBind
from time import sleep
import struct

# Plugin details
pName = 'StackSplitter'
gui = QtBind.init(__name__, pName)

# GUI Elements
lblInstruction = QtBind.createLabel(gui, 'Enter the amount to split (max 10000):', 20, 20)
tbxAmount = QtBind.createLineEdit(gui, "", 20, 50, 100, 20)
btnSplit = QtBind.createButton(gui, 'btnSplit_clicked', 'Split', 20, 80)

def btnSplit_clicked():
    try:
        amount_to_split = int(QtBind.text(gui, tbxAmount))
        if amount_to_split <= 0 or amount_to_split > 10000:
            log("Please enter a valid amount (1-10000).")
            return
        
        # Attempt to split the Gold Coin
        split_gold_coin(amount_to_split)
    except ValueError:
        log("Invalid input. Please enter a numeric value.")

def split_gold_coin(amount):
    item_name = "Gold Coin 1 (B)"
    item_info = get_item_string(item_name)
    
    if not item_info:
        log(f"Item {item_name} not found in the game data.")
        return

    # Check if the item can be split based on max_stack
    if item_info['max_stack'] <= 1:
        log(f"{item_name} cannot be split (max_stack: {item_info['max_stack']}).")
        return

    total_coins = get_item_quantity(item_name)
    if total_coins < amount:
        log(f"Not enough {item_name} in inventory to split. Current amount: {total_coins}.")
        return

    # Debugging inventory before splitting
    log_inventory_state()

    # Loop to split coins
    for _ in range(amount):
        if not is_inventory_full():
            # Send split command
            if not send_split_command(item_info):
                log(f"Failed to split {item_name}.")
                break
            sleep(0.1)  # Delay to prevent spamming commands
        else:
            log("Inventory full, stopping the split process.")
            break

def is_inventory_full():
    inventory = get_inventory()
    occupied_slots = len([item for item in inventory['items'] if item is not None])
    log(f"Occupied slots: {occupied_slots}, Total slots (reported): {inventory['size']}")
    return occupied_slots >= inventory['size']

def send_split_command(item_info):
    item = get_item_by_name(item_info['name'])
    if item:
        try:
            # Injection command to split the item
            inject_joymax(0x7034, struct.pack('I', item['model']), False)
            log(f"Splitting {item_info['name']}.")
            return True
        except Exception as e:
            log(f"Failed to send split command: {e}")
    else:
        log(f"{item_info['name']} not found in inventory.")
    return False

def get_item_by_name(name):
    inventory = get_inventory()
    for item in inventory['items']:
        if item and item['name'] == name:
            return item
    return None

def get_item_quantity(name):
    inventory = get_inventory()
    quantity = sum(item['quantity'] for item in inventory['items'] if item and item['name'] == name)
    return quantity

def log_inventory_state():
    """Logs the state of the inventory for debugging purposes."""
    inventory = get_inventory()
    log("==== INVENTORY STATE ====")
    for slot, item in enumerate(inventory['items']):
        if item:
            log(f"Slot {slot+1}: {item['name']} - Quantity: {item['quantity']} (Model ID: {item['model']})")
        else:
            log(f"Slot {slot+1}: Empty")
    log("=========================")

log('[%s] Loaded' % pName)

I’m really a novice at this, and I’m not sure if what I’m trying to do is even possible. If anyone has advice or can point me in the right direction, I would greatly appreciate it.

FAQ: its a private server.

Thank you in advance for your help!

Best regards,
A total novice

No one can help me?

Did AI write this?

sure, I couldn’t :smiley:

This plugin is for puresro? If yes, this alredy exist, talk to me in private.

I spoke to you privately