Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[Development] Random attachment system

Developer
Developer
Joined
Dec 11, 2010
Messages
2,955
Reaction score
2,688
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

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

ITe6EGc - [Development] Random attachment system - RaGEZONE Forums


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
 

Attachments

You must be registered for see attachments list
Last edited:
Newbie Spellweaver
Joined
Jul 30, 2014
Messages
38
Reaction score
7
you should check WorldRes folder and search for baseattachments, and you should place random attachments there
 
Back
Top