[Share] DragonSource Item GM command v1.0

Results 1 to 8 of 8
  1. #1
    Alpha Member GlaphanKing is offline
    MemberRank
    Sep 2008 Join Date
    World of MorrowLocation
    2,594Posts

    [Share] DragonSource Item GM command v1.0

    I noticed BBim and Adidishen were having trouble (adi might have gotten this to work already) getting items to correctly appear in the inventory.

    The problem is not that difficult once you figure out the pattern on how to do this. First let me show you the GM command in its natural habitat.

    Code:
    if(_stricmp(command,"item")==0){
                int itemid = strval(strtok_s(NULL, " ",&next_token));
                int amount = strval(strtok_s(NULL, " ",&next_token));
                PlayerInventory* inventory = player->inv;
                ItemBank *itembank = ItemBanks::getItemBankById(itemid);
                Item* item = new Item();
                item->setItemId(itembank->id);
                // check to see whether the amount is greater than the max amount in the itembank
                if(amount > itembank->maxItems)
                {
                    item->setAmount(itembank->maxItems);
                }
                else
                {
                    item->setAmount(amount);
                }
                
                item->setSlot(inventory->getFirstUnunsedSlot());
                
                int usedSlot = item->getSlot();
    
                inventory->addUsedSlot(usedSlot);
                inventory->removeUnusedSlot(usedSlot);
    
                inventory->addItem(item);
    
                int newSlot = item->getSlot();
    
                InventoryPacket::addItem(player, item, newSlot);
                
                return true;
            }
    I haven't yet added in the mods for the items so its more of a item and amount command thus far.

    So lemme break it down for you.

    Input the following code in the chat box: !item 85 1

    Code:
    int itemid = strval(strtok_s(NULL, " ",&next_token));

    this is the id of the item.


    Code:
    int amount = strval(strtok_s(NULL, " ",&next_token));


    this is the number of items you want.


    Code:
    PlayerInventory* inventory = player->inv;
    call in the player's inventory to work with.
    Code:
    ItemBank *itembank = ItemBanks::getItemBankById(itemid);
    get an item bank from the ID.

    Code:
    Item* item = new Item();
    Make a new item.

    Code:
    item->setItemId(itembank->id);
      // check to see whether the amount is greater than the max amount in the itembank
                if(amount > itembank->maxItems)
                {
                    item->setAmount(itembank->maxItems);
                }
                else
                {
                    item->setAmount(amount);
                }
    set the item id from the itembank. then it checks to see whether you try and beat the system of making more items than needed in the same slot (i,e, 200 swords). If its more than the max amount it sets the max amount to the amount of the item. Its a failsafe against item abuse.

    Code:
     item->setSlot(inventory->getFirstUnunsedSlot());
    This is the crucial part. This returns the first unused slot available.

    Code:
                inventory->addUsedSlot(usedSlot);
                inventory->removeUnusedSlot(usedSlot);
    Ok. Some don't know this but there are two arrays or vectors that hold some vital slot information. UsedSlot array has all the slot numbers in use including equipped slots. UnusedSlot is all the free slots available including equip slots. If you add one, you remove one and vice versa.

    Code:
    inventory->addItem(item);
    This adds the item in the inventory for saving. Its not complete until you send the packet to the client.

    Code:
                int newSlot = item->getSlot();
    
                InventoryPacket::addItem(player, item, newSlot);
    this is the final part of the command. this sends the packet to the client so your item can finally appear. Next I'll post the addItem packet. This is for the InventoryPacket.

    Code:
    void InventoryPacket::addItem(Player* player, Item* item, int slot){
        Packet pak = Packet();
        pak.setPlayer(player);
        pak.addHeader(player, 0x03);            // Add item to inventory command
        pak.addByte(0);
        pak.addInt(-1);//ff ff ff ff 
        if(item->getItemId() == 0)
        {
            pak.addShort(21);
        }
        else
        {
            pak.addShort(item->getItemId());
        }
        pak.addShort(0);
        pak.addInt(0);
        pak.addInt(0);
        pak.addShort(item->getAmount());
        pak.addShort(0);
        pak.addInt(0);
        pak.addInt(0);
        pak.addShort(0);
        pak.addShort(0);
        pak.addInt(0);
        pak.addByte(0);
        pak.addShort(0);
        pak.addShort(0);
        pak.addInt(0);
        pak.addInt(0);
        pak.addBytes("000000000000000000000000000001");
        pak.addByte(slot);
        pak.addShort(1);
    
        pak.completePacket();
        pak.packetSend();
    }
    Thanks to BBim and Adidishen for their POVs and help in the matter. This is just a simple packet which only has a id and a qty.


  2. #2
    Account Upgraded | Title Enabled! BBim is offline
    MemberRank
    Sep 2008 Join Date
    127.0.0.1Location
    1,110Posts

    Re: [Share] DragonSource Item GM command v1.0

    I made it just the item spawn packet, I was going to make it add to items variable server side later but I stopped working on it :\
    After some time I saw that it already have the item spawn packet xD
    I will post at my guide one thing for GM commands, it might help a little, just to save you guys some time :]
    Thanks for this GlaphanKing ;]

  3. #3
    Alpha Member GlaphanKing is offline
    MemberRank
    Sep 2008 Join Date
    World of MorrowLocation
    2,594Posts

    Re: [Share] DragonSource Item GM command v1.0

    You've actually done a lot for the source bbim. Though they were small fixes, those can go a long way in the road to completion.

  4. #4
    Account Upgraded | Title Enabled! x103strike is offline
    MemberRank
    Sep 2008 Join Date
    EarthLocation
    993Posts

    Re: [Share] DragonSource Item GM command v1.0

    as it says " Big things started from small things" XD

    @ Sir Galaph : sir why I cant open the exe XD I can open only the version .05b XD

  5. #5
    Account Upgraded | Title Enabled! Shinija is offline
    MemberRank
    Oct 2007 Join Date
    UKLocation
    684Posts

    Re: [Share] DragonSource Item GM command v1.0

    Hehe thanks i could learn from this

  6. #6
    Account Upgraded | Title Enabled! BBim is offline
    MemberRank
    Sep 2008 Join Date
    127.0.0.1Location
    1,110Posts

    Re: [Share] DragonSource Item GM command v1.0

    Quote Originally Posted by GlaphanKing View Post
    You've actually done a lot for the source bbim. Though they were small fixes, those can go a long way in the road to completion.
    Yeah, I started to work into small things, so I could post it here to people learn from it and help us, didnt work as I wanted thought.
    The update I mentioned was put in place, go check it there ;]

  7. #7
    Rhisis Developer Akitasha is offline
    MemberRank
    Jun 2005 Join Date
    NY, USALocation
    220Posts

    Re: [Share] DragonSource Item GM command v1.0

    Quote Originally Posted by BBim View Post
    Yeah, I started to work into small things, so I could post it here to people learn from it and help us, didnt work as I wanted thought.
    The update I mentioned was put in place, go check it there ;]
    Lol, yeah i noticed not much community contributions, have you taken a stab at the skills?

  8. #8
    Account Upgraded | Title Enabled! kingblazer is offline
    MemberRank
    Sep 2008 Join Date
    282Posts

    Re: [Share] DragonSource Item GM command v1.0

    Quote Originally Posted by x103strike View Post
    as it says " Big things started from small things" XD

    @ Sir Galaph : sir why I cant open the exe XD I can open only the version .05b XD
    you need to edit a few things to make the others work

    aso Akiasha

    sorry i havn contributed much but im trying but ive been grownded for 3 months

    i do my asignments on a laptop the school permitted me but its defective and wipes itself daily
    but i cant get a replacement until the teacherr in charge of it is back from surgery :[

    so im kinda stuck atm but as soon as its worked out il finish my lessons then help out with more knoledge than previus



Advertisement