Jump to content
The Classified Rebel

Spawning with Gear

Recommended Posts

I am looking into doing event about like the pvp stress test they did and I have players spawning in with a M4A1 and mags but it is a bare bones M4, how do a spawn it with attachments? I am doing it through the init file using notepad++ and this is what it looks like:

        itemEnt = player.GetInventory().CreateInInventory("M4A1");
        itemBs = ItemBase.Cast(itemEnt);
        
        itemEnt = player.GetInventory().CreateInInventory("Mag\_STANAG\_30Rnd");
        itemBs = ItemBase.Cast(itemEnt);
        

Share this post


Link to post
Share on other sites

Have a read through the comments here.

Quote

For now, you can attach a magazine and other attachments by using something to the effect of

itemEnt.GetInventory().CreateAttachment("M4_RISHndgrd_Black");

The thing is, you MUST update the ItemBase count or it won't spawn. This is done like this:

itemBs = ItemBase.Cast(itemEnt);

And should be added after every line where you're spawning something in the player's inventory.

I don't use CreateInInventory for my M4, I use CreateAttachment because it seems to load the gun automatically if you spawn a mag with it. Here's that code:

itemEnt.GetInventory().CreateAttachment("M4A1");

itemBs = ItemBase.Cast(itemEnt); //updating ItemBase count again

Taking the item to your hands automatically can be done like this:

player.LocalTakeEntityToHands(itemEnt);

You'd want to add that after the code for spawning your M4, and preferably you'd want your M4 spawning last.

 

Edited by smasht

Share this post


Link to post
Share on other sites
On 9/22/2018 at 6:27 AM, smasht said:

Have a read through the comments here.

 

The way you said I have tried and it does not work, could you copy and paste what you have like I did at the top so I know what you are saying.

Share this post


Link to post
Share on other sites

@The Classified Rebel I managed to spawn with an M4 and a powered M68 scope using code like this:

Quote

EntityAI itemEnt = player.GetHumanInventory().CreateInHands("M4A1");
itemEnt.GetInventory().CreateAttachment("M4_OEBttstck");
itemEnt.GetInventory().CreateAttachment("M4_PlasticHndgrd");

EntityAI scopeEnt = itemEnt.GetInventory().CreateAttachment("M68Optic");
scopeEnt.GetInventory().CreateAttachment("Battery9V");
        
for (int i = 0; i < 3; i++)
{
    player.GetInventory().CreateInInventory("Mag_STANAG_30Rnd");
}

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×