Hello,
I decided to add a feature that it's in current 0.60 which is the random attachment system for guns, this includes optics and magazines.
The attachment system is coded in C++ and it happens when an item is spawned on the server at the very beginning of server start up.
Features
- AK101 can spawn with PSO-1 scope and/or magazine
- AKM can spawn with drum mag or 30 round magazine, or PSO-1 scope
(Will add more guns later)
Video
Tutorial
Go to gameStateExp.cpp and add at the very top
And then find
In that function, locate
And then add this line of code at the end of the second last }; so it looks like this:
And then add this function BEFORE the SpawnLootObject function
And then go to WorldSpawn.cpp and add this before SpawnLootObject object so it looks like this
Go to weapons_firearms.pbo
And under "AKMbase" from config.bin -> config.cpp with UnRap you add
So it looks like this
And then recreate weapons_firearms.pbo file, now you can configure random attachments
Bugs
- Magazines are not visible on gun until you pick it up
I decided to add a feature that it's in current 0.60 which is the random attachment system for guns, this includes optics and magazines.
The attachment system is coded in C++ and it happens when an item is spawned on the server at the very beginning of server start up.
Features
- AK101 can spawn with PSO-1 scope and/or magazine
- AKM can spawn with drum mag or 30 round magazine, or PSO-1 scope
(Will add more guns later)
Video
Tutorial
Go to gameStateExp.cpp and add at the very top
PHP:
#include <string>
And then find
PHP:
Entity* SpawnLootObject( WRClassHierarchy* pClass, const char* sName, WRLoot_Point* pProxy, Vector3Par vPosOverride )
In that function, locate
PHP:
if( pClass )
{
// default attachments
AutoArray<RString*>& at = pClass->GetAttachments();
if( at.Size() > 0 )
{
for( int atSize = 0; atSize < at.Size(); atSize++ )
SpawnLootObjectInInventory(veh,at[atSize]->Data());
};
// default cargo
AutoArray<RString*>& ct = pClass->GetCargo();
if( ct.Size() > 0 )
{
for( int ctSize = 0; ctSize < ct.Size(); ctSize++ )
SpawnLootObjectInCargo(veh,ct[ctSize]->Data());
};
};
And then add this line of code at the end of the second last }; so it looks like this:
PHP:
if( pClass )
{
// default attachments
AutoArray<RString*>& at = pClass->GetAttachments();
if( at.Size() > 0 )
{
for( int atSize = 0; atSize < at.Size(); atSize++ )
SpawnLootObjectInInventory(veh,at[atSize]->Data());
};
// default cargo
AutoArray<RString*>& ct = pClass->GetCargo();
if( ct.Size() > 0 )
{
for( int ctSize = 0; ctSize < ct.Size(); ctSize++ )
SpawnLootObjectInCargo(veh,ct[ctSize]->Data());
};
GiveRandomAttachments( veh );
};
And then add this function BEFORE the SpawnLootObject function
PHP:
void GiveRandomAttachments(Entity* veh)
{
InventoryItem *item = dyn_cast<InventoryItem>(veh);
std::string item_name( item->GetName() ); // Quackster:: char* pointer to string
ConstParamEntryPtr cls = (Pars >> "CfgWeapons").FindEntry( item->GetName() );
if (cls && cls->IsClass())
{
ParamEntryPtr magazines = cls->FindEntry("gun_magazines");
ParamEntryPtr optics = cls->FindEntry("gun_optics");
if ((magazines && magazines->IsArray()) && (optics && optics->IsArray()))
{
RString magazine = (*magazines)[ rand() % magazines->GetSize() ].GetValue();
RString optic = (*optics)[ rand() % optics->GetSize() ].GetValue();
SpawnLootObjectInInventory(veh,magazine);
SpawnLootObjectInInventory(veh,optic);
}
}
}
And then go to WorldSpawn.cpp and add this before SpawnLootObject object so it looks like this
PHP:
/**/void GiveRandomAttachments( Entity* veh );
/**/Entity* SpawnLootObject( WRClassHierarchy* pClass, const char* sName, WRLoot_Point* pProxy, Vector3Par vPosOverride );
Go to weapons_firearms.pbo
And under "AKMbase" from config.bin -> config.cpp with UnRap you add
Code:
gun_magazines[] = {"M_akm_30Rnd", "M_akm_palm30_green", "M_akm_palm30_black", "M_akm_drum","","","","","","","","","","","","","",""};
gun_optics[] = {"Attachment_Optic_PSO1","","","","",""} ;
So it looks like this
And then recreate weapons_firearms.pbo file, now you can configure random attachments

Bugs
- Magazines are not visible on gun until you pick it up
Last edited: