[Tutorial] Auto-Equip Helmet or Armor

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    failed in javascript ItzFdr is offline
    MemberRank
    May 2013 Join Date
    BrasilLocation
    293Posts

    [Tutorial] Auto-Equip Helmet or Armor





    WarZ_Server.sln
    Search for it:

    Code:
    bool obj_ServerPlayer::BackpackAddItem(const wiInventoryItem& wi1)
    Note: Replace 'all function for this'

    Code:
    bool obj_ServerPlayer::BackpackAddItem(const wiInventoryItem& wi1)
    {
        // SPECIAL case - GOLD item
        if(wi1.itemID == 'GOLD')
        {
            r3dOutToLog("%s BackpackAddItem %d GameDollars\n", userName, wi1.quantity); CLOG_INDENT;
    
            profile_.ProfileData.GameDollars += wi1.quantity;
    
    
            // report to client
            PKT_S2C_BackpackAddNew_s n;
            n.SlotTo = 0;
            n.Item   = wi1;
            gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
            return true;
        }
    
    
        const WeaponAttachmentConfig* cfg = g_pWeaponArmory->getAttachmentConfig(wi1.itemID);
    
    
        //r3dOutToLog("%s BackpackAddItem %dx%d\n", userName, wi1.itemID, wi1.quantity); CLOG_INDENT;
        r3d_assert(wi1.itemID > 0);
        //r3d_assert(wi1.quantity > 0);
        
        const BaseItemConfig* itemCfg = g_pWeaponArmory->getConfig(wi1.itemID);
        if(!itemCfg) 
        {
            gServerLogic.LogCheat(peerId_, PKT_S2C_CheatWarning_s::CHEAT_Data, false, "BackpackAddItem",
                "%d", wi1.itemID);
            return false;
        }
        
        int slot_exist = -1;
        int slot_free  = -1;
        
        extern bool storecat_IsItemStackable(uint32_t ItemID);
        bool isStackable = storecat_IsItemStackable(wi1.itemID);
        for(int i=0; i<loadout_->BackpackSize; i++)
        {
            const wiInventoryItem& wi2 = loadout_->Items[i];
    
    
            // can stack only non-modified items
            if(isStackable && wi2.itemID == wi1.itemID && wi1.Var1 < 0 && wi2.Var1 < 0) 
            {
                slot_exist = i;
                break;
            }
            
            // check if we can place that item to loadout slot
            bool canPlace = storecat_CanPlaceItemToSlot(itemCfg, i);
            if(canPlace && wi2.itemID == 0 && slot_free == -1) 
            {
                slot_free = i;
            }
        }
        
        if(slot_exist == -1 && slot_free == -1)
        {
            PKT_S2C_BackpackModify_s n;
            n.SlotTo = 0xFF;
    
    
            gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
            return false;
        }
    
    
        // check weight
        //float totalWeight = loadout_->getTotalWeight();
        //totalWeight += itemCfg->m_Weight*wi1.quantity;
    
    
        const BackpackConfig* bc = g_pWeaponArmory->getBackpackConfig(loadout_->BackpackID);
    
    
        if(slot_exist >= 0)
        {
            // modify backpack
            r3d_assert(loadout_->Items[slot_exist].itemID == wi1.itemID);
            loadout_->Items[slot_exist].quantity += wi1.quantity;
            
            // report to client
            PKT_S2C_BackpackModify_s n;
            n.SlotTo     = (BYTE)slot_exist;
            n.Quantity   = (WORD)loadout_->Items[slot_exist].quantity;
            n.dbg_ItemID = loadout_->Items[slot_exist].itemID;
            gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
            
            OnBackpackChanged(slot_exist);
    
    
            return true;
        }
    
    
        if(slot_free >= 0)
        {
            // modify backpack
            r3d_assert(loadout_->Items[slot_free].itemID == 0);
    
    
            // check if we can place that item to loadout slot
            bool canPlace = storecat_CanPlaceItemToSlot(itemCfg, 6); // For armor
            bool canPlace1 = storecat_CanPlaceItemToSlot(itemCfg, 7); // For helmet
    
    
            if((wi1.itemID >= 20006 && wi1.itemID <= 20188) && canPlace && loadout_->Items[6].quantity == 0)
            {
               loadout_->Items[6] = wi1;
               // report to client
               PKT_S2C_BackpackAddNew_s n;
               n.SlotTo = 6;
               n.Item   = wi1;
               gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
    
    
               OnBackpackChanged(6);
            }
            else if((wi1.itemID >= 20006 && wi1.itemID <= 20188) && canPlace1 && loadout_->Items[7].quantity == 0)
            {
               loadout_->Items[7] = wi1;
               // report to client
               PKT_S2C_BackpackAddNew_s n;
               n.SlotTo = 7;
               n.Item   = wi1;
               gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
    
    
               OnBackpackChanged(6);
            }
            else
            {
               loadout_->Items[slot_free] = wi1;
    
    
               // report to client
               PKT_S2C_BackpackAddNew_s n;
               n.SlotTo = (BYTE)slot_free;
               n.Item   = wi1;
               gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
    
    
               OnBackpackChanged(slot_free);
            }
    
    
            return true;
        }
        
        r3d_assert(false);
        return false;
    }

    Enjoy!

    Credits: Me
    Last edited by ItzFdr; 11-11-14 at 03:05 PM.


  2. #2
    Valued Member Noobly is offline
    MemberRank
    Aug 2014 Join Date
    101Posts

    Re: [Release] Auto-Equip Helmet or Armor

    Thanks for sharing all this stuff FDRGamer.

  3. #3
    failed in javascript ItzFdr is offline
    MemberRank
    May 2013 Join Date
    BrasilLocation
    293Posts

    Re: [Release] Auto-Equip Helmet or Armor

    Quote Originally Posted by Noobly View Post
    Thanks for sharing all this stuff FDRGamer.
    It's a pleasure to help, but call me Fdr

  4. #4
    Valued Member Noobly is offline
    MemberRank
    Aug 2014 Join Date
    101Posts

    Re: [Release] Auto-Equip Helmet or Armor

    Alright :)

  5. #5
    Account Upgraded | Title Enabled! Oosmar02 is offline
    MemberRank
    Sep 2013 Join Date
    FranceLocation
    894Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    Error :




    Fix please :) ?

  6. #6
    failed in javascript ItzFdr is offline
    MemberRank
    May 2013 Join Date
    BrasilLocation
    293Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    Quote Originally Posted by Oosmar02 View Post
    Error :




    Fix please :) ?
    Fixed, do tutorial again.

  7. #7
    Account Upgraded | Title Enabled! Oosmar02 is offline
    MemberRank
    Sep 2013 Join Date
    FranceLocation
    894Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    For WarZTH

    Code:
    bool obj_ServerPlayer::BackpackAddItem(const wiInventoryItem& wi1){
        // SPECIAL case - GOLD item
        if(wi1.itemID == 'GOLD')
        {
            r3dOutToLog("%s BackpackAddItem %d GameDollars\n", userName, wi1.quantity); CLOG_INDENT;
    
    
    
    
            // FOR PREMIUM USERS
            int gd = wi1.quantity;
            if (profile_.ProfileData.isPremium && gServerLogic.ginfo_.ispre)
                gd *= 2; // DOUBLE DOLLARS
    
    
    
    
            profile_.ProfileData.GameDollars += gd;
    
    
    
    
            // report to client
            PKT_S2C_BackpackAddNew_s n;
            n.SlotTo = 0;
            n.Item   = wi1;
            gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
            return true;
        }
    
    
    
    
        const WeaponAttachmentConfig* cfg = g_pWeaponArmory->getAttachmentConfig(wi1.itemID);
    
    
    
    
        //r3dOutToLog("%s BackpackAddItem %dx%d\n", userName, wi1.itemID, wi1.quantity); CLOG_INDENT;
        r3d_assert(wi1.itemID > 0);
        //r3d_assert(wi1.quantity > 0);
        
        const BaseItemConfig* itemCfg = g_pWeaponArmory->getConfig(wi1.itemID);
        if(!itemCfg) 
        {
            gServerLogic.LogCheat(peerId_, PKT_S2C_CheatWarning_s::CHEAT_Data, false, "BackpackAddItem",
                "%d", wi1.itemID);
            return false;
        }
        
        int slot_exist = -1;
        int slot_free  = -1;
        
        extern bool storecat_IsItemStackable(uint32_t ItemID);
        bool isStackable = storecat_IsItemStackable(wi1.itemID);
        for(int i=0; i<loadout_->BackpackSize; i++)
        {
            const wiInventoryItem& wi2 = loadout_->Items[i];
    
    
    
    
            // can stack only non-modified items
            if(isStackable && wi2.itemID == wi1.itemID && wi1.Var1 < 0 && wi2.Var1 < 0) 
            {
                slot_exist = i;
                break;
            }
            
            // check if we can place that item to loadout slot
            bool canPlace = storecat_CanPlaceItemToSlot(itemCfg, i);
            if(canPlace && wi2.itemID == 0 && slot_free == -1) 
            {
                slot_free = i;
            }
        }
        
        if(slot_exist == -1 && slot_free == -1)
        {
            PKT_S2C_BackpackModify_s n;
            n.SlotTo = 0xFF;
    
    
    
    
            gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
            return false;
        }
    
    
    
    
        // check weight
        //float totalWeight = loadout_->getTotalWeight();
        //totalWeight += itemCfg->m_Weight*wi1.quantity;
    
    
    
    
        const BackpackConfig* bc = g_pWeaponArmory->getBackpackConfig(loadout_->BackpackID);
    
    
    
    
        if(slot_exist >= 0)
        {
            // modify backpack
            r3d_assert(loadout_->Items[slot_exist].itemID == wi1.itemID);
            loadout_->Items[slot_exist].quantity += wi1.quantity;
            
            // report to client
            PKT_S2C_BackpackModify_s n;
            n.SlotTo     = (BYTE)slot_exist;
            n.Quantity   = (WORD)loadout_->Items[slot_exist].quantity;
            n.dbg_ItemID = loadout_->Items[slot_exist].itemID;
            gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
            
            OnBackpackChanged(slot_exist);
    
    
    
    
            return true;
        }
    
    
    
    
        if(slot_free >= 0)
        {
            // modify backpack
            r3d_assert(loadout_->Items[slot_free].itemID == 0);
    
    
    
    
            // check if we can place that item to loadout slot
            bool canPlace = storecat_CanPlaceItemToSlot(itemCfg, 6); // For armor
            bool canPlace1 = storecat_CanPlaceItemToSlot(itemCfg, 7); // For helmet
    
    
    
    
            if((wi1.itemID >= 20006 && wi1.itemID <= 20188) && canPlace && loadout_->Items[6].quantity == 0)
            {
               loadout_->Items[6] = wi1;
               // report to client
               PKT_S2C_BackpackAddNew_s n;
               n.SlotTo = 6;
               n.Item   = wi1;
               gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
    
    
    
    
               OnBackpackChanged(6);
            }
            else if((wi1.itemID >= 20006 && wi1.itemID <= 20188) && canPlace1 && loadout_->Items[7].quantity == 0)
            {
               loadout_->Items[7] = wi1;
               // report to client
               PKT_S2C_BackpackAddNew_s n;
               n.SlotTo = 7;
               n.Item   = wi1;
               gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
    
    
    
    
               OnBackpackChanged(6);
            }
            else
            {
               loadout_->Items[slot_free] = wi1;
    
    
    
    
               // report to client
               PKT_S2C_BackpackAddNew_s n;
               n.SlotTo = (BYTE)slot_free;
               n.Item   = wi1;
               gServerLogic.p2pSendToPeer(peerId_, this, &n, sizeof(n));
    
    
    
    
               OnBackpackChanged(slot_free);
            }
    
    
    
    
            return true;
        }
        
        r3d_assert(false);
        return false;
    }

  8. #8
    Enthusiast zD4RK is offline
    MemberRank
    Mar 2014 Join Date
    localhostLocation
    48Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    i luv u man

  9. #9
    Apprentice grizzly is offline
    MemberRank
    Aug 2015 Join Date
    7Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    is the AUTOEQUIP code for global inventory to backpack or not? or is this in game
    can someone help me search AUTOEQUIP function for global inventory to backpack
    faster equip

    sorry for my bad English

  10. #10
    Enthusiast pauloplx is offline
    MemberRank
    Sep 2015 Join Date
    35Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    is the AUTOEQUIP code for global inventory to backpack or not? or is this in game
    can someone help me search AUTOEQUIP function for global inventory to backpack
    faster equip ?

    ??? HELP

  11. #11
    My Status --> LukasCCB is offline
    MemberRank
    Apr 2013 Join Date
    CracolandiaLocation
    1,190Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    Quote Originally Posted by pauloplx View Post
    is the AUTOEQUIP code for global inventory to backpack or not? or is this in game
    can someone help me search AUTOEQUIP function for global inventory to backpack
    faster equip ?

    ??? HELP
    Auto equip in-game playing, not for global inv.

  12. #12
    Enthusiast pauloplx is offline
    MemberRank
    Sep 2015 Join Date
    35Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    I'm talking the code in an armor it goes straight to part of armor

  13. #13
    Play Alpha MMO DouglasPro is offline
    MemberRank
    Nov 2014 Join Date
    //HKEY//RJ_BRLocation
    391Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    Quote Originally Posted by pauloplx View Post
    I'm talking the code in an armor it goes straight to part of armor
    Maybe I can help you when you get home.

  14. #14
    Enthusiast pauloplx is offline
    MemberRank
    Sep 2015 Join Date
    35Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    Quote Originally Posted by DouglasPro View Post
    Maybe I can help you when you get home.

    ok, I'm waiting
    I'm waiting

  15. #15
    Enthusiast pauloplx is offline
    MemberRank
    Sep 2015 Join Date
    35Posts

    Re: [Tutorial] Auto-Equip Helmet or Armor

    @DouglasPro

    Do you think you can help me?



Page 1 of 2 12 LastLast

Advertisement