Modding > Spelunky 2 > Custom Entities Library


Create custom entities easily
By:
SereneRuby12
Downloads:
1455
Mod Type:
Script
Install Code:
custom-entities-library
Added:
4 years, 9 months ago
Last Update:
1 year, 3 months ago
Average Rating:

Details


🧰 Install

NOTE: This mod doesn't do anything by itself, it's required for mods that use it via import
Also, only works on Playlunky nightly for now (until new stable release)
(if the mod doesn't indicate that you need it, you probably don't need to install this)

Simply install as any other mod and make sure to place other mods that use the library below it on the Load Order (or just place the library on top)

ℹ Details

A library to easily make new entities, focused on items (and mounts), but works with any entity.

💻 Short example (for basic custom entities)

First, import the lib and make a function that will be called when the custom entity is spawned or set

local celib = import("SereneRuby12/custom-entities-library")
--local celib = require "custom_entities" --You can use this one if you want to include the library in your mod rather than
--people having to download it, but might cause some issues with pickups,
--and would not be the most optimized way if the player uses more custom entities

local function custom_ent_set(entity)
    -- ... your code
    local my_entity_data = {
        --store anything that you want in a table, optional
    }
    return my_entity_data --make sure to return the table if you use it
end

Second, make a function that will be called on every frame for the custom entity

local function custom_ent_update(entity, custom_data) --custom_data is the table that you created on the set function
    -- ... your code
end

Third, make a new custom entity type

    local custom_caveman_id = celib.new_custom_entity(custom_ent_set, custom_ent_update, nil, ENT_TYPE.MONS_CAVEMAN) -- the function can take more parameters, check documentation

And then spawn it, or add chances to be in shops, container, etc.

    celib.set_custom_entity(spawn_on_floor(ENT_TYPE.MONS_CAVEMAN, x, y, l), custom_caveman_id )
    celib.spawn_custom_entity(custom_caveman_id , x, y, l, 0, 0)

    celib.add_custom_container_chance(custom_caveman_id , celib.CHANCE.LOW, ENT_TYPE.ITEM_CRATE)

There are two ways of spawning a custom entity, that are basically the same: using the spawn function from the lib, or spawning the entity and making it to be a custom entity.

note: the example was simplified, check the original one on the github Readme

🔗 Useful links

🔤 Examples

Downloads


Latest Download
Downloads Name Uploaded
315 custom_entities.lua 1 year, 3 months ago
Past Downloads (8)
Downloads Name Uploaded
1 custom_entities.lua 1 year, 3 months ago
44 main.lua 1 year, 5 months ago
38 main.lua 1 year, 6 months ago
55 main.lua 1 year, 10 months ago
285 main.lua 3 years, 2 months ago
77 main.lua 3 years, 4 months ago
346 custom_entities.lua 4 years, 2 months ago
293 custom_entities.lua 4 years, 8 months ago

Comments (4)


Please log in to leave a comment.

1 year, 1 month ago

Hello. I'm trying to integrate your mod with mine, the Pouch mod. Could provide an API that would allow other mods too get the generated entity ids of all the items registered with your mod? Some other functions for retrieving and setting the custom_entity_data would also be helpful to be able to save data between levels.

What would be nice is some API with which you can check what entities have been registered/created, so that other mods could spawn them and maybe an API with which you could get and apply the custom entity data to save the state of custom entities to use between levels.

1 year, 1 month ago

Is there any way I could attach the custom item index this mod creates to Fenesd's backpack mod?

For context: whenever I try to pull a custom item that uses this library from the backpack, it returns as a freeze ray or clone gun. I assume it's due to the backpack not being able to find the custom item id in Spelunky 2's item index. I'm guessing this could be fixed by editing the backpack's code, but I don't know what to add.

2 years, 4 months ago

last example link doesn't work

4 years, 8 months ago

very good man, this awesome addon, I thought I had a very false dream and that I would only see reskin objects.