Jump to content

2nd ItemPicker.lua


tommysticks

Recommended Posts

I'm trying to update my Mod and I don't believe anyone has been able to reduce the spawn rate of items in their mods without reducing other in-game items.

 

I believe this is due to SuburbsDistributions and the amount of rolls that are assigned to each container. I believe the lowest "rarity" an Item can have is 1. If I want to increase the rarity of my item and still have it spawn in common places I have to increase the rarity of all items in the container by reducing the rolls to 1.

 

What I've been trying to do is mod the ItemPicker.lua to run two separate ItemPickers. I figured this would be simple by copying ItemPicker, naming it GunPicker, and changing all "ItemPicker"s in the lua to "GunPicker" and having GunPicker choose items from a different distribution file, rather than SuburbsDistro. It turns out that this doesn't work.

 

Is there anyone who knows how I can make a 2nd ItemPicker.lua that will run in conjunction with the in-game one?

 

There is also another way I thought of to make it work, but I know too little to do it myself.

 

If I could make a single ItemPicker.lua run, but choose items from two different distribution files, that would also work.

 

Hope this doesn't sound insane.

 

 

 

 

Link to comment
Share on other sites

You can write your own item spawn code (just be careful with what you do, as it can cause the game to stutter while containers around you are filled).

 

I hope the code && comments speak for themselves:

-- =============================================================================-- Muldraugh Tales-- by RoboMat---- Created: 11.11.13 - 23:31-- =============================================================================require'StoryHandling/StoryLoader.lua';require'StoryHandling/StoryTracker';-- -------------------------------------------------- Global Locals-- ------------------------------------------------local NO_NOTES = 11;local NO_LETTERS = 8;local NO_FLYERS = 11;local NO_PHOTOS = 1;local TYPE_NOTES = "Note";local TYPE_LETTERS = "Letter";local TYPE_FLYERS = "Flyer";local TYPE_PHOTOS = "Polaroid";local SPAWN_CHANCE_ALL = 50; -- Spawn chance for stories that have no room restrictions.local SPAWN_CHANCE_SPEC = 25; -- Spawn chance for stories that have room restrictions.local stories = StoryLoader.getStories();local spawnPoints = StoryLoader.getSpawns();-- -------------------------------------------------- Local functions-- ------------------------------------------------local function spawnStory(_id, _container)    local id = _id;    local story = stories[id];    local container = _container;    if story then        local item;        if story.tags['<type>'] == "letter" then            item = "MuldraughTales." .. TYPE_LETTERS .. (ZombRand(NO_LETTERS) + 1);        elseif story.tags['<type>'] == "flyer" then            item = "MuldraughTales." .. TYPE_FLYERS .. (ZombRand(NO_FLYERS) + 1);        elseif story.tags['<type>'] == "polaroid" then            item = "MuldraughTales." .. TYPE_PHOTOS .. (ZombRand(NO_PHOTOS) + 1);        else            item = "MuldraughTales." .. TYPE_NOTES .. (ZombRand(NO_NOTES) + 1);        end        local newNote = container:AddItem(item);        local modData = newNote:getModData();        modData.id = id;        print("Spawned story: \"" .. id .. "\"");    endend----- @param _roomName-- @param _containerType-- @param _containerFilled--local function spawnGlobalStories(_roomName, _containerType, _containerFilled)    local roomType = _roomName;    local containerType = _containerType;    local container = _containerFilled; -- ItemContainer    -- Make sure we have saved stories for this container type.    if spawnPoints.global[roomType] then        -- Spawn stories that are limited to certain room spawn.        if spawnPoints.global[roomType][containerType] then            for key, id in ipairs(spawnPoints.global[roomType][containerType]) do                if ZombRand(SPAWN_CHANCE_SPEC) == 0 then                    spawnStory(id, container);                end            end        end        -- Spawn stories that can spawn everywhere in the world.        if spawnPoints.global["all"][containerType] then            for key, id in ipairs(spawnPoints.global["all"][containerType]) do                if ZombRand(SPAWN_CHANCE_ALL) == 0 then                    spawnStory(id, container);                end            end        end    else        print("No stories for " .. containerType);    endend----- Spawns all stories with a specific coordinate. The difference to global-- stories is, that they have a 100% chance to spawn, only spawn once and-- always spawn at the same place.-- @param _roomName-- @param _containerType-- @param _containerFilled--local function spawnSpecificStories(_roomName, _containerType, _containerFilled)    local container = _containerFilled; -- ItemContainer    -- Cycle through the stories that have a special spawn place.    -- Get the container's coordinates.    local x = container:getSourceGrid():getX();    local y = container:getSourceGrid():getY();    if spawnPoints.specific["X" .. x .. ":Y" .. y] then        for _, id in pairs(spawnPoints.specific["X" .. x .. ":Y" .. y]) do            print(id);            spawnStory(id, container);        end    else        print("No stories have been found for these coordinates.");    endend-- -------------------------------------------------- Game Hooks-- ------------------------------------------------Events.OnFillContainer.Add(spawnGlobalStories);Events.OnFillContainer.Add(spawnSpecificStories);

 

This hasn't been tested with the latest MP build and TurboTuTone mentioned something to me concerning the item spawns. I'll send him over here to share his wisdom ;)

Link to comment
Share on other sites

Well, that what i mentioned was that if im not mistaken your posted piece of code above should work for mp without any need for tweaks or such :P

 

also, i only speak words of wisdom if you shove a quarter down my throat.... come see me at the fair! fun times.

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...