Jump to content

Forums Announcement

Read-Only Mode for Announcements & Changelogs

Dear Survivors, we'd like to inform you that this forum will transition to read-only mode. From now on, it will serve exclusively as a platform for official announcements and changelogs.

For all community discussions, debates, and engagement, we encourage you to join us on our social media platforms: Discord, Twitter/X, Facebook.

Thank you for being a valued part of our community. We look forward to connecting with you on our other channels!

Stay safe out there,
Your DayZ Team

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

×