Jump to content
StreetkillnHD

custom spawn gear with primary weapon and secondary weapon slots equiped

Recommended Posts

hello im trying to to figure out how to set up custom spawn gear, in stead of just adding the items to a backpack i want to add 2 weapons to the primary and seconday slots, also how make it so a mag is already inserted into a gun.

Share this post


Link to post
Share on other sites
On 4/10/2023 at 9:57 PM, StreetkillnHD said:

hello im trying to to figure out how to set up custom spawn gear, in stead of just adding the items to a backpack i want to add 2 weapons to the primary and seconday slots, also how make it so a mag is already inserted into a gun.

Don't standing like a dump and wait when smbdy tell you what to do.

Get to Google and find how to spawn item to player's inventory (it's quite simple). How to spawn weapons on player (I tell you not in player's hands, so last spawned weapon always be in hands exception is when you spawn not in hands.).

So what da heck shall you do: explore, search and lean to scripting. It's too easy to be carried about. Find, understand and use it. Not like a dummy child - sitting and awaiting when you'll able to get someone's home work...

Share this post


Link to post
Share on other sites

i get it i know how to add items and such to spawn gear, im just loking for the code on how to get it so the weapons i want is in there primary and secondary slots, not the hotbar the equipment slots , i know how to set and items to the hot bar.

Share this post


Link to post
Share on other sites

The code below works for me. I don't have to specify they should be placed on the back of the player, they just do anyways. Put it in the init.c

class CustomMission: MissionServer
{
	// Vanilla code
	
	
	
	override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
	{
		// Vanilla code




		
		// M4
		private Weapon_Base weapon1;
		weapon1 = player.GetInventory().CreateInInventory("M4A1");
		weapon1.GetInventory().CreateAttachment("M4_OEBttstck");
		weapon1.GetInventory().CreateAttachment("M4_RISHndgrd");
		weapon1.GetInventory().CreateAttachment("ACOGOptic");
		weapon1.GetInventory().CreateAttachment("Mag_STANAG_30Rnd");
		ChaimberWeapon(weapon1);

		// AKM
		private Weapon_Base weapon2;
		weapon2 = player.GetInventory().CreateInInventory("AKM");
		weapon2.GetInventory().CreateAttachment("AK_WoodBttstck_Black");
		weapon2.GetInventory().CreateAttachment("AK_RailHndgrd_Black");
		weapon2.GetInventory().CreateAttachment("PSO11Optic");
		weapon2.GetInventory().CreateAttachment("Mag_AKM_30Rnd");
		ChaimberWeapon(weapon2);
	}
	
	// Put a round in the chaimber of the weapon.
	void ChaimberWeapon(Weapon_Base weapon)
	{
		int muzzleIndex = weapon.GetCurrentMuzzle();
		float ammoDamage;
		string ammoTypeName;
		Magazine magazine = weapon.GetMagazine(muzzleIndex);
		magazine.LocalAcquireCartridge(ammoDamage, ammoTypeName);
		
		weapon.PushCartridgeToChamber(muzzleIndex, ammoDamage, ammoTypeName);		
	}
};

When you attach a magazine to the weapon this way it doesn't put a round in the chaimber, so I made a method for that.

For some reason the first shot will click, but the second and following rounds will fire as normal. I don't know why that is.

If you don't want a round to be put in the chaimber, but rather the player has to do it themself by clicking "R", just remove that function and the calls to it.

Also, the magazine will only be visible in the attachment slots for the weapon until the first round is fired or the weapon is placed on the ground and picked up again. Everywhere else it will look like the weapon doesn't have a magazine (but it does). But after having done either of those two manouvers the magazine will be visible everywhere. I don't know why that is either. I'm guessing some more code is needed when attaching a magazine to make it work properly, but I haven't figured out what that is and I'm too lazy to dig into it any further.

  • Thanks 1

Share this post


Link to post
Share on other sites
On 4/14/2023 at 9:27 PM, NoBeansForMe said:

The code below works for me. I don't have to specify they should be placed on the back of the player, they just do anyways. Put it in the init.c


class CustomMission: MissionServer
{
	// Vanilla code
	
	
	
	override void StartingEquipSetup(PlayerBase player, bool clothesChosen)
	{
		// Vanilla code




		
		// M4
		private Weapon_Base weapon1;
		weapon1 = player.GetInventory().CreateInInventory("M4A1");
		weapon1.GetInventory().CreateAttachment("M4_OEBttstck");
		weapon1.GetInventory().CreateAttachment("M4_RISHndgrd");
		weapon1.GetInventory().CreateAttachment("ACOGOptic");
		weapon1.GetInventory().CreateAttachment("Mag_STANAG_30Rnd");
		ChaimberWeapon(weapon1);

		// AKM
		private Weapon_Base weapon2;
		weapon2 = player.GetInventory().CreateInInventory("AKM");
		weapon2.GetInventory().CreateAttachment("AK_WoodBttstck_Black");
		weapon2.GetInventory().CreateAttachment("AK_RailHndgrd_Black");
		weapon2.GetInventory().CreateAttachment("PSO11Optic");
		weapon2.GetInventory().CreateAttachment("Mag_AKM_30Rnd");
		ChaimberWeapon(weapon2);
	}
	
	// Put a round in the chaimber of the weapon.
	void ChaimberWeapon(Weapon_Base weapon)
	{
		int muzzleIndex = weapon.GetCurrentMuzzle();
		float ammoDamage;
		string ammoTypeName;
		Magazine magazine = weapon.GetMagazine(muzzleIndex);
		magazine.LocalAcquireCartridge(ammoDamage, ammoTypeName);
		
		weapon.PushCartridgeToChamber(muzzleIndex, ammoDamage, ammoTypeName);		
	}
};

When you attach a magazine to the weapon this way it doesn't put a round in the chaimber, so I made a method for that.

For some reason the first shot will click, but the second and following rounds will fire as normal. I don't know why that is.

If you don't want a round to be put in the chaimber, but rather the player has to do it themself by clicking "R", just remove that function and the calls to it.

Also, the magazine will only be visible in the attachment slots for the weapon until the first round is fired or the weapon is placed on the ground and picked up again. Everywhere else it will look like the weapon doesn't have a magazine (but it does). But after having done either of those two manouvers the magazine will be visible everywhere. I don't know why that is either. I'm guessing some more code is needed when attaching a magazine to make it work properly, but I haven't figured out what that is and I'm too lazy to dig into it any further.

Actually it's quite simple to make. (Create firearm with attached mag and with cartridge in the chamer BUT, function for weapon with external magazine and function for weapons with internal magazine is different).

And the funniest part that if you attach mag you may breake your gun (mag couldn't be detached), with function from Weapon.c - you not breaking mag and firearm and will abre to change the magazine.

Share this post


Link to post
Share on other sites
Quote

For some reason the first shot will click, but the second and following rounds will fire as normal. I don't know why that is.

I have the same issue, trying to figure it out, do you have any success or maybe you've found another way?

Share this post


Link to post
Share on other sites
8 hours ago, takumo@gmail.com said:

I have the same issue, trying to figure it out, do you have any success or maybe you've found another way?

Main problem of guns - some may have an internal mag (like Winchester 70, SKS, Mosin, etc).
Here some tricks how to chamber your rifle and spawn with full internal mag or with attached mag.

For the code I'll use some std classes:
Slot Wpn A = AKM (with attached drum and with cartridge in chamber)
Slot Wpn B = SKS with 10 loaded ammo in internal mag.

EntityAI AKM_Entity = player.GetInventory().CreateInInventory("AKM");
AKM_Entity.SetHealth(AKM_Entity.GetMaxHealth());		// Remove any damage from item
EntityAI Kobra = AK_74Entity.GetInventory().CreateAttachment("KobraOptic");	// set attachment
Kobra.GetInventory().CreateAttachment("Battery9V");							// add battary for attachment
AKM_Entity.GetInventory().CreateAttachment("AK_Bayonet");			// let's add some muzle attachment
AKM_Entity.GetInventory().CreateAttachment("AK_PlasticHndgrd");		// I hate to feel the smell of my hands, let's set handguard
AKM_Entity.GetInventory().CreateAttachment("AK_PlasticBttstck");	// I wish to kick zmbs a**es so I need the buttstock!
player.SetQuickBarEntityShortcut(AKM_Entity, 0, true);		// Set ours AKM to prime slot of quick bar.
Weapon wpn1 = Weapon.Cast(AKM_Entity);			// Now we cast or AKM to Weapon-instance class
Weapon_Base wpn_bs1 = Weapon_Base.Cast(wpn);	// For safe way recast to WeaponBase
Magazine mag = wpn_bs1.SpawnAttachedMagazine("Mag_AKM_Drum75Rnd");	// Attach mag to ours AKM = 75-1 (coz 1 cartrige placed ain camber
mag.LocalSetAmmoCount(mag.GetAmmoMax());		// Intent our Mag has full cap for local player instance
mag.ServerSetAmmoCount(mag.GetAmmoMax());		// Same fr Server instance
// On that stage we have a full AKM with mag and chambered!

EntityAI SKS_Entity = player.GetInventory().CreateInInventory("SKS");	// Will be placed to the sholder - wpn slot B
SKS_Entity.SetHealth(SKS_Entity.GetMaxHealth());		// Remove any damage from item
SKS_Entity.GetInventory().CreateInInventory("PUScopeOptic");			// Let's set PU Optics
SKS_Entity.GetInventory().CreateInInventory("SKS_Bayonet");				// Let's set SKS Bayonet
player.SetQuickBarEntityShortcut(SKS_Entity, 1, true);
Weapon wpn2 = Weapon.Cast(SKS_Entity);									// Set ours SKS to secondary slot of quick bar.
Weapon_Base wpn_bs2 = Weapon_Base.Cast(wpn2);
wpn_bs2.SpawnAmmo("", WeaponWithAmmoFlags.CHAMBER);						// Fill ammo into the chamber and internal mag (rnd masybe std maybe tracer)

Tryout it will works like a charm.
Checkout /dta/scrips.pbo -> Weapon_Base.c for usefull fncs like WeaponBase.HasInternalMagazine() => true is internal, false = external (attaching).

  • Like 1

Share this post


Link to post
Share on other sites

I have been literally trying to do this for my custom init.c file where I have various loadouts on a PVP server. I have all guns spawn with a magazine but no bullet in the chamber. I have also argued with Chat GPT who has been giving me code that does not work and gives me errors. My question then would be where would I insert this code so it reads my init.c properly? This is my init.c file. I also use CPB weapon which has custom ammo types I.E CPB_Ammo_338, CPB_Ammo50Cal etc. Can anyone help me out I would appreciate it a lot!! Thanks.  

//Spawn helper function
void SpawnObject( string type, vector position, vector orientation )
{
    auto obj = GetGame().CreateObject( type, position );
    obj.SetPosition( position );
    obj.SetOrientation( orientation );
    obj.SetOrientation( obj.GetOrientation() ); //Collision fix
    obj.Update();
    obj.SetAffectPathgraph( true, false );
    if( obj.CanAffectPathgraph() ) GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( GetGame().UpdatePathgraphRegionByObject, 100, false, obj );
}
#define DISABLE_PERSISTENCY
#include "$CurrentDir:mpmissions\\dayzOffline.chernarusplus\\custom_Skalinsky_Military_Buildings.c"
//#include "$CurrentDir:mpmissions\\dayzOffline.chernarusplus\\custom_Skalinsky_Bridges.c"


void main()
{
    AddcustomSkalinskyMilitaryBuildings();
    //AddcustomSkalinskyBridges();
    //INIT WEATHER BEFORE ECONOMY INIT------------------------
    Weather weather = g_Game.GetWeather();

    weather.MissionWeather(false);    // false = use weather controller from Weather.c

    weather.GetOvercast().Set( Math.RandomFloatInclusive(0.0, 0.0), 0, 0);
    weather.GetRain().Set( 0, 0, 0);
    weather.GetFog().Set( Math.RandomFloatInclusive(0.0, 0.0), 0, 0);

    //INIT ECONOMY--------------------------------------
    Hive ce = CreateHive();
    if ( ce )
        ce.InitOffline();

//DATE RESET AFTER ECONOMY INIT-------------------------
    int year, month, day, hour, minute;
    int reset_month = 8, reset_day = 20;
    GetGame().GetWorld().GetDate(year, month, day, hour, minute);

    if ((month == reset_month) && (day < reset_day))
    {
        GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
    }
    else
    {
        if ((month == reset_month + 1) && (day > reset_day))
        {
            GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
        }
        else
        {
            if ((month < reset_month) || (month > reset_month + 1))
            {
                GetGame().GetWorld().SetDate(year, reset_month, reset_day, hour, minute);
            }
        }
    }
}

class CustomMission : MissionServer {
    /*
     *  Config:
     *      This area is the only area in which users should change any information/variables.
     *      If you do not understand what something is being used for please read the comments above every function.
    */

    //Bag Name
    string bag_name = "Renegade_MilitaryCamoSmershBag";

    /*
     * Name: Assault Class
     * Primary Weapon: M4
     * Weapon Attachments: CQB Buttstock, ACOG Scope, RIS Handguard
     * Sidearm Weapon: AWM
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Assault_Clothing = {"Renegade_MilitaryCamo_BalaclavaMask", "Tango_clanHelmet", "Tango_clanPlatecarrier", "Renegade_MilitaryCamoGloves", "Tango_clanPouches", "Tango_clanPants"};
    string Assault_Gun = "Gold_M4";
    string Assault_SideArm = "CPB_AWM_Green";
    autoptr TStringArray Assault_SideArm_Attachments = {"HuntingOptic", "CPB_AWM_Magazine_10Rnd"};
    autoptr TStringArray Assault_Attachments = {"M4_CQBBttstck_Black", "ACOGOptic", "MAG_STANAGCoupled_30Rnd", "M4_RISHndgrd_Black"};
    autoptr TStringArray Assault_Mags = {"MAG_STANAGCoupled_30Rnd", "MAG_STANAGCoupled_30Rnd", "CPB_AWM_Magazine_10Rnd", "CPB_AWM_Magazine_10Rnd", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"}
    
        /*
     * Name: Tango Class
     * Primary Weapon: AKM
     * Weapon Attachments: CQB Buttstock, ACOG Scope, RIS Handguard
     * Sidearm Weapon: SVD
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Tango_Clothing = {"Tango_clanBalaclava", "Tango_clanHelmet", "Tango_clanPlatecarrier", "Tango_clanGloves", "Tango_clanAssaultVest", "Tango_clanPants"};
    string Tango_Gun = "Gold_AKM";
    string Tango_Sidearm = "CPB_M300_Black";
    autoptr TStringArray Tango_SideArm_Attachments = {"DA_Scope", "CPB_M300_Magazine"};
    autoptr TStringArray Tango_Attachments = {"Ki_Mag_AKMCoupled_30Rnd", "AK_WoodHndgrd_Camo", "AK_WoodBttstck_Camo"};
    autoptr TStringArray Tango_Mags = {"CPB_M300_Magazine", "CPB_M300_Magazine", "Ki_Mag_AKMCoupled_30Rnd", "Ki_Mag_AKMCoupled_30Rnd", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};
    
        /*
     * Name: BoombaClass
     * Primary Weapon: AKM
     * Weapon Attachments: CQB Buttstock, ACOG Scope, RIS Handguard
     * Sidearm Weapon: SVD
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Boomba_Clothing = {"Renegade_MilitaryCamo_BalaclavaMask", "Tango_clanHelmet", "Tango_clanPlatecarrier", "Renegade_MilitaryCamoGloves", "Tango_clanAssaultVest", "Tango_clanPants"};
    string Boomba_Gun = "CPB_AR15_Green";
    string Boomba_Sidearm = "CPB_M300_Black";
    autoptr TStringArray Boomba_SideArm_Attachments = {"DA_Scope", "CPB_M300_Magazine"};
    autoptr TStringArray Boomba_Attachments = {"MAG_STANAGCoupled_30Rnd", "CPB_HKE1_Bttstck_Tan", "CPB_AR15RIS_Black"};
    autoptr TStringArray Boomba_Mags = {"CPB_M300_Magazine", "CPB_M300_Magazine", "MAG_STANAGCoupled_30Rnd", "MAG_STANAGCoupled_30Rnd", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};
    
            /*
     * Name: Hazoe Class
     * Primary Weapon: AKM
     * Weapon Attachments: CQB Buttstock, ACOG Scope, RIS Handguard
     * Sidearm Weapon: SVD
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Hazoe_Clothing = {"Renegade_MilitaryCamo_BalaclavaMask", "Tango_clanHelmet", "Tango_clanPlatecarrier", "Renegade_MilitaryCamoGloves", "Tango_clanAssaultVest", "Tango_clanPants"};
    string Hazoe_Gun = "Gold_M4";
    string Hazoe_Sidearm = "CPB_AX50_Tan";
    autoptr TStringArray Hazoe_SideArm_Attachments = {"DA_Scope", "CPB_AX50_Magazine"};
    autoptr TStringArray Hazoe_Attachments = {"M4_CQBBttstck_Black", "ACOGOptic", "MAG_STANAGCoupled_30Rnd", "M4_RISHndgrd_Black"};
    autoptr TStringArray Hazoe_Mags = {"MAG_STANAGCoupled_30Rnd", "MAG_STANAGCoupled_30Rnd", "CPB_AX50_Magazine", "CPB_AX50_Magazine", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};

    /*
     * Name: Submachine Gun Class
     * Primary Weapon: MP5K
     * Weapon Attachments: Rail Handguard, Buttstock, M69 Optic
     * Sidearm Weapon: IJ70
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Submachine_Clothing = {"Renegade_MilitaryCamo_BalaclavaMask", "Renegade_BlueGrunge_2Helmet", "Tango_clanPlatecarrier", "Renegade_MilitaryCamoGloves", "YRTSK_VansSneakers_Black", "Tango_clanPants"};
    string SubMachineGun_Gun = "CPB_AR15_Green";
    string SubMachineGun_Sidearm = "CPB_AX50_Black";
    autoptr TStringArray SubMachineGun_SideArm_Attachments = {"DA_Scope", "CPB_AX50_Magazine"};
    autoptr TStringArray SubmachineGun_Attachments = {"MAG_STANAGCoupled_30Rnd", "CPB_HKE1_Bttstck_Tan", "CPB_AR15RIS_Black"};
    autoptr TStringArray SubmachineGun_Mags = {"MAG_STANAGCoupled_30Rnd", "MAG_STANAGCoupled_30Rnd", "CPB_AX50_Magazine", "CPB_AX50_Magazine", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};

    /*
     * Name: Sniper Class
     * Primary Weapon: SVD
     * Weapon Attachments: PU Scope
     * Sidearm Weapon: IJ70
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Sniper_Clothing = {"Tango_clanBalaclava", "Renegade_BlackYellowPixelHelmet", "Tango_clanPlatecarrier", "Tango_clanGloves", "YRTSK_VansSneakers_Black", "Tango_clanPants"};
    string Sniper_Gun = "CPB_AR15_Tan";
    string Sniper_Sidearm = "Gold_SVD";
    autoptr TStringArray Sniper_SideArm_Attachments = {"AD_Pilad_B13", "Ki_Mag_SVDCoupled_10Rnd"};
    autoptr TStringArray Sniper_Attachments = {"MAG_STANAGCoupled_30Rnd", "CPB_HKE1_Bttstck_Tan", "CPB_AR15RIS_Black"};
    autoptr TStringArray Sniper_Mags = {"Ki_Mag_SVDCoupled_10Rnd", "Ki_Mag_SVDCoupled_10Rnd", "MAG_STANAGCoupled_30Rnd", "MAG_STANAGCoupled_30Rnd", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};
    
        /*
     * Name: Neo Class
     * Primary Weapon: SVD
     * Weapon Attachments: PU Scope
     * Sidearm Weapon: IJ70
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Neo_Clothing = {"Tango_clanBalaclava", "Renegade_BlueGrunge_2Helmet", "Tango_clanPlatecarrier", "Tango_clanGloves", "YRTSK_VansSneakers_Black", "Tango_clanPants"};
    string Neo_Gun = "Gold_AKM";
    string Neo_Sidearm = "CPB_AWM_Green";
    autoptr TStringArray Neo_SideArm_Attachments = {"HuntingOptic", "CPB_AWM_Magazine_10Rnd"};
    autoptr TStringArray Neo_Attachments = {"Ki_Mag_AKMCoupled_30Rnd", "AK_WoodHndgrd_Camo", "AK_WoodBttstck_Camo"};
    autoptr TStringArray Neo_Mags = {"CPB_AWM_Magazine_10Rnd", "CPB_AWM_Magazine_10Rnd", "Ki_Mag_AKMCoupled_30Rnd", "Ki_Mag_AKMCoupled_30Rnd", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};
    
         /*
     * Name: Shaze Class
     * Primary Weapon: SVD
     * Weapon Attachments: PU Scope
     * Sidearm Weapon: IJ70
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Shaze_Clothing = {"Tango_clanBalaclava", "Renegade_BlueGrunge_2Helmet", "Tango_clanPlatecarrier", "Tango_clanGloves", "YRTSK_VansSneakers_Black", "Tango_clanPants"};
    string Shaze_Gun = "CPB_AR15_Tan";
    string Shaze_Sidearm = "CPB_ASR338_Tan";
    autoptr TStringArray Shaze_SideArm_Attachments = {"HuntingOptic", "CPB_ASR338_Magazine"};
    autoptr TStringArray Shaze_Attachments = {"MAG_STANAGCoupled_30Rnd", "CPB_HKE1_Bttstck_Tan", "CPB_AR15RIS_Black"};
    autoptr TStringArray Shaze_Mags = {"CPB_ASR338_Magazine", "CPB_ASR338_Magazine", "MAG_STANAGCoupled_30Rnd", "MAG_STANAGCoupled_30Rnd", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};
    
        /*
     * Name: Benze Class
     * Primary Weapon: SVD
     * Weapon Attachments: PU Scope
     * Sidearm Weapon: IJ70
     * Sidearm Attachments: Suppressor
    */
    autoptr TStringArray Benze_Clothing = {"Tango_clanBalaclava", "Renegade_BlueGrunge_2Helmet", "Tango_clanPlatecarrier", "Tango_clanGloves", "YRTSK_VansSneakers_Black", "Tango_clanPants"};
    string Benze_Gun = "CPB_SA58_Green";
    string Benze_Sidearm = "CPB_ASR338_Tan";
    autoptr TStringArray Benze_SideArm_Attachments = {"HuntingOptic", "CPB_ASR338_Magazine"};
    autoptr TStringArray Benze_Attachments = {"CPB_SA58_Magazine", "CPB_Bipod_Black"};
    autoptr TStringArray Benze_Mags = {"CPB_ASR338_Magazine", "CPB_ASR338_Magazine", "CPB_SA58_Magazine", "CPB_SA58_Magazine", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};

    /*
      * Name: Medic Class
      * Primary Weapon: FAL
      * Weapon Attachments: Fal_FoldingBttstck, ACOGOptic
      * Sidearm Weapon: IJ70
      * Sidearm Attachments: Suppressor
      * Medical Kit: Bandage, Morphine, Saline, Painkillers
     */
    autoptr TStringArray Medic_Clothing = {"Renegade_MilitaryCamo_BalaclavaMask", "Renegade_ForestGreenHelmet", "Tango_clanPlatecarrier", "Renegade_MilitaryCamoGloves", "YRTSK_VansSneakers_SO_Black", "Tango_clanPants"};
    string Medic_Gun = "Gold_M4";
    string Medic_Sidearm = "M14";
    autoptr TStringArray Medic_Attachments = {"M4_CQBBttstck_Black", "ACOGOptic", "MAG_STANAGCoupled_30Rnd", "M4_RISHndgrd_Black"};
    autoptr TStringArray Medic_SideArm_Attachments = {"Ki_Mag_M14Coupled_10Rnd", "AD_Pilad"};
    string Medical_Supply_Case = "";
    autoptr TStringArray Medical_Supplies = {""};
    autoptr TStringArray Medic_Mags = {"Ki_Mag_M14Coupled_10Rnd", "Ki_Mag_M14Coupled_10Rnd", "MAG_STANAGCoupled_30Rnd", "MAG_STANAGCoupled_30Rnd", "GPB_Stims_HealthRestore", "GPB_Stims_HealthBoost"};

//  General Items which everyone will receive on spawn; regardless of class. "MAG_STANAG_60Rnd",
    autoptr TStringArray Utilities = {"M67Grenade", "M67Grenade", "M67Grenade", "FlashGrenade", "FlashGrenade", "M18SmokeGrenade_Purple", "M18SmokeGrenade_Yellow", "M18SmokeGrenade_Red_Contaminated", "GPB_Stims_HemostaticDrug", "Epinephrine", "EpoxyPutty", "MORPHINE", "Rangefinder", "Renegade_ExtendedBattery", "Renegade_Bandage", "Petrollighter", "SALINEBAGIV", "Ammo_", "Ammo_556x45", "Ammo_308Win", "Ammo_762x54", "Ammo_762x39", "CPB_Ammo_408", "CPB_Ammo_338", "Ammo_9x39AP", "CPB_Ammo_50Cal", "VTR_SigSauerTango", "HuntingOptic", "AD_Pilad_B13", "Grenade_ChemGas", "Gold_Winchester70"};
    autoptr TStringArray Uniform = {"Renegade_MilitaryCamo_BalaclavaMask", "Tango_clanJacket",     "Tango_clanPlatecarrier", "Renegade_MilitaryCamoGloves", "TacticalGoggles", "MilitaryBelt", "YRTSK_VansSneakers_SO_Black"};
    

    // Melee Weapons
    autoptr TStringArray oneHanders = {"WeaponCleaningKit"};

    /*
     * End of Config:
     *   Do not change anything below unless you understand what you are doing....
    */

    autoptr TStringArray batteryCompatible = {"Rangefinder", "VTR_SigSauerTango"};

    /*
     * @function addMags
     * @discussion Adds mags to players inventory
     *
     * @param    player: Instance Of Player
     * @param    magArray: Collection mag names
     * @param    count: Number of each mag which needs to be given.
     * @param    toQuickBar: Should be added to the quick bar, or not.
     */
    int magCount = 2;
    void addMags(PlayerBase player, TStringArray magArray, int count, bool toQuickBar) {
        if (count < 1 || magArray.Count() < 1)
            return;

        for(int x = 0; x < magArray.Count(); x++) {
            for (int i = 0; i < count; i++) {
                EntityAI mag = player.GetInventory().CreateInInventory(magArray.Get(x));
                if (toQuickBar)
                    if(x != 1) {
                        player.SetQuickBarEntityShortcut(mag, x + i + 2, true);
                    }else{
                        player.SetQuickBarEntityShortcut(mag, x + i + 10, true);
                    }
            }
        }
    }

    /*
     * @function dress_player
     * @abstract Gives player class related clothing.
     * @discussion This function puts choosen class clothing on the player.
     *
     * @param    player: Instance Of Player
     * @param    class_clothes: Collection of class clothing names
     * @param    general_items: Collection of general items which will also be given to the player
     */
    void dress_player(PlayerBase player, TStringArray class_clothes, TStringArray general_items){
        for(int i = 0; i < class_clothes.Count(); i++)
            player.GetInventory().CreateAttachment(class_clothes.Get(i));

        for(int x = 0; x < general_items.Count(); x++)
            player.GetInventory().CreateAttachment(general_items.Get(x));
    }
    
    /*
     *  @function   arm_player
     *  @abstract   Arms player with weapon, and adds attachments to weapon.
     *  @discussion This function creates a weapon, goes through all the attachments and attaches them,
     *                while checking if it needs a battery.
     *  @param      player: Instance of Player
     *  @param      weapon_name: Name of weapon to be given
     *  @param      gunAttachments: Collection of attachment names to be added to weapon
     *  @result     EntityAI: weapon
     */
    EntityAI arm_player(PlayerBase player, string weapon_name, TStringArray gunAttachments){
        EntityAI weapon = player.GetHumanInventory().CreateInHands(weapon_name);
        for(int i = 0; i < gunAttachments.Count(); i++){
            EntityAI attachment = weapon.GetInventory().CreateAttachment(gunAttachments.Get(i));
            for (int x = 0; x < batteryCompatible.Count(); x++){
                if(batteryCompatible.Get(x).Contains(gunAttachments.Get(i)))
                    attachment.GetInventory().CreateAttachment("Battery9V");
            }
        }
        return weapon;
    }

    EntityAI arm_player_secondary(PlayerBase player, string weapon_name, TStringArray secondaryAttachments){
        EntityAI weapon = player.GetInventory().CreateInInventory(weapon_name);
        for(int i = 0; i < secondaryAttachments.Count(); i++){
            EntityAI attachment = weapon.GetInventory().CreateAttachment(secondaryAttachments.Get(i));
            for (int x = 0; x < batteryCompatible.Count(); x++){
                if(batteryCompatible.Get(x).Contains(secondaryAttachments.Get(i)))
                    attachment.GetInventory().CreateAttachment("Battery9V");
            }
        }
        return weapon;
    }

    /*
     *  @function   give_utilities
     *  @discussion Added a backpack to the players back and fills it with provided items.
     *
     *  @param      player: Instance of Player
     *  @param      util: Collection of utility items names to be added to the backpack
     *  @param      backpack: Backpack item name which items will be stored, and will be added to players back.
     */
    void give_utilities(PlayerBase player, TStringArray util, string backpack){
        EntityAI backpackEnt = player.GetInventory().CreateAttachment(backpack);
        for (int i = 0; i < util.Count(); i++)
            backpackEnt.GetInventory().CreateInInventory(util.Get(i));
    }

    /*
    *  @function   give_medical
    *  @discussion Puts a bag into players inventory and adds items into the bag.
    *                  This is NOT the same as give_utilities, one adds bag to inventory, one adds bag to player.
    *  @param      player: Instance of Player
    *  @param      bag_name: Name of the bag which will be added to the players inventory and filled with items.
    *  @param      supplies: Collection of items which will be added to the bag.
    */
    void give_medical(PlayerBase player, string bag_name, TStringArray supplies) {
        EntityAI medickit = player.GetInventory().CreateInInventory(bag_name);

        for (int i = 5; i < supplies.Count(); i++)
            medickit.GetInventory().CreateInInventory(supplies.Get(i));
    }

    override PlayerBase CreateCharacter(PlayerIdentity identity, vector pos, ParamsReadContext ctx, string characterName){
        Entity playerEnt;
        playerEnt = GetGame().CreatePlayer(identity, characterName, pos, 0, "NONE");//Creates random player
        Class.CastTo(m_player, playerEnt);

        GetGame().SelectPlayer(identity, m_player);


        return m_player;
    }

    override void StartingEquipSetup(PlayerBase player, bool clothesChosen) {
        player.RemoveAllItems();

        EntityAI primary;
        EntityAI secondary;

        switch (Math.RandomInt(0, 10))  {
            case 0: // Assault
                dress_player(player, Assault_Clothing, Uniform);
                primary = arm_player(player, Assault_Gun, Assault_Attachments);
                secondary = arm_player_secondary(player, Assault_SideArm, Assault_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Assault_Mags, magCount, true);
                break;
            case 1: // Sniper
                dress_player(player, Sniper_Clothing, Uniform);
                primary = arm_player(player, Sniper_Gun, Sniper_Attachments);
                secondary = arm_player_secondary(player, Sniper_Sidearm, Sniper_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Sniper_Mags, magCount, true);
                break;
            case 2: // Submachine Gun
                dress_player(player, Submachine_Clothing, Uniform);
                primary = arm_player(player, SubMachineGun_Gun, SubmachineGun_Attachments);
                secondary = arm_player_secondary(player, SubMachineGun_Sidearm, SubMachineGun_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, SubmachineGun_Mags, magCount, true);
                break;
            case 3: // Medic
                dress_player(player, Medic_Clothing, Uniform);
                primary = arm_player(player, Medic_Gun, Medic_Attachments);
                secondary = arm_player_secondary(player, Medic_Sidearm, Medic_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Medic_Mags, magCount, true);
                give_medical(player, Medical_Supply_Case, Medical_Supplies);
                break;
            case 4: // Tango
                dress_player(player, Tango_Clothing, Uniform);
                primary = arm_player(player, Tango_Gun, Tango_Attachments);
                secondary = arm_player_secondary(player, Tango_Sidearm, Tango_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Tango_Mags, magCount, true);
                break;
            case 5: // Hazoe
                dress_player(player, Hazoe_Clothing, Uniform);
                primary = arm_player(player, Hazoe_Gun, Hazoe_Attachments);
                secondary = arm_player_secondary(player, Hazoe_Sidearm, Hazoe_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Hazoe_Mags, magCount, true);
                break;
            case 6: // Neo
                dress_player(player, Neo_Clothing, Uniform);
                primary = arm_player(player, Neo_Gun, Neo_Attachments);
                secondary = arm_player_secondary(player, Neo_Sidearm, Neo_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Neo_Mags, magCount, true);
                break;
            case 7: // Boomba
                dress_player(player, Boomba_Clothing, Uniform);
                primary = arm_player(player, Boomba_Gun, Boomba_Attachments);
                secondary = arm_player_secondary(player, Boomba_Sidearm, Boomba_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Boomba_Mags, magCount, true);
                break;
            case 8: // Shaze
                dress_player(player, Shaze_Clothing, Uniform);
                primary = arm_player(player, Shaze_Gun, Shaze_Attachments);
                secondary = arm_player_secondary(player, Shaze_Sidearm, Shaze_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Shaze_Mags, magCount, true);
                break;
            case 9: // Benze
                dress_player(player, Benze_Clothing, Uniform);
                primary = arm_player(player, Benze_Gun, Benze_Attachments);
                secondary = arm_player_secondary(player, Benze_Sidearm, Benze_SideArm_Attachments);
                give_utilities(player, Utilities, bag_name);
                addMags(player, Benze_Mags, magCount, true);
                break;
        }
        player.GetInventory().CreateInInventory(oneHanders.GetRandomElement());
        player.SetQuickBarEntityShortcut(primary, 0, true);

        if(secondary != null){
            player.SetQuickBarEntityShortcut(secondary, 1, true);
            player.GetStatWater().Add(4400);
            player.GetStatEnergy().Add(4400);
        }
        
    }
    
};

Mission CreateCustomMission(string path) {
    return new CustomMission();
}

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

×