Quantcast
Channel: RaGEZONE - MMO Development Forums
Viewing all articles
Browse latest Browse all 33177

[Release] Stack Clips - Cmd

$
0
0
Hey!
This is the code for Stacking full clips into one slot with server command.

Yes, it has no GUI and it's kinda messy but this is the concept and needs some work so you can develop it to the Stack Bullets, improve it, match it with the GUI, whatever! :D:

You stack clips by putting the wanted mag into Slot 6 in your inventory and typing /stack command.

Pic here.
Spoiler:




You probably want to highlight the Slot 6 as I did. :P:

So it's server-sided and it comes with an extra RemoveItem function (which basicly set the item quantity and reports it to the client).
There might be some secret dupes, bugs as I didn't try it out with other players, but I haven't meet any so far.
If so, post it here.


In ServerGameLogic.cpp

Search for
Code:

    if(strncmp(cmd, "/tp", 3) == 0 && plr->profile_.ProfileData.isDevAccount)
        return Cmd_Teleport(plr, cmd);

Add below
Code:

    if(strncmp(cmd, "/stack", 6) == 0)
        return Cmd_StackClip(plr, cmd);

Search for
Code:

int ServerGameLogic::Cmd_Teleport(obj_ServerPlayer* plr, const char* cmd)
{
.
.
.
}

Add below
Code:

int ServerGameLogic::Cmd_StackClip(obj_ServerPlayer* plr, const char* cmd)
{
    if(plr->loadout_->Alive == 0)
    {
        return 2;
    }


    plr->StackClip();


    return 0;
}

Now in ServerGameLogic.h

Seach for
Code:

    int          Cmd_Teleport(obj_ServerPlayer* plr, const char* cmd);
Add below
Code:

    int          Cmd_StackClip(obj_ServerPlayer* plr, const char* cmd);
Now in obj_ServerPlayer.cpp

Search for
Code:

void obj_ServerPlayer::BackpackDropItem(int idx)
{
.
.
.
}

Add below
Code:

void obj_ServerPlayer::StackClip() //MRsrac
{
    short mags = 0; //var for the mag count


    wiInventoryItem& wi = loadout_->Items[5]; //get the item from slot 5 (in-game slot 6)
    uint32_t stackitem = wi.itemID; //save the itemid


    const WeaponAttachmentConfig* mag = g_pWeaponArmory->getAttachmentConfig(stackitem);
    if(!mag) return; //if its not mag, fuck it :D


    wiInventoryItem wi2; //initialize another item


    //go through the inventory
    for(int i = 0; i < loadout_->BackpackSize; i++)
    {
        //get the item
        wi2 = loadout_->Items[i];


        //if is the same mag
        if(wi2.itemID == stackitem)
        {
            //stack ammo/bullets code here? :P


            if(wi2.Var1 == mag->m_Clipsize || wi2.Var1 == -1) //thats right, -1 bullets is full mag, however it doesnt work sometimes(?) so check also for the max clip size
            {
                //increase mag count
                mags += wi2.quantity;


                //remove it
                wi2.Reset();
                RemoveItem(i, 0);
            }
        }
    }
   
    if(mags >= 1)
    {
        //initialize new item
        wiInventoryItem magazine;
        magazine.itemID = stackitem; //same id as the mag
        magazine.quantity = mags; //how many mags
       
        //Add it!
        BackpackAddItem(magazine);
    }   
}

And below it add
Code:

void obj_ServerPlayer::RemoveItem(int slot, int count)
{
    wiInventoryItem& wi = loadout_->Items[slot];
    PKT_S2C_BackpackModify_s p;
    p.SlotTo = slot;
    p.Quantity = count;
    p.dbg_ItemID = wi.itemID;
    gServerLogic.p2pSendToPeer(peerId_, this, &p, sizeof(p));
    wi.Reset();
}

Now in obj_ServerPlayer.h

Search for
Code:

    void        BackpackDropItem(int slot);
Add below
Code:

    void        StackClip();
    void        RemoveItem(int slot, int count);

That should be it. If you get errors tell me.

Ummm, and credit?

Credit: ME!!! ME !!!
IMMA CREDIT-EATING MONSTER NOM NOM NOM PLZ FEED xD

Viewing all articles
Browse latest Browse all 33177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>