DayZ
DayZ > General Discussions > Topic Details
FurryKeidran Sep 26, 2019 @ 4:16pm
Init.c editing: changing spawn items
Basically on my private server I've added a crap ton of stuff I spawn with, just to kind of give me a good foot up when starting (canteen, gun, more food, etc). I first added clothes, backpacks, a vest, and I thought that by spawning them in first I could add more stuff, but it seems after the first few items fill up the pants inventory nothing else spawns. Is there another command I should be using instead to put items in a specific location? Like have some items in pants, some in jacket, some in backpack, etc?
Thanks,
Mark
< >
Showing 1-15 of 17 comments
SmashT Sep 26, 2019 @ 5:28pm 
What your code look like at the moment?
FurryKeidran Sep 27, 2019 @ 6:54am 
Originally posted by SmashT:
What your code look like at the moment?
https://pastebin.com/TVe8SjzM
basically it's just a bunch of
"GetInventory().CreateInInventory('");"
for everything, clothes, items, etc. Before everything I have "player.RemoveAllItems();" to hopefully take everything out. I've also removed the tactical shirt. So basically I'm wondering how to add stuff in the jacket and vest, and if I can't, how can I spawn stuff around the player?
One more question, is there a way to add multiples of something? Like instead of 3 lines putting a pistol mag in the inventory can I do something like "x.quantity(3);"?
ribeye007 (Banned) Sep 27, 2019 @ 7:57am 
add as attachments or something like this //Light Gunner
itemEnt = player.GetInventory().CreateInInventory("AthleticShoes_Black"); itemBs = ItemBase.Cast(itemEnt);
pGun = player.GetInventory().CreateInInventory("MP5K"); itemBs = ItemBase.Cast(itemEnt); // added the gun before any backpacks so attachments would be added to the gun and not in the players inventory
itemEnt = player.GetInventory().CreateInInventory("MP5_RailHndgrd"); itemBs = ItemBase.Cast(itemEnt); //doing this before adding inventory spaces ensured the attachment was on the gun by default
itemEnt = player.GetInventory().CreateInInventory("MP5k_StockBttstck"); itemBs = ItemBase.Cast(itemEnt); // same thing with the buttstock for the gun
itemEnt = player.GetInventory().CreateInInventory("MP5_Compensator"); itemBs = ItemBase.Cast(itemEnt); // and the compensator
itemEnt = player.GetInventory().CreateInInventory("BoonieHat_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("TrackSuitJacket_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("TrackSuitPants_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("Mag_MP5_30Rnd"); itemBs = ItemBase.Cast(itemEnt); // note that when spawnin players with mags, they are full by default
player.SetQuickBarEntityShortcut(itemEnt, 1, true);
itemEnt = player.GetInventory().CreateInInventory("Mag_MP5_30Rnd"); itemBs = ItemBase.Cast(itemEnt);
player.SetQuickBarEntityShortcut(itemEnt, 2, true);
itemEnt = player.GetInventory().CreateInInventory("Mag_MP5_30Rnd"); itemBs = ItemBase.Cast(itemEnt);
player.SetQuickBarEntityShortcut(itemEnt, 3, true);
itemEnt = player.GetInventory().CreateInInventory("Ammo_9x19"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("HighCapacityVest_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("TacticalBaconCan_Opened"); itemBs = ItemBase.Cast(itemEnt);

player.SetQuickBarEntityShortcut(pGun, 0, true);
break;
SmashT Sep 27, 2019 @ 9:24am 
Originally posted by FurryKedrian:
Originally posted by SmashT:
What your code look like at the moment?
https://pastebin.com/TVe8SjzM

Thanks, I’ll take a look when I get home, been a while since I used loadout scripts so not sure if the code I was using still works.
Last edited by SmashT; Sep 27, 2019 @ 9:52am
Smokey Sep 27, 2019 @ 9:55am 
Originally posted by FurryKedrian:
Originally posted by SmashT:
What your code look like at the moment?
https://pastebin.com/TVe8SjzM
basically it's just a bunch of
"GetInventory().CreateInInventory('");"
for everything, clothes, items, etc. Before everything I have "player.RemoveAllItems();" to hopefully take everything out. I've also removed the tactical shirt. So basically I'm wondering how to add stuff in the jacket and vest, and if I can't, how can I spawn stuff around the player?
One more question, is there a way to add multiples of something? Like instead of 3 lines putting a pistol mag in the inventory can I do something like "x.quantity(3);"?

Initially looking at this all the items just end up in the inventory correct ??

you also appear to have some excess lines such as:

string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" }; int rndIndex = Math.RandomInt(0, 4); itemEnt = itemTop.GetInventory().CreateInInventory(chemlightArray[rndIndex]); SetRandomHealth(itemEnt); rand = Math.RandomFloatInclusive(0.0, 1.0); if ( rand < 0.35 ) itemEnt = player.GetInventory().CreateInInventory("Apple"); else if ( rand > 0.65 ) itemEnt = player.GetInventory().CreateInInventory("Pear"); else itemEnt = player.GetInventory().CreateInInventory("Plum"); SetRandomHealth(itemEnt); */ player.RemoveAllItems(); itemEnt = player.GetInventory().CreateInInventory("ChemLight_White"); itemEnt = player.GetInventory().CreateInInventory("Apple"); itemEnt = player.GetInventory().CreateInInventory("Pear"); itemEnt = player.GetInventory().CreateInInventory("Plum");

where if you just removed the rand = Math from the first set of foods you would not need the second set and have it read:

string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" }; int rndIndex = Math.RandomInt(0, 4); itemEnt = itemTop.GetInventory().CreateInInventory(chemlightArray[rndIndex]); SetRandomHealth(itemEnt); itemEnt = player.GetInventory().CreateInInventory("Apple"); itemEnt = player.GetInventory().CreateInInventory("Pear"); itemEnt = player.GetInventory().CreateInInventory("Plum"); SetRandomHealth(itemEnt); */

Or even:

string chemlightArray[] = { "Chemlight_White", "Chemlight_Yellow", "Chemlight_Green", "Chemlight_Red" }; int rndIndexCL = Math.RandomInt(0, 4); itemEnt = itemTop.GetInventory().CreateInInventory(chemlightArray[rndIndexCL]); SetRandomHealth(itemEnt); string FoodArray[] = { "Apple", "Pear", "Plum", "Tomato" }; int rndIndexFood = Math.RandomInt(0, 4); itemEnt = itemTop.GetInventory().CreateInInventory(FoodArray[rndIndexFood]);

However the above FoodArray will only pick from one of the food items.


Note: i'm only glancing over your init file right now as i'm still working so forgive any formatting or typos i've made in my examples.

Edit: altered typo in rndindex definitions.
Last edited by Smokey; Sep 27, 2019 @ 11:49am
Smokey Sep 27, 2019 @ 10:02am 
Originally posted by ribeye007:
add as attachments or something like this //Light Gunner
itemEnt = player.GetInventory().CreateInInventory("AthleticShoes_Black"); itemBs = ItemBase.Cast(itemEnt);
pGun = player.GetInventory().CreateInInventory("MP5K"); itemBs = ItemBase.Cast(itemEnt); // added the gun before any backpacks so attachments would be added to the gun and not in the players inventory
itemEnt = player.GetInventory().CreateInInventory("MP5_RailHndgrd"); itemBs = ItemBase.Cast(itemEnt); //doing this before adding inventory spaces ensured the attachment was on the gun by default
itemEnt = player.GetInventory().CreateInInventory("MP5k_StockBttstck"); itemBs = ItemBase.Cast(itemEnt); // same thing with the buttstock for the gun
itemEnt = player.GetInventory().CreateInInventory("MP5_Compensator"); itemBs = ItemBase.Cast(itemEnt); // and the compensator
itemEnt = player.GetInventory().CreateInInventory("BoonieHat_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("TrackSuitJacket_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("TrackSuitPants_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("Mag_MP5_30Rnd"); itemBs = ItemBase.Cast(itemEnt); // note that when spawnin players with mags, they are full by default
player.SetQuickBarEntityShortcut(itemEnt, 1, true);
itemEnt = player.GetInventory().CreateInInventory("Mag_MP5_30Rnd"); itemBs = ItemBase.Cast(itemEnt);
player.SetQuickBarEntityShortcut(itemEnt, 2, true);
itemEnt = player.GetInventory().CreateInInventory("Mag_MP5_30Rnd"); itemBs = ItemBase.Cast(itemEnt);
player.SetQuickBarEntityShortcut(itemEnt, 3, true);
itemEnt = player.GetInventory().CreateInInventory("Ammo_9x19"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("HighCapacityVest_Black"); itemBs = ItemBase.Cast(itemEnt);
itemEnt = player.GetInventory().CreateInInventory("TacticalBaconCan_Opened"); itemBs = ItemBase.Cast(itemEnt);

player.SetQuickBarEntityShortcut(pGun, 0, true);
break;


I don't see where you define pGun🤔🤔🤔🤔
Last edited by Smokey; Sep 27, 2019 @ 10:02am
Smokey Sep 27, 2019 @ 12:55pm 
So i've taken a more in depth look at your init.c file and this is what i'm spotting.



Originally posted by FurryKedrian:
I first added clothes, backpacks, a vest

you have the right idea with player.RemoveAllItems(); just in the wrong place ( at least i see it as being in the wrong place as you was adding items just to remove them with that ).

If you use it here instead:
EntityAI itemTop; EntityAI itemEnt; ItemBase itemBs; float rand; player.RemoveAllItems();

That will remove the random generated ones / chosen clothing.

On to the clothing you want, create a line space after removing the clothes and create your outfit in the same way as you are inventory items ( if you want the option of putting specific items into a backpack or something you will need to alter the way you create / add the items ).

Just adding clothing without the option of adding loot to a specific piece of clothing do:
player.RemoveAllItems(); itemEnt = player.GetInventory().CreateInInventory(""); itemEnt = player.GetInventory().CreateInInventory(""); itemEnt = player.GetInventory().CreateInInventory(""); itemEnt = player.GetInventory().CreateInInventory(""); itemEnt = player.GetInventory().CreateInInventory("");

To have the ability to set loot into a specific piece of clothing you will need to do:
EntityAI DEFINECLOTHINGHERE = player.GetInventory().CreateInInventory("");

so you can spawn the loot item to that location later by doing:
itemEnt = DEFINECLOTHINGHERE.GetInventory().CreateInInventory("");


Edit: I can help further if you would like just add me.
Last edited by Smokey; Sep 27, 2019 @ 12:56pm
FurryKeidran Sep 27, 2019 @ 10:01pm 
Originally posted by Smokey:
So I've taken a more in depth look at your init.c file and this is what i'm spotting.

Thank you Smokey, I have programmed in c for a year or two now and have taken a year of comp sci in college, I just don't know the classes and how everything is defined in DZ. Everything you've said makes sense and I think I have the basic functions down for now. If you know any useful functions, or ones you find yourself using a lot I would appreciate it if you could post them, I might find them useful, and even if I don't someone else will.

EDIT: another question, can the EntityAI class be used to attach objects to guns, such as
"EntityAI g1 = ...("FNX45");"
"itemEnt = g1...("PistolSuppressor");"
or is there another way of doing this? Unless you're on right now I'm about to figure it out for myself but it's useful to have someone who already knows lol. Thanks again, by the way. You've been a great help.
Last edited by FurryKeidran; Sep 27, 2019 @ 10:08pm
FurryKeidran Sep 27, 2019 @ 11:17pm 
Originally posted by Smokey:
So

https://pastebin.com/kqR0mcr8

This is my new code, everything is working great! I did need the "remove items" inside the if condition, for some reason when its outside where you suggested it removes all items AFTER they have been placed on the character (I spawned with no items or clothes when using your suggestion, commented the line out and it worked but I had default clothes, so I moved it to the if condition and it worked). The EntityAI does work with guns, belts, everything and it's great, but if you use it with a magazine in a gun it seems to either despawn it or have no ammo, so that's staying out for now.
Smokey Sep 28, 2019 @ 1:54am 
Originally posted by FurryKedrian:
Originally posted by Smokey:
So

https://pastebin.com/kqR0mcr8

This is my new code, everything is working great! I did need the "remove items" inside the if condition, for some reason when its outside where you suggested it removes all items AFTER they have been placed on the character (I spawned with no items or clothes when using your suggestion, commented the line out and it worked but I had default clothes, so I moved it to the if condition and it worked). The EntityAI does work with guns, belts, everything and it's great, but if you use it with a magazine in a gun it seems to either despawn it or have no ammo, so that's staying out for now.

I will have a look at your new file shortly, the weekend is here and my attention can be split though so will take a while haha.

When it comes to adding magazines just adding them as an attachment or in any simple way bugs out the weapon and / or magazine and I suspect you also need to add ammo to the chamber for that weapon ( I was investigating this yesterday but have no solution as of yet ).



Originally posted by FurryKedrian:
EDIT: another question, can the EntityAI class be used to attach objects to guns, such as
"EntityAI g1 = ...("FNX45");"
"itemEnt = g1...("PistolSuppressor");"
or is there another way of doing this? Unless you're on right now I'm about to figure it out for myself but it's useful to have someone who already knows lol. Thanks again, by the way. You've been a great help.

What I have been doing is this:

EntityAI G1 = player.GetInventory().CreateInInventory("");

G1.GetInventory().CreateAttachment("");

When it comes to an attachment that requires another item ( such as a light needing a battery ) create a new class with EntityAI.

Defining a class should allow for attachment of the likes of chemlights and radios to backpacks, granades to vests and even NVGs and lights, with batteries to helmets.
Last edited by Smokey; Sep 28, 2019 @ 1:56am
Smokey Sep 28, 2019 @ 4:55pm 
Originally posted by FurryKedrian:

https://pastebin.com/kqR0mcr8

This is my new code, everything is working great! I did need the "remove items" inside the if condition, for some reason when its outside where you suggested it removes all items AFTER they have been placed on the character (I spawned with no items or clothes when using your suggestion


I may have another solution for the remove items, when I did an initial test it functioned in the place I referenced hence why I'm looking for a different overall solution to that.

Is that init file you posted last the one you intend to use as I noticed your previous one had a mosin not a SVD as the primary weapon, I only ask as I'm thinking of making you a sample, once I iron out a few things with what I'm working on that is 😂😂
ribeye007 (Banned) Sep 28, 2019 @ 5:03pm 
Originally posted by FurryKedrian:
Basically on my private server I've added a crap ton of stuff I spawn with, just to kind of give me a good foot up when starting (canteen, gun, more food, etc). I first added clothes, backpacks, a vest, and I thought that by spawning them in first I could add more stuff, but it seems after the first few items fill up the pants inventory nothing else spawns. Is there another command I should be using instead to put items in a specific location? Like have some items in pants, some in jacket, some in backpack, etc?
Thanks,
Mark
i have a 0-20 load out don't know if you can use but here it is it was written for an event

https://pastebin.com/fA7QEPfL
Smokey Sep 29, 2019 @ 9:27am 
Originally posted by FurryKedrian:
Originally posted by Smokey:
So

https://pastebin.com/kqR0mcr8

This is my new code

I was just thinking instead of this:
//food //printf("%s", "add food"); itemEnt = player.GetInventory().CreateInInventory("Apple"); itemEnt = player.GetInventory().CreateInInventory("Pear"); itemEnt = player.GetInventory().CreateInInventory("Plum");

trying something more like this:
string FoodArray[] = { "Apple", "Pear", "Plum", "Tomato", "Potato", "Zucchini" }; int rndIndexFood = Math.RandomInt(0, 3); itemEnt = player.GetInventory().CreateInInventory(FoodArray[rndIndexFood]); int rndIndexFood1 = Math.RandomInt(3, 6); itemEnt = player.GetInventory().CreateInInventory(FoodArray[rndIndexFood1]); int rndIndexFood2 = Math.RandomInt(0, 6); itemEnt = player.GetInventory().CreateInInventory(FoodArray[rndIndexFood2]);

As this would allow variation instead of the constant three food items.
MRPHYX May 9, 2020 @ 6:53am 
Hey guys,

If you have a random multiple character set in init.c similar to the one above, is there an easy way to spawn a random car at the player? I tried adding different cars per loadout but it doesn't seem to like it, I can only make it work on the one I had done for a single character spawn and a set car. Any help would be awesome, cheers
surviv0r1969 Oct 28, 2020 @ 6:18am 
hi guys so how would i start with a silenced ak, mags, scope and bullets and some food and water, vitamin tab and antibiotics, and purification tabs

with just normal clothing though

for each player that joins my server

many thanks for any help as not too clever at this stuff
Last edited by surviv0r1969; Oct 28, 2020 @ 6:23am
< >
Showing 1-15 of 17 comments
Per page: 15 30 50

DayZ > General Discussions > Topic Details
Date Posted: Sep 26, 2019 @ 4:16pm
Posts: 17