Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Tutorial] Auto-Equip Helmet or Armor

Skilled Illusionist
Joined
May 17, 2013
Messages
309
Reaction score
206





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:
Junior Spellweaver
Joined
Aug 13, 2014
Messages
100
Reaction score
38
Re: [Release] Auto-Equip Helmet or Armor

Thanks for sharing all this stuff FDRGamer.
 
Joined
Sep 3, 2013
Messages
903
Reaction score
227
Error :

ItzFdr - [Tutorial] Auto-Equip Helmet or Armor - RaGEZONE Forums



Fix please :) ?
 
Joined
Sep 3, 2013
Messages
903
Reaction score
227
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;
}
 
Newbie Spellweaver
Joined
Aug 29, 2015
Messages
7
Reaction score
0
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 :w00t:
 
Newbie Spellweaver
Joined
Sep 15, 2015
Messages
35
Reaction score
0
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
 
Newbie Spellweaver
Joined
Sep 15, 2015
Messages
35
Reaction score
0
I'm talking the code in an armor it goes straight to part of armor
 
Experienced Elementalist
Joined
May 28, 2017
Messages
225
Reaction score
127
just take a closer look at the code, its server code, it might work at the gi ingame but not in the menu since the menu is using that stupid API
 
Back
Top