Jump to content

Ground Item Spawning


Hydromancerx

Recommended Posts

So things are coming together now. However I still have not figured out how to get this to work. Basiclly want I want to do is spawn car items that are "bags". To do this I have a few steps ...

 

Bags on the ground show in the loot window's list of containers.

 

1. The new update allows for large objects to see the inventory inside. A bag that can be opened from the ground, check.

    ResizeWorldIcon     = FALSE,

2. His code allows for normal objects to appear as big as the image provided is. So a large item, check.

table.insert(SuburbsDistributions["Schoolbag"].items, "ShuiYin.SYNSchoolbag");table.insert(SuburbsDistributions["Schoolbag"].items, 500);

3. Spawning items inside the car. Well you can spawn stuff inside bags. I am not sure how you can make your own bag but I assume you can. So items spawn in bags, check.

function YouBetterMakeABackUp(square)    square:AddWorldInventoryItem("Hydrocraft.HCCar", 0.0, 0.0, 0.0);endEvents.LoadGridsquare.Add(YouBetterMakeABackUp

4. The last part is the hard part. Getting the car to spawn on the ground. The code above gives this. Which while hilarious is not going to help if the whole map is covered in cars. In short my question is ..

 

How do I limit where the car spawns? Can i specify what tiles such as streets? What about in a mechanics garage? Please help!

Link to comment
Share on other sites

I know someone posted this before but I cannot find it. What is the code for adding loot spawn to custom bag? if I recall I could not just do this ...

table.insert(SuburbsDistributions["HCNewbag"].items, "Hydrocraft.HCStuff");table.insert(SuburbsDistributions["HCNewbag"].items, 1);

Something about not being able to insert into a table that did not exist yet. But then how do you make the "table" in the first place?

Link to comment
Share on other sites

 

you do this:

require('Items/SuburbsDistributions');

My lua guy says ...

 

"This still isn't the problem.  It's not that we can't get to the table. It's that we can't get the distribution code to recognize our bag as a valid place to populate.  We proved that last night with the 30 alice packs in the store."

 

Note last night we tried to get alice packs to spawn junkitems inside and nothing happened.

	table.insert(SuburbsDistributions["aesthetic"]["counter"].items, "Hydrocraft.HCAlicepack");	table.insert(SuburbsDistributions["aesthetic"]["counter"].items, 500);	-- Add items for Custom Bag	Hydrocraft.HCAlicepack = {rolls = 2, items = {"Hydrocraft.HCJunk", 5,},}	table.insert(SuburbsDistributions, Hydrocraft.HCAlicepack);

Any ideas?

 

Link to comment
Share on other sites

The Suburbsdistribution object has this structure:

SuburbsDistribution[ROOMTYPE][CONTAINERTYPE]-- orSuburbsDistribution[CONTAINERTYPE]

So, unless "aesthetic" is a room declaration (like "conveniencestore", "burgerkitchen" or "bedroom") that won't work.

 

Also, this:

    Hydrocraft.HCAlicepack = {rolls = 2, items = {"Hydrocraft.HCJunk", 5,},}    table.insert(SuburbsDistributions, Hydrocraft.HCAlicepack);

is going to add an anonymous object into SuburbsDistribution. I think you should try it this way:

    Hydrocraft.HCAlicepack = {rolls = 2, items = {"Hydrocraft.HCJunk", 5,}}    SuburbsDistributions["HCAlicepack"] = Hydrocraft.HCAlicepack;
Link to comment
Share on other sites

 

 

you do this:

require('Items/SuburbsDistributions');

My lua guy says ...

 

"This still isn't the problem.  It's not that we can't get to the table. It's that we can't get the distribution code to recognize our bag as a valid place to populate.  We proved that last night with the 30 alice packs in the store."

 

Note last night we tried to get alice packs to spawn junkitems inside and nothing happened.

	table.insert(SuburbsDistributions["aesthetic"]["counter"].items, "Hydrocraft.HCAlicepack");	table.insert(SuburbsDistributions["aesthetic"]["counter"].items, 500);	-- Add items for Custom Bag	Hydrocraft.HCAlicepack = {rolls = 2, items = {"Hydrocraft.HCJunk", 5,},}	table.insert(SuburbsDistributions, Hydrocraft.HCAlicepack);

Any ideas?

 

Have you tried adding to the suburb distribution file itself a new table mr Hydro? im sure it will not work on location based distribution but bags might be able to work if we are lucky.

 

Tried the above but did not work :( (i made a new container "SYNCarBagageItem" and added it to the suburbdistribution thing and scripts item, then i make another info item "SYNCarBagage" in my distribution mod also script item and place it inside the "SYNCarBagageItem" bag and failed) Error was on distribution being in a non table thing.

 

My solution: sacrifice 1 of the bags and substitute it with another: so like you can sacrifice Tote Bag or Garbage Bag and use its distribution to your Car Bagage. Then what should happen is you can distribute in the garbage or tote bag and get it to spawn in your car.

 

Oops scratch that garbage bag (its used on recipes)

Link to comment
Share on other sites

"aesthetic" worked fine. It is the room name for the Hair Salon. The bottom code is what we were having issues with.

 

Ah, okay. Have you tried this:

    require('Items/SuburbsDistributions');    Hydrocraft.HCAlicepack = {rolls = 2, items = {"Hydrocraft.HCJunk", 5}}    SuburbsDistributions["HCAlicepack"] = Hydrocraft.HCAlicepack;
Link to comment
Share on other sites

What do you mean by "Container distribution tag"?

Generally, the SuburbsDistribution must be populated before the area is first spawned. Items are placed in containers the first time the container is spanwed into the game world, not when the container is first accessed!

Link to comment
Share on other sites

What do you mean by "Container distribution tag"?

Generally, the SuburbsDistribution must be populated before the area is first spawned. Items are placed in containers the first time the container is spanwed into the game world, not when the container is first accessed!

Since bag like container are spawned inside wardobes and many other places. They are created at the time we open the wardrobe. i believe they then spawn random generated item at that very moment. So if let say you can make the alicepack do that with your above code then it should be possible to replicate with any other bags in game. Btw you can test this by installing my distributionXposed mod. I have tried this on a load game and it will still spawn my tags even if the world have been created days before
Link to comment
Share on other sites

Huh, I might have to try this. The way I read the code is that LoadGridsquarePerformanceWorkaround.LoadGridsquare is called from IsoChunk.doLoadGridsquare which is called by the Worldstreamer class.

LoadGridsquarePerformanceWorkaround.LoadGridsquare then calls Luas ItemPicker.fillContainer object for every object in the streamed Chunk. This would mean that objects are placed when the map is first streamed in, not when a container is opened. This also matches observations I made in the SecondhandLoots mod.

 

Are you absolutely sure that items are spawned only when containers are first accessed? Cabinets and trash cans? Or do you mean containers like tote bags and garbage bags?

Link to comment
Share on other sites

Huh, I might have to try this. The way I read the code is that LoadGridsquarePerformanceWorkaround.LoadGridsquare is called from IsoChunk.doLoadGridsquare which is called by the Worldstreamer class.

LoadGridsquarePerformanceWorkaround.LoadGridsquare then calls Luas ItemPicker.fillContainer object for every object in the streamed Chunk. This would mean that objects are placed when the map is first streamed in, not when a container is opened. This also matches observations I made in the SecondhandLoots mod.

 

Are you absolutely sure that items are spawned only when containers are first accessed? Cabinets and trash cans? Or do you mean containers like tote bags and garbage bags?

 

I am pretty sure. i will also try and test it again today. the way to test it is:

1. make a new game and spawn.

2. Without opening a container exit game

3. Turn on my DistributionXposed mod

4. Continue game and open any container.

 

I have tested the above and here is my findings:

1. The house i spawned in did not contain my distribution tags

2. The house next door also did not contain my distribution tag

3. The 2nd house after the one i spawned in contained my distribution tag.

 

My current analysis is that as you said maps were loaded and items put in place but at a fixed radius. so out of that radius all items are not spawned yet. Therefore my thought that items spawn at the 1st time a container is opened is wrong Lol. It spawned as soon as i enter the area.

Link to comment
Share on other sites

 

"aesthetic" worked fine. It is the room name for the Hair Salon. The bottom code is what we were having issues with.

 

Ah, okay. Have you tried this:

    require('Items/SuburbsDistributions');    Hydrocraft.HCAlicepack = {rolls = 2, items = {"Hydrocraft.HCJunk", 5}}    SuburbsDistributions["HCAlicepack"] = Hydrocraft.HCAlicepack;

 

Hi mr BlindCoder: i have tried the above code but it did not work, maybe i placed it wrong or something.

 

 

 

 

 

you do this:

require('Items/SuburbsDistributions');

My lua guy says ...

 

"This still isn't the problem.  It's not that we can't get to the table. It's that we can't get the distribution code to recognize our bag as a valid place to populate.  We proved that last night with the 30 alice packs in the store."

 

Note last night we tried to get alice packs to spawn junkitems inside and nothing happened.

	table.insert(SuburbsDistributions["aesthetic"]["counter"].items, "Hydrocraft.HCAlicepack");	table.insert(SuburbsDistributions["aesthetic"]["counter"].items, 500);	-- Add items for Custom Bag	Hydrocraft.HCAlicepack = {rolls = 2, items = {"Hydrocraft.HCJunk", 5,},}	table.insert(SuburbsDistributions, Hydrocraft.HCAlicepack);

Any ideas?

 

Have you tried adding to the suburb distribution file itself a new table mr Hydro? im sure it will not work on location based distribution but bags might be able to work if we are lucky.

 

Tried the above but did not work :( (i made a new container "SYNCarBagageItem" and added it to the suburbdistribution thing and scripts item, then i make another info item "SYNCarBagage" in my distribution mod also script item and place it inside the "SYNCarBagageItem" bag and failed) Error was on distribution being in a non table thing.

 

My solution: sacrifice 1 of the bags and substitute it with another: so like you can sacrifice Tote Bag or Garbage Bag and use its distribution to your Car Bagage. Then what should happen is you can distribute in the garbage or tote bag and get it to spawn in your car.

 

Oops scratch that garbage bag (its used on recipes)

 

 

Good news and bad news:

 

The good news is i can spawn stuff in an Alice pack that i made with id: SYNAlicepack. How did i do this > it seems on my quote above i am using a bag "SYNCarBagageItem" inside a ShuiYin module. so when i put it inside the suburbdistribution.lua its not recognised because there is no "Base" module "SYNCarBagageItem". i tried again but this time i moved my bag to a Base module instead and the "not table error" dissapeared and the game loads normally with no error

 

Now for the bad news: or semi good news, i have managed to spawn stuff using the insert.table method. but somehow its random even if i set the spawn percentage at 500 <-- this ussually guarantees a spawn. i do find some of the custom bags that i make containing stuff that i place using insert table. Also i edited directly inside the suburbdistribution file and it seems whenever it does not spawn the content than its blank, but when they do spawn it will spawn together (both the one i input directly and the one using insert table method)

 

Final update: i found out the culprit that is causing it. seems i copied inside the suburbdistribution file the table of Garbagebag and just changed the item name to SYNAlicepack. Inside the garbagebag table contains the "FillRand = 3" property. This makes it random maybe by 1/3, i change it to "FillRand =0" and it spawns 100% all the time.

Link to comment
Share on other sites

@ShuiYin

 

My lua coder says your results are exactly what he was assuming. Then goes on to say ...

 

"The actual under laying code that does the distribution looks for at the string literal and just appends Base. to it. Hence why we can't add new bags without making it part of the Base module."


 

Link to comment
Share on other sites

@ShuiYin

 

My lua coder says your results are exactly what he was assuming. Then goes on to say ...

 

"The actual under laying code that does the distribution looks for at the string literal and just appends Base. to it. Hence why we can't add new bags without making it part of the Base module."

 

 

That's not actually how this works, assuming I have the correct code here.

In media/server/Items/ItemPicker.lua on line 195 ff.:

                        -- if the item is a container, we look to spawn item inside it                        if(SuburbsDistributions[item:getType()]) then                            if instanceof(item, "InventoryContainer") and doItemContainer and ZombRand(SuburbsDistributions[item:getType()].fillRand) == 0 then                                ItemPicker.rollContainerItem(item, character, SuburbsDistributions[item:getType()]);                            end                        end

This uses item:getType() which - for an item called Foo.NewBag - would return "NewBag". If the code used item:getFullType() then you would get "Foo.NewBag". So using this should work:

require "Items/SuburbsDistributions"; SuburbsDistribution["NewBag"] = {rolls = 10,items = {"Foo.Bar", 50},fillRand = 5}
Link to comment
Share on other sites

 

So in testing this code worked for spawning items in bags!

	-- Add items for Custom BagSuburbsDistributions["HCAlicepack"] = {rolls = 2,items = {"Hydrocraft.HCJunk", 500,},fillRand = 5,};

 

 

 

@ShuiYin

 

My lua coder says your results are exactly what he was assuming. Then goes on to say ...

 

"The actual under laying code that does the distribution looks for at the string literal and just appends Base. to it. Hence why we can't add new bags without making it part of the Base module."

 

 

That's not actually how this works, assuming I have the correct code here.

In media/server/Items/ItemPicker.lua on line 195 ff.:

                        -- if the item is a container, we look to spawn item inside it                        if(SuburbsDistributions[item:getType()]) then                            if instanceof(item, "InventoryContainer") and doItemContainer and ZombRand(SuburbsDistributions[item:getType()].fillRand) == 0 then                                ItemPicker.rollContainerItem(item, character, SuburbsDistributions[item:getType()]);                            end                        end

This uses item:getType() which - for an item called Foo.NewBag - would return "NewBag". If the code used item:getFullType() then you would get "Foo.NewBag". So using this should work:

require "Items/SuburbsDistributions"; SuburbsDistribution["NewBag"] = {rolls = 10,items = {"Foo.Bar", 50},fillRand = 5}

 

Aah i see. i also didnt try to put the ShuiYin module before my item name in the table before that is why only work on base module items. so we still can spawn item even if we use our own module.

Link to comment
Share on other sites

  • 2 weeks later...
function YouBetterMakeABackUp(square)    square:AddWorldInventoryItem("Hydrocraft.HCCar", 0.0, 0.0, 0.0);endEvents.LoadGridsquare.Add(YouBetterMakeABackUp

4. The last part is the hard part. Getting the car to spawn on the ground. The code above gives this. Which while hilarious is not going to help if the whole map is covered in cars. In short my question is ..

 

How do I limit where the car spawns? Can i specify what tiles such as streets? What about in a mechanics garage? Please help!

 

Then add a check to spawn only x number of cars with y percent chance and you're set.

 

I just did that, but now I have the problem that additional items will spawn whenever Events.LoadGridsquare fires. If i keep running up and down a street, the function will flood the street with items over time.

 

I tried to use IsoGridSquare.getHourLastSeen() to make each square spawn items only once, but that function always returns "0". Do I have to use setHourSeenToCurrent()  first to make this work? Or is there a better way to make sure each square only tries to spawn items once?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...