Jump to content

Custom items in crates


Jela331

Recommended Posts

Hello there,

 

I'm working on a side project and I want to put some crates with custom items in the spawn. For example, a shotgun with 24 shells. I know that there's a code that allows this in The Last Stand maps, but does it work for Sandbox/Survival? If it does, can somebody be kind enough to write it down? Thanks in advance. :D

Link to comment
Share on other sites

You mean that there always are the same items in the same containers?

 

I mean, that certain items would spawn in a certain crate. For example, you create a new save and you spawn near Crate 1 and Crate 2. Crate 1 would have an Axe and Nails, Crate 2 would have a Saw. Every time you create a new save there would be the same stuff in those crates.

Link to comment
Share on other sites

Ah yes ... well I achieved something like this by storing the coordinates of the containers to spawn the items in:

 

-- =============================================================================-- 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 was pre-multiplayer though, so I'm not sure how much of it still works.


P.S.: The interesting function for you is "spawnSpecificStories"

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