Page MenuHomeFeedback Tracker

[Feature Request] Add possibility to spawn weapon with attached magazine/ loaded using scripting
Closed, ResolvedPublic

Description

I would like spawn weapon entity. I can spawn it, add attachments too. BUT adding magazine is MISSING or IMPOSSIBLE.
Code:

oWpn = Weapon_Base.Cast((GetGame().CreateObject("VSS" , "0 0 0");
optic = oWpn.GetInventory().CreateAttachment("PSO11Optic");

BUT for magazine this way DOES NOT WORK.
Also idk how is possible spawn for example shotgun with ammo loaded.

Could you please implement this?

Thanks a lot!

Details

Severity
Feature
Resolution
Open
Reproducibility
Always
Operating System
Windows 7
Category
Modding

Event Timeline

Hunterz created this task.Feb 19 2020, 9:13 PM
Hunterz renamed this task from [Featrure Request] Add possibility to spawn weapon with attached magazine/ loaded using scripting to [Feature Request] Add possibility to spawn weapon with attached magazine/ loaded using scripting.Feb 19 2020, 9:25 PM
Hunterz updated the task description. (Show Details)

You most likely need to go through the scripted process of attaching the magazine either way. Have a look at how it is currently done in the reload/switch magazine scripts.

Jacob_Mango added subscribers: Geez, Jacob_Mango.EditedMar 2 2020, 4:53 AM

Call this on the server @Hunterz if you want to spawn a magazine in a weapon

	Weapon_Base weapon = ...
	string magazine_type = ...

	int stateId = -1;

	if ( weapon.IsInherited( SKS_Base ) )
	{
		return;
	} else if ( weapon.IsInherited( BoltActionRifle_InnerMagazine_Base ) )
	{
		return;
	} else if ( weapon.IsInherited( DoubleBarrel_Base ) )
	{
		return;
	} else if ( weapon.IsInherited( Pistol_Base ) )
	{
		stateId = PistolStableStateID.CLO_DIS_BU0_MA1;
	} else if ( weapon.IsInherited( CZ527_Base ) )
	{
		stateId = CZ527StableStateID.CZ527_CLO_BU0_MA1;
	} else if ( weapon.IsInherited( Repeater_Base ) )
	{
		return;
	} else if ( weapon.IsInherited( RifleBoltFree_Base ) )
	{
		stateId = RBFStableStateID.RBF_CLO_BU0_MA1;
	} else if ( weapon.IsInherited( RifleBoltLock_Base ) )
	{
		stateId = RBLStableStateID.RBL_OPN_BU0_MA1;
	} else if ( weapon.IsInherited( Mp133Shotgun_Base ) )
	{
		return;
	}

	InventoryLocation il = new InventoryLocation;
	il.SetAttachment( weapon, NULL, InventorySlots.MAGAZINE );

	// using any of the inventory sync for existing spawning magazines also works
	// e.g. GameInventory.LocationSyncMoveEntity

	EntityAI mag = SpawnEntity( magazine_type, il, ECE_IN_INVENTORY, RF_DEFAULT );
	GetGame().RemoteObjectDelete( mag );
	GetGame().RemoteObjectDelete( weapon );

	pushToChamberFromAttachedMagazine( weapon, weapon.GetCurrentMuzzle() );

	ScriptReadWriteContext ctx = new ScriptReadWriteContext;
	ctx.GetWriteContext().Write( stateId );
	weapon.LoadCurrentFSMState( ctx.GetReadContext(), GetGame().SaveVersion() );

	GetGame().RemoteObjectCreate( weapon );
	GetGame().RemoteObjectCreate( mag );

Ticket can be closed @Geez

Geez closed this task as Resolved.Mar 2 2020, 10:32 AM
Geez claimed this task.

Thank a lot Jacob_Mango!

When I tried attach magazine to CZ527, got bugged weapon. I did with CZ527 and Mag_CZ527_5rnd. Others rifles like AK works very well.