StreetkillnHD 0 Posted April 10, 2023 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
Sid Debian 132 Posted April 12, 2023 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
StreetkillnHD 0 Posted April 14, 2023 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
NoBeansForMe 14 Posted April 14, 2023 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. 1 Share this post Link to post Share on other sites
Sid Debian 132 Posted April 18, 2023 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
takumo@gmail.com 0 Posted June 25, 2023 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
NoBeansForMe 14 Posted June 25, 2023 No, sorry, I haven't looked into it any more. Share this post Link to post Share on other sites
Sid Debian 132 Posted June 25, 2023 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). 1 Share this post Link to post Share on other sites
Skarblah 0 Posted April 5 (edited) 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. Edited August 8 by Skarblah Share this post Link to post Share on other sites
Skarblah 0 Posted August 8 Hi has anyone solved the issue of adding ammo into the chamber on player spawn? I’m still having trouble. Appreciate if someone has a solution. Thanks Share this post Link to post Share on other sites
Sid Debian 132 Posted August 10 On 8/9/2024 at 2:29 AM, Skarblah said: Hi has anyone solved the issue of adding ammo into the chamber on player spawn? I’m still having trouble. Appreciate if someone has a solution. Thanks In this topic I'd solved that "issue" already long time ago. It's nothing hard or strange. But required some searching and exploring. Task is quite simple if you was not so lazy (perhaps) you could resolve it by your own hands. Well I even posted here the code for most of firearms except the supporting of revolvers charging (bad mechanics in my understanding). But it will be resolved when devs will find that any kind of revolver has 1 barrel and many slots for ammunition (right now revolver logic has many barrels and in each of barrels slotted 1 ammo). Share this post Link to post Share on other sites